Google OR-Tools
v9.11
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
WeightedSumExpression.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.modelbuilder;
15
17
public
final
class
WeightedSumExpression
implements
LinearExpr {
18
private
final
int
[] variablesIndices;
19
private
final
double
[] coefficients;
20
private
final
double
offset;
21
22
public
WeightedSumExpression
(
int
[] variablesIndices,
double
[] coefficients,
double
offset) {
23
this.variablesIndices = variablesIndices;
24
this.coefficients = coefficients;
25
this.offset = offset;
26
}
27
28
@Override
29
public
LinearExpr
build
() {
30
return
this
;
31
}
32
33
@Override
34
public
int
numElements
() {
35
return
variablesIndices.length;
36
}
37
38
@Override
39
public
int
getVariableIndex
(
int
index) {
40
if
(index < 0 || index >= variablesIndices.length) {
41
throw
new
IllegalArgumentException(
"wrong index in LinearExpr.getVariable(): "
+ index);
42
}
43
return
variablesIndices[index];
44
}
45
46
@Override
47
public
double
getCoefficient
(
int
index) {
48
if
(index < 0 || index >= variablesIndices.length) {
49
throw
new
IllegalArgumentException(
"wrong index in LinearExpr.getCoefficient(): "
+ index);
50
}
51
return
coefficients[index];
52
}
53
54
@Override
55
public
double
getOffset
() {
56
return
offset;
57
}
58
}
com.google.ortools.modelbuilder.WeightedSumExpression.getVariableIndex
int getVariableIndex(int index)
Definition
WeightedSumExpression.java:39
com.google.ortools.modelbuilder.WeightedSumExpression.build
LinearExpr build()
Definition
WeightedSumExpression.java:29
com.google.ortools.modelbuilder.WeightedSumExpression.getCoefficient
double getCoefficient(int index)
Definition
WeightedSumExpression.java:47
com.google.ortools.modelbuilder.WeightedSumExpression.numElements
int numElements()
Definition
WeightedSumExpression.java:34
com.google.ortools.modelbuilder.WeightedSumExpression.getOffset
double getOffset()
Definition
WeightedSumExpression.java:55
com.google.ortools.modelbuilder.WeightedSumExpression.WeightedSumExpression
WeightedSumExpression(int[] variablesIndices, double[] coefficients, double offset)
Definition
WeightedSumExpression.java:22
com.google.ortools.modelbuilder.LinearExpr
Definition
LinearExpr.java:17
ortools
java
com
google
ortools
modelbuilder
WeightedSumExpression.java
Generated by
1.12.0