This commit is contained in:
Laurent Perron
2022-01-11 16:15:07 +01:00
parent 79865d02cb
commit 1615d1956c
3 changed files with 11 additions and 21 deletions

View File

@@ -33,7 +33,7 @@ public class MultipleCircuitConstraint extends Constraint {
* @param head the index of the head node.
* @param literal it will be set to true if the arc is selected.
*/
public public void addArc(int tail, int head, Literal literal) {
public void addArc(int tail, int head, Literal literal) {
RoutesConstraintProto.Builder circuit = getBuilder().getRoutesBuilder();
circuit.addTails(tail);
circuit.addHeads(head);

View File

@@ -72,10 +72,10 @@ public class TableConstraint extends Constraint {
*/
public void addTuples(int[][] tuples) {
TableConstraintProto.Builder table = getBuilder().getTableBuilder();
for (int[] tuple : tuples {
for (int[] tuple : tuples) {
if (tuple.length != table.getVarsCount()) {
throw new CpModel.WrongLength(
"addTuple", "tuple does not have the same length as the variables");
"addTuples", "a tuple does not have the same length as the variables");
}
for (int value : tuple) {
table.addValues(value);
@@ -92,10 +92,10 @@ public class TableConstraint extends Constraint {
*/
public void addTuples(long[][] tuples) {
TableConstraintProto.Builder table = getBuilder().getTableBuilder();
for (long[] tuple : tuples {
for (long[] tuple : tuples) {
if (tuple.length != table.getVarsCount()) {
throw new CpModel.WrongLength(
"addTuple", "tuple does not have the same length as the variables");
"addTuples", "a tuple does not have the same length as the variables");
}
for (long value : tuple) {
table.addValues(value);

View File

@@ -23,7 +23,6 @@ import com.google.ortools.sat.IntVar;
import com.google.ortools.sat.LinearExpr;
import com.google.ortools.sat.LinearExprBuilder;
import com.google.ortools.sat.Literal;
import com.google.ortools.sat.TableConstraint;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.IntStream;
@@ -135,21 +134,12 @@ public class AssignmentGroupsSat {
}
// Define the allowed groups of worders
TableConstraint group1Ct =
model.addAllowedAssignments(new IntVar[] {work[0], work[1], work[2], work[3]});
for (int[] assignment : group1) {
group1Ct.addTuple(assignment);
}
TableConstraint group2Ct =
model.addAllowedAssignments(new IntVar[] {work[4], work[5], work[6], work[7]});
for (int[] assignment : group2) {
group2Ct.addTuple(assignment);
}
TableConstraint group3Ct =
model.addAllowedAssignments(new IntVar[] {work[8], work[9], work[10], work[11]});
for (int[] assignment : group3) {
group3Ct.addTuple(assignment);
}
model.addAllowedAssignments(new IntVar[] {work[0], work[1], work[2], work[3]})
.addTuples(group1);
model.addAllowedAssignments(new IntVar[] {work[4], work[5], work[6], work[7]})
.addTuples(group2);
model.addAllowedAssignments(new IntVar[] {work[8], work[9], work[10], work[11]})
.addTuples(group3);
// [END assignments]
// Objective