// // Given a round robin schedule, that respects last/first in round constraint // orient matches such that for a skipper he spends as much time port as // starboard and does not have 3 consecutive matches in the same orientation // 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.kernel.model.constraints.automaton.DFA; import choco.kernel.model.constraints.automaton.Transition; public class Phase1b { 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 int matchesPerRound; // the maximum number of matches in a round (boats/2) Phase1b (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(); matchesPerRound = boats/2; // of course for (int i=0;i t = new LinkedList(); t.add(new Transition(0,0,1)); t.add(new Transition(0,1,2)); t.add(new Transition(1,0,3)); t.add(new Transition(1,1,2)); t.add(new Transition(2,1,4)); t.add(new Transition(2,0,1)); t.add(new Transition(3,1,2)); t.add(new Transition(4,0,1)); // // Deterministic Finite Automat0n that accepts strings // from alphabet {0,1} that do not contain *000* or *111* // List fs = new LinkedList(); fs.add(0); fs.add(1); fs.add(2); fs.add(3); fs.add(4); // // list of accepting states, in this case all but the start state 0 // DFA auto = new DFA(t,fs,n-1); 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 { Phase1b orientBoats = new Phase1b (args[0]); int timeout = 0; if (args.length > 1) orientBoats.solver.setTimeLimit(Integer.parseInt(args[1]) * 1000); //System.out.println(orientBoats.minimize()); System.out.println(orientBoats.solve()); orientBoats.stats(); orientBoats.output(); } }