Google OR-Tools v9.9
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-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
14package com.google.ortools.sat;
15
16import com.google.ortools.sat.CpModelProto;
17import com.google.ortools.util.Domain;
18
20public 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()) {
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 {
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}
final IntegerVariableProto.Builder varBuilder
Definition IntVar.java:95