// // Given a n skippers and m boats, produce a round robin schedule // with at most m/2 matches per round, respecting the constraint that the // players in the last match of a round cannot participate in the first // match of the next round, and if 5 or more matches in a round, the // first match in the next round does not contain either skipper from the // second last match in this round // 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 Phase0 { Model model; Solver solver; int n; // contestants int m; // maximum number of matches in a round int matches; // number of matches overall IntegerVariable[] fMatch; // flattened match, for all difference int rounds; // number of rounds int boats; // number of boats given IntegerVariable[][] match; // match[i][j] = k <-> contestants i and j are in a match in round k/m position k%m Phase0 (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]; this.boats = boats; for (int i=0,k=0;i 4) for (int i=0;i 0) model.addConstraint(implies(and(eq(mod(y,m),m-2),eq(div(y,m),minus(div(x,m),1))),neq(mod(x,m),0))); // as above but with x and y swapped } // // If at least 5 matches in a flight // Then skippers in second last match in a flight cannot // be in first match of next flight // // NOTE: "Principal Criteria ... 7. In flights with five or more matches no skipper // should be in the next-to-last match in a flight and then in the first // match of the next flight." // model.addConstraint(allDifferent(fMatch)); // // every match takes place in a different time slot // solver.read(model); //solver.setValIntSelector(new MidVal()); solver.setValIntSelector(new RandomIntValSelector()); //solver.setVarIntSelector(new RandomIntVarSelector(solver)); //solver.setVarIntSelector(new MaxDomain(solver)); //,solver.getVar(fMatch))); solver.setVarIntSelector(new MinDomain(solver,solver.getVar(fMatch))); // search over decision variables } boolean solve(){return solver.solve();} void result(){ int[][][] schedule = new int[rounds][m][2]; for (int i=0;i