Actual model
| 99 | |
| 100 | /// Actual model |
| 101 | Golf(const GolfOptions& opt) |
| 102 | : Script(opt), |
| 103 | g(opt.g()), s(opt.s()), w(opt.w()), |
| 104 | groups(*this,g*w,IntSet::empty,0,g*s-1, |
| 105 | static_cast<unsigned int>(s),static_cast<unsigned int>(s)) { |
| 106 | Matrix<SetVarArray> schedule(groups,g,w); |
| 107 | |
| 108 | // Groups in one week must be disjoint |
| 109 | SetVar allPlayers(*this, 0,g*s-1, 0,g*s-1); |
| 110 | for (int i=0; i<w; i++) |
| 111 | rel(*this, setdunion(schedule.row(i)) == allPlayers); |
| 112 | |
| 113 | // No two golfers play in the same group more than once |
| 114 | if (opt.propagation() == PROP_SET || opt.propagation() == PROP_MIXED) { |
| 115 | // Cardinality of intersection between two groups is at most one |
| 116 | for (int i=0; i<groups.size()-1; i++) |
| 117 | for (int j=i+1; j<groups.size(); j++) |
| 118 | rel(*this, cardinality(groups[i] & groups[j]) <= 1); |
| 119 | } |
| 120 | if (opt.propagation() == PROP_INT || opt.propagation() == PROP_MIXED) { |
| 121 | // Set up table mapping from pairs (p1,p2) (where p1<p2) of players to |
| 122 | // unique integer identifiers |
| 123 | int playerCount = g * s; |
| 124 | TupleSet ts(3); |
| 125 | int pairCount=0; |
| 126 | for (int p1=0; p1<playerCount-1; p1++) |
| 127 | for (int p2=p1+1; p2<playerCount; p2++) |
| 128 | ts.add({p1, p2, pairCount++}); |
| 129 | ts.finalize(); |
| 130 | |
| 131 | // Collect pairs of golfers into pairs |
| 132 | IntVarArgs pairs; |
| 133 | for (int i=0; i<groups.size()-1; i++) { |
| 134 | // Channel sorted will ensure that for i<j, group[i]<group[j], |
| 135 | // ensuring that the tuple set has a valid mapping. |
| 136 | IntVarArgs group(*this, s, 0, playerCount-1); |
| 137 | channelSorted(*this, group, groups[i]); |
| 138 | // Collect all pairs in current group |
| 139 | for (int p1=0; p1<group.size()-1; ++p1) { |
| 140 | for (int p2=p1+1; p2<group.size(); ++p2) { |
| 141 | IntVar pair(*this, 0, pairCount); |
| 142 | |
| 143 | IntVarArgs args; |
| 144 | args << group[p1] << group[p2] << pair; |
| 145 | extensional(*this, args, ts); |
| 146 | |
| 147 | pairs << pair; |
| 148 | } |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | // All pairs of golfers (using the unique identifiers) must be different |
| 153 | distinct(*this, pairs, opt.ipl()); |
| 154 | } |
| 155 | |
| 156 | if (opt.model() == MODEL_SYMMETRY) { |
| 157 | |
| 158 | /* |
nothing calls this directly
no test coverage detected