Google OR-Tools
v9.12
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
Variable.java
Go to the documentation of this file.
1
// Copyright 2010-2025 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
class
Variable
implements
LinearArgument
{
18
Variable(
ModelBuilderHelper
helper
,
double
lb,
double
ub,
boolean
isIntegral, String name) {
19
this.helper =
helper
;
20
this.index =
helper
.addVar();
21
this.helper.
setVarName
(
index
, name);
22
this.helper.
setVarIntegrality
(
index
, isIntegral);
23
this.helper.
setVarLowerBound
(
index
, lb);
24
this.helper.
setVarUpperBound
(
index
, ub);
25
}
26
27
Variable(
ModelBuilderHelper
helper
,
int
index
) {
28
this.helper =
helper
;
29
this.index =
index
;
30
}
31
33
public
int
getIndex
() {
34
return
index
;
35
}
36
37
// LinearArgument interface
38
@Override
39
public
LinearExpr
build
() {
40
return
new
AffineExpression
(
index
, 1.0, 0.0);
41
}
42
44
public
double
getLowerBound
() {
45
return
helper
.getVarLowerBound(
index
);
46
}
47
49
public
void
setLowerBound
(
double
lowerBound) {
50
helper
.setVarLowerBound(
index
, lowerBound);
51
}
52
54
public
double
getUpperBound
() {
55
return
helper
.getVarUpperBound(
index
);
56
}
57
59
public
void
setUpperBound
(
double
upperBound) {
60
helper
.setVarUpperBound(
index
, upperBound);
61
}
62
64
public
boolean
getIntegrality
() {
65
return
helper
.getVarIntegrality(
index
);
66
}
67
69
public
void
setIntegrality
(
boolean
isIntegral) {
70
helper
.setVarIntegrality(
index
, isIntegral);
71
}
72
74
public
double
getObjectiveCoefficient
() {
75
return
helper
.getVarObjectiveCoefficient(
index
);
76
}
77
79
public
void
setObjectiveCoefficient
(
double
objectiveCoefficient) {
80
helper
.setVarObjectiveCoefficient(
index
, objectiveCoefficient);
81
}
82
84
public
String
getName
() {
85
return
helper
.getVarName(
index
);
86
}
87
88
public
void
setName
(String name) {
89
helper
.setVarName(
index
, name);
90
}
91
92
@Override
93
public
String
toString
() {
94
if
(
getName
().isEmpty()) {
95
if
(
getLowerBound
() ==
getUpperBound
()) {
96
return
String.format(
"%f"
,
getLowerBound
());
97
}
else
{
98
return
String.format(
"var_%d(%f, %f)"
,
getIndex
(),
getLowerBound
(),
getUpperBound
());
99
}
100
}
else
{
101
return
String.format(
"%s(%f, %f)"
,
getName
(),
getLowerBound
(),
getUpperBound
());
102
}
103
}
104
105
protected
final
ModelBuilderHelper
helper
;
106
protected
final
int
index
;
107
}
com.google.ortools.modelbuilder.AffineExpression
Definition
AffineExpression.java:17
com.google.ortools.modelbuilder.ModelBuilderHelper
Definition
ModelBuilderHelper.java:11
com.google.ortools.modelbuilder.ModelBuilderHelper.setVarIntegrality
void setVarIntegrality(int var_index, boolean is_integer)
Definition
ModelBuilderHelper.java:91
com.google.ortools.modelbuilder.ModelBuilderHelper.setVarName
void setVarName(int var_index, String name)
Definition
ModelBuilderHelper.java:99
com.google.ortools.modelbuilder.ModelBuilderHelper.setVarUpperBound
void setVarUpperBound(int var_index, double ub)
Definition
ModelBuilderHelper.java:87
com.google.ortools.modelbuilder.ModelBuilderHelper.setVarLowerBound
void setVarLowerBound(int var_index, double lb)
Definition
ModelBuilderHelper.java:83
com.google.ortools.modelbuilder.Variable.build
LinearExpr build()
LinearArgument interface.
Definition
Variable.java:39
com.google.ortools.modelbuilder.Variable.helper
final ModelBuilderHelper helper
Definition
Variable.java:105
com.google.ortools.modelbuilder.Variable.setObjectiveCoefficient
void setObjectiveCoefficient(double objectiveCoefficient)
Definition
Variable.java:79
com.google.ortools.modelbuilder.Variable.getLowerBound
double getLowerBound()
Definition
Variable.java:44
com.google.ortools.modelbuilder.Variable.getIndex
int getIndex()
Definition
Variable.java:33
com.google.ortools.modelbuilder.Variable.setIntegrality
void setIntegrality(boolean isIntegral)
Definition
Variable.java:69
com.google.ortools.modelbuilder.Variable.getIntegrality
boolean getIntegrality()
Definition
Variable.java:64
com.google.ortools.modelbuilder.Variable.getObjectiveCoefficient
double getObjectiveCoefficient()
Definition
Variable.java:74
com.google.ortools.modelbuilder.Variable.getName
String getName()
Definition
Variable.java:84
com.google.ortools.modelbuilder.Variable.getUpperBound
double getUpperBound()
Definition
Variable.java:54
com.google.ortools.modelbuilder.Variable.setLowerBound
void setLowerBound(double lowerBound)
Definition
Variable.java:49
com.google.ortools.modelbuilder.Variable.setName
void setName(String name)
Definition
Variable.java:88
com.google.ortools.modelbuilder.Variable.toString
String toString()
Definition
Variable.java:93
com.google.ortools.modelbuilder.Variable.setUpperBound
void setUpperBound(double upperBound)
Definition
Variable.java:59
com.google.ortools.modelbuilder.Variable.index
final int index
Definition
Variable.java:106
com.google.ortools.modelbuilder.LinearArgument
Definition
LinearArgument.java:21
com.google.ortools.modelbuilder.LinearExpr
Definition
LinearExpr.java:17
ortools
java
com
google
ortools
modelbuilder
Variable.java
Generated by
1.13.2