Google OR-Tools
v9.12
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
BoolVar.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.sat;
15
16
import
com.google.ortools.sat.CpModelProto;
17
import
com.google.ortools.util.Domain;
18
20
public
final
class
BoolVar
extends
IntVar implements
Literal
{
21
BoolVar(
CpModelProto
.
Builder
builder,
Domain
domain, String name) {
22
super(builder, domain, name);
23
this.negation =
null
;
24
}
25
26
BoolVar(
CpModelProto
.
Builder
builder,
int
index) {
27
super(builder, index);
28
this.negation =
null
;
29
}
30
32
@Override
33
public
Literal
not
() {
34
if
(negation ==
null
) {
35
negation =
new
NotBoolVar
(
this
);
36
}
37
return
negation;
38
}
39
40
@Override
41
public
String
toString
() {
42
if
(
varBuilder
.getName().isEmpty()) {
43
if
(
varBuilder
.getDomainCount() == 2 &&
varBuilder
.getDomain(0) ==
varBuilder
.getDomain(1)) {
44
if
(
varBuilder
.getDomain(0) == 0) {
45
return
"false"
;
46
}
else
{
47
return
"true"
;
48
}
49
}
else
{
50
return
String.format(
"boolvar_%d(%s)"
,
getIndex
(),
displayBounds
());
51
}
52
}
else
{
53
if
(
varBuilder
.getDomainCount() == 2 &&
varBuilder
.getDomain(0) ==
varBuilder
.getDomain(1)) {
54
if
(
varBuilder
.getDomain(0) == 0) {
55
return
String.format(
"%s(false)"
,
varBuilder
.getName());
56
}
else
{
57
return
String.format(
"%s(true)"
,
varBuilder
.getName());
58
}
59
}
else
{
60
return
String.format(
"%s(%s)"
,
getName
(),
displayBounds
());
61
}
62
}
63
}
64
65
private
NotBoolVar
negation =
null
;
66
}
com.google.ortools.sat.BoolVar.not
Literal not()
Definition
BoolVar.java:33
com.google.ortools.sat.BoolVar.toString
String toString()
Definition
BoolVar.java:41
com.google.ortools.sat.CpModelProto.Builder
Definition
CpModelProto.java:910
com.google.ortools.sat.CpModelProto
Definition
CpModelProto.java:18
com.google.ortools.sat.IntVar.getIndex
int getIndex()
Definition
IntVar.java:44
com.google.ortools.sat.IntVar.varBuilder
final IntegerVariableProto.Builder varBuilder
Definition
IntVar.java:95
com.google.ortools.sat.IntVar.displayBounds
String displayBounds()
Definition
IntVar.java:60
com.google.ortools.sat.IntVar.getName
String getName()
Definition
IntVar.java:39
com.google.ortools.sat.NotBoolVar
Definition
NotBoolVar.java:20
com.google.ortools.util.Domain
Definition
Domain.java:21
com.google.ortools.sat.Literal
Definition
Literal.java:17
ortools
java
com
google
ortools
sat
BoolVar.java
Generated by
1.13.2