Google OR-Tools
v9.11
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
LinearExpr.java
Go to the documentation of this file.
1
// Copyright 2010-2024 Google LLC
2
// Licensed under the Apache License, Version 2.0 (the "License");
3
// you may not use this file except in compliance with the License.
4
// You may obtain a copy of the License at
5
//
6
// http://www.apache.org/licenses/LICENSE-2.0
7
//
8
// Unless required by applicable law or agreed to in writing, software
9
// distributed under the License is distributed on an "AS IS" BASIS,
10
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
// See the License for the specific language governing permissions and
12
// limitations under the License.
13
14
package
com.google.ortools.sat;
15
16
import
com.google.ortools.sat.LinearExpressionProto;
17
19
public
interface
LinearExpr
extends
LinearArgument {
21
int
numElements
();
22
24
int
getVariableIndex
(
int
index);
25
27
long
getCoefficient
(
int
index);
28
30
long
getOffset
();
31
33
static
LinearExprBuilder
newBuilder
() {
34
return
new
LinearExprBuilder
();
35
}
36
38
static
LinearExpr
constant
(
long
value) {
39
return
newBuilder
().
add
(value).
build
();
40
}
41
43
static
LinearExpr
term
(
LinearArgument
expr,
long
coeff) {
44
return
newBuilder
().
addTerm
(expr, coeff).
build
();
45
}
46
48
static
LinearExpr
affine
(
LinearArgument
expr,
long
coeff,
long
offset) {
49
return
newBuilder
().
addTerm
(expr, coeff).
add
(offset).
build
();
50
}
51
53
static
LinearExpr
sum
(
LinearArgument
[] exprs) {
54
return
newBuilder
().
addSum
(exprs).
build
();
55
}
56
58
static
LinearExpr
weightedSum
(
LinearArgument
[] exprs,
long
[] coeffs) {
59
return
newBuilder
().
addWeightedSum
(exprs, coeffs).
build
();
60
}
61
62
static
LinearExpr
rebuildFromLinearExpressionProto
(
LinearExpressionProto
proto) {
63
int
numElements
= proto.
getVarsCount
();
64
if
(
numElements
== 0) {
65
return
new
ConstantExpression
(proto.
getOffset
());
66
}
else
if
(
numElements
== 1) {
67
return
new
AffineExpression
(proto.
getVars
(0), proto.
getCoeffs
(0), proto.
getOffset
());
68
}
else
{
69
int
[] varsIndices =
new
int
[
numElements
];
70
long
[] coeffs =
new
long
[
numElements
];
71
long
offset = proto.
getOffset
();
72
for
(
int
i = 0; i <
numElements
; ++i) {
73
varsIndices[i] = proto.
getVars
(i);
74
coeffs[i] = proto.
getCoeffs
(i);
75
}
76
return
new
WeightedSumExpression
(varsIndices, coeffs, offset);
77
}
78
}
79
}
com.google.ortools.sat.AffineExpression
Definition
AffineExpression.java:17
com.google.ortools.sat.ConstantExpression
Definition
ConstantExpression.java:17
com.google.ortools.sat.LinearExprBuilder
Definition
LinearExprBuilder.java:20
com.google.ortools.sat.LinearExprBuilder.add
LinearExprBuilder add(LinearArgument expr)
Definition
LinearExprBuilder.java:29
com.google.ortools.sat.LinearExprBuilder.addWeightedSum
LinearExprBuilder addWeightedSum(LinearArgument[] exprs, long[] coeffs)
Definition
LinearExprBuilder.java:56
com.google.ortools.sat.LinearExprBuilder.addSum
LinearExprBuilder addSum(LinearArgument[] exprs)
Definition
LinearExprBuilder.java:49
com.google.ortools.sat.LinearExprBuilder.addTerm
LinearExprBuilder addTerm(LinearArgument expr, long coeff)
Definition
LinearExprBuilder.java:39
com.google.ortools.sat.LinearExprBuilder.build
LinearExpr build()
Definition
LinearExprBuilder.java:71
com.google.ortools.sat.LinearExpressionProto
Definition
LinearExpressionProto.java:19
com.google.ortools.sat.LinearExpressionProto.getVarsCount
int getVarsCount()
Definition
LinearExpressionProto.java:69
com.google.ortools.sat.LinearExpressionProto.getCoeffs
long getCoeffs(int index)
Definition
LinearExpressionProto.java:107
com.google.ortools.sat.LinearExpressionProto.getOffset
long getOffset()
Definition
LinearExpressionProto.java:119
com.google.ortools.sat.LinearExpressionProto.getVars
int getVars(int index)
Definition
LinearExpressionProto.java:77
com.google.ortools.sat.WeightedSumExpression
Definition
WeightedSumExpression.java:17
com.google.ortools.sat.LinearArgument
Definition
LinearArgument.java:21
com.google.ortools.sat.LinearExpr
Definition
LinearExpr.java:19
com.google.ortools.sat.LinearExpr.getCoefficient
long getCoefficient(int index)
com.google.ortools.sat.LinearExpr.getVariableIndex
int getVariableIndex(int index)
com.google.ortools.sat.LinearExpr.term
static LinearExpr term(LinearArgument expr, long coeff)
Definition
LinearExpr.java:43
com.google.ortools.sat.LinearExpr.getOffset
long getOffset()
com.google.ortools.sat.LinearExpr.affine
static LinearExpr affine(LinearArgument expr, long coeff, long offset)
Definition
LinearExpr.java:48
com.google.ortools.sat.LinearExpr.newBuilder
static LinearExprBuilder newBuilder()
Definition
LinearExpr.java:33
com.google.ortools.sat.LinearExpr.numElements
int numElements()
com.google.ortools.sat.LinearExpr.weightedSum
static LinearExpr weightedSum(LinearArgument[] exprs, long[] coeffs)
Definition
LinearExpr.java:58
com.google.ortools.sat.LinearExpr.sum
static LinearExpr sum(LinearArgument[] exprs)
Definition
LinearExpr.java:53
com.google.ortools.sat.LinearExpr.rebuildFromLinearExpressionProto
static LinearExpr rebuildFromLinearExpressionProto(LinearExpressionProto proto)
Definition
LinearExpr.java:62
com.google.ortools.sat.LinearExpr.constant
static LinearExpr constant(long value)
Definition
LinearExpr.java:38
ortools
java
com
google
ortools
sat
LinearExpr.java
Generated by
1.12.0