import static choco.Choco.*; import choco.cp.model.CPModel; import choco.cp.solver.CPSolver; import choco.kernel.model.Model; import choco.kernel.solver.Solver; import choco.kernel.model.variables.integer.IntegerVariable; import choco.kernel.model.constraints.Constraint; import choco.cp.solver.search.integer.varselector.*; import java.util.*; public class Skipper { Model model; int id; // identification number int n; // number of skippers, controls domains size for a time slot int m; // size of a round int matches; // number of matches int rounds; // number of rounds int timeSlots; int boats; IntegerVariable[] timeSlot; // array of timeslots for a skipper IntegerVariable[] isMinusTwo; // IntegerVariable[] isMinusOne; // IntegerVariable[] isGeqZero; // IntegerVariable[] state; // there is a state for each round for the skipper IntegerVariable[] decVar; // decision variables IntegerVariable[] change; // when a boat change takes place IntegerVariable[][] position; // position[i][j] = 1 <-> there is a match in position i in round j IntegerVariable[] imbalance; // imbalance[i] is how far from perfect balance in position i IntegerVariable maxImbalance; // maximum imbalance for this skipper IntegerVariable changes; // number of boat changes made final int FIRST = 1; final int MID = 2; final int LAST = 3; final int BYE = 4; final int END = 5; Skipper(Model model,int id,int n,int m,int boats){ this.model = model; this.id = id; this.n = n; this.m = m; this.boats = boats; matches = n*(n-1)/2; rounds = (int)Math.ceil((double)matches/(double)m); timeSlots = rounds * m; timeSlot = makeIntVarArray("timeSlot_"+ id,timeSlots,-2,n-1); isMinusTwo = makeIntVarArray("isMinusTwo",timeSlots,0,1); isMinusOne = makeIntVarArray("isMinusOne",timeSlots,0,1); isGeqZero = makeIntVarArray("isGeqZero",timeSlots,0,1); state = makeIntVarArray("state_"+ id,rounds,1,5); decVar = new IntegerVariable[timeSlots + rounds]; change = makeIntVarArray("change",rounds-1,0,1); changes = makeIntVar("changes",0,n-1); position = makeIntVarArray("position",m,rounds,0,1); imbalance = makeIntVarArray("imbalance",m,0,n-1); maxImbalance = makeIntVar("maxImbalance",0,n-1); for (int i=0;i= 0) // public void output(Solver solver){ System.out.print(id +": "); for (int round=0;round= 0) System.out.print(x); } System.out.print(" "); } System.out.println(); while (solver.nextSolution().booleanValue()){ for (int round=0;round= 0) System.out.print(x); } System.out.print(" "); } System.out.println(); } } } }