// // Given a round robin schedule, that respects last/first in round constraint // Allocate boats to minimise the maximum number of boat changes over all skippers // import java.util.*; import java.io.*; 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.cp.solver.search.integer.varselector.MinDomain; import choco.kernel.solver.ContradictionException; public class Phase1a { Model model; Solver solver; int n, rounds, boats; int[][] schedule; // constant, schedule[i][j] = k <-> match(i,j) at timeslot k Round[] round; // an array of rounds Skipper[] skipper; // an array of skippers IntegerVariable changes; // the maximum boat changes for a skipper int matchesPerRound; // the maximum number of matches in a round (boats/2) IntegerVariable[] boat; // the decision variables Phase1a (String fname) throws IOException { Scanner sc = new Scanner(new File(fname)); n = sc.nextInt(); // number of skippers rounds = sc.nextInt(); // number of rounds boats = sc.nextInt(); // number of boats schedule = new int[n][n]; // as read in round = new Round[rounds]; skipper = new Skipper[n]; model = new CPModel(); solver = new CPSolver(); changes = makeIntVar("changes",0,n-1); // maximum boat changes over all skippers matchesPerRound = boats/2; // of course boat = new IntegerVariable[n*(n-1)]; // the decision variables for (int i=0;i "); for (IntegerVariable b : s.boat) System.out.print(solver.getVar(b).getVal() +" "); System.out.println(); } } boolean minimize(){return solver.minimize(solver.getVar(changes),false);} boolean solve(){return solver.solve();} void stats(){ System.out.println("nodes: "+ solver.getNodeCount() +" cpu: "+ solver.getTimeCount()); } public static void main(String[] args) throws IOException { Phase1a allocBoats = new Phase1a (args[0]); int timeout = 0; if (args.length > 1) allocBoats.solver.setTimeLimit(Integer.parseInt(args[1]) * 1000); System.out.println(allocBoats.minimize()); //System.out.println(allocBoats.solve()); allocBoats.stats(); allocBoats.output(); } }