// // The problem is viewed more a scheduling problem. Rather than just have rounds // we have positions in a round. That is, a round is a sequence. // Constraints are added such that the last contestants in a round // cannot be in the first match of the next round // NOTE: BAP4 is same as BAP3 (this) but uses value selectors (rando works well) // import static choco.Choco.*; import choco.cp.model.CPModel; import choco.kernel.model.Model; import choco.kernel.model.variables.integer.IntegerVariable; import choco.cp.solver.CPSolver; import choco.kernel.solver.Solver; import choco.kernel.solver.variables.integer.IntDomainVar; import choco.cp.solver.search.integer.varselector.*; import choco.cp.solver.search.integer.valselector.*; public class BAP3 { Model model; Solver solver; int n; // contestants int m; // maximum number of matches in a round int matches; // number of matches IntegerVariable[] fMatch; // flattened match int rounds; // number of rounds IntegerVariable[][] match; // match[i][j] = k <-> contestants i and j are in a match in round k/m position k%m BAP3 (int n,int boats) { this.n = n; this.m = boats/2; matches = n*(n-1)/2; rounds = (int)Math.ceil((double)matches/(double)m); model = new CPModel(); solver = new CPSolver(); match = new IntegerVariable[n][n]; fMatch = new IntegerVariable[matches]; for (int i=0,k=0;i