Google OR-Tools v9.9
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
TableConstraint.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.sat.TableConstraintProto;
18
25public class TableConstraint extends Constraint {
27 super(builder);
28 }
29
37 public TableConstraint addTuple(int[] tuple) {
38 TableConstraintProto.Builder table = getBuilder().getTableBuilder();
39 if (tuple.length != table.getVarsCount()) {
40 throw new CpModel.WrongLength(
41 "addTuple", "tuple does not have the same length as the variables");
42 }
43 for (int value : tuple) {
44 table.addValues(value);
45 }
46 return this;
47 }
48
56 public TableConstraint addTuple(long[] tuple) {
57 TableConstraintProto.Builder table = getBuilder().getTableBuilder();
58 if (tuple.length != table.getVarsCount()) {
59 throw new CpModel.WrongLength(
60 "addTuple", "tuple does not have the same length as the variables");
61 }
62 for (long value : tuple) {
63 table.addValues(value);
64 }
65 return this;
66 }
67
75 public TableConstraint addTuples(int[][] tuples) {
76 TableConstraintProto.Builder table = getBuilder().getTableBuilder();
77 for (int[] tuple : tuples) {
78 if (tuple.length != table.getVarsCount()) {
79 throw new CpModel.WrongLength(
80 "addTuples", "a tuple does not have the same length as the variables");
81 }
82 for (int value : tuple) {
83 table.addValues(value);
84 }
85 }
86 return this;
87 }
88
96 public TableConstraint addTuples(long[][] tuples) {
97 TableConstraintProto.Builder table = getBuilder().getTableBuilder();
98 for (long[] tuple : tuples) {
99 if (tuple.length != table.getVarsCount()) {
100 throw new CpModel.WrongLength(
101 "addTuples", "a tuple does not have the same length as the variables");
102 }
103 for (long value : tuple) {
104 table.addValues(value);
105 }
106 }
107 return this;
108 }
109}
ConstraintProto.Builder getBuilder()
TableConstraint(CpModelProto.Builder builder)
TableConstraint addTuple(int[] tuple)
TableConstraint addTuples(long[][] tuples)
TableConstraint addTuple(long[] tuple)
TableConstraint addTuples(int[][] tuples)