import static choco.Choco.*; import choco.kernel.model.Model; import choco.kernel.model.variables.integer.IntegerVariable; import choco.kernel.model.constraints.automaton.DFA; import java.util.*; public class Skipper { int id; // a sequence number Match[] match; // matches skipper is in int firstFree; // for adding new matches IntegerVariable numberOfChanges; // number of times skipper changes boats IntegerVariable[] change; // change[i] = 0 <-> skipper is in same boat in match i and match i+1 IntegerVariable[] boat; // boat[i] maybe {1..numberOfBoats} for allocation or {0,1} for orientation int numberOfMatches; // number of matches for this skipper (must be n-1) int numberOfBoats; // to compute position of match in a round/flight // // NOTE: boat[i] is used in two different roles. // // In Phase1a, boat allocation, boat[i] is the boat used by this skipper in his ith match. // See penalizeBoatChange below // // In Phase1b boat[i] is 0 or 1, where 0 is port and 1 starboard. This then gives the // orientation of the skipper in his ith match. See portStarboard below // Skipper(int id,int numberOfMatches,int numberOfBoats){ this.id = id; this.numberOfMatches = numberOfMatches; match = new Match[numberOfMatches]; firstFree = 0; numberOfChanges = makeIntVar("totalChanges-"+ id,0,numberOfMatches-1); change = makeIntVarArray("change-"+ id,numberOfMatches-1,0,1); boat = new IntegerVariable[numberOfMatches]; this.numberOfBoats = numberOfBoats; } // // as used in Phase1a, boat allocation // Skipper(int id,int numberOfMatches){ this.id = id; this.numberOfMatches = numberOfMatches; match = new Match[numberOfMatches]; firstFree = 0; boat = new IntegerVariable[numberOfMatches]; } // // as used in Phase1b, match orientation // void add(Match m){ match[firstFree] = m; firstFree++; } // // add a new match m to this skipper, where skipper // is player1 or player2 in that match m // void penalizeBoatChange(Model model){ Arrays.sort(match,new MatchComparator()); int m = numberOfBoats/2; // number of matches in a round/flight for (int i=0;i boat k was used in the ith match by this skipper // void portStarboard(Model model,DFA auto){ Arrays.sort(match,new MatchComparator()); int m = numberOfBoats/2; // number of matches in a round/flight for (int i=0;i