Actual model
| 86 | |
| 87 | /// Actual model |
| 88 | Domino(const SizeOptions& opt) |
| 89 | : Script(opt), |
| 90 | spec(specs[opt.size()]), |
| 91 | width(spec[0]), height(spec[1]), |
| 92 | x(*this, (width+1)*height, 0, 28) { |
| 93 | spec+=2; // skip board size information |
| 94 | |
| 95 | // Copy spec information to the board |
| 96 | IntArgs board((width+1)*height); |
| 97 | for (int i=0; i<width; i++) |
| 98 | for (int j=0; j<height; j++) |
| 99 | board[j*(width+1)+i] = spec[j*width+i]; |
| 100 | |
| 101 | // Initialize the separator column in the board |
| 102 | for (int i=0; i<height; i++) { |
| 103 | board[i*(width+1)+8] = -1; |
| 104 | rel(*this, x[i*(width+1)+8]==28); |
| 105 | } |
| 106 | |
| 107 | // Variables representing the coordinates of the first |
| 108 | // and second half of a domino piece |
| 109 | IntVarArgs p1(*this, 28, 0, (width+1)*height-1); |
| 110 | IntVarArgs p2(*this, 28, 0, (width+1)*height-1); |
| 111 | |
| 112 | |
| 113 | if (opt.propagation() == PROP_ELEMENT) { |
| 114 | int dominoCount = 0; |
| 115 | |
| 116 | int possibleDiffsA[] = {1, width+1}; |
| 117 | IntSet possibleDiffs(possibleDiffsA, 2); |
| 118 | |
| 119 | for (int i=0; i<=6; i++) |
| 120 | for (int j=i; j<=6; j++) { |
| 121 | |
| 122 | // The two coordinates must be adjacent. |
| 123 | // I.e., they may differ by 1 or by the width. |
| 124 | // The separator column makes sure that a field |
| 125 | // at the right border is not adjacent to the first field |
| 126 | // in the next row. |
| 127 | IntVar diff(*this, possibleDiffs); |
| 128 | abs(*this, expr(*this, p1[dominoCount]-p2[dominoCount]), |
| 129 | diff, IPL_DOM); |
| 130 | |
| 131 | // If the piece is symmetrical, order the locations |
| 132 | if (i == j) |
| 133 | rel(*this, p1[dominoCount], IRT_LE, p2[dominoCount]); |
| 134 | |
| 135 | // Link the current piece to the board |
| 136 | element(*this, board, p1[dominoCount], i); |
| 137 | element(*this, board, p2[dominoCount], j); |
| 138 | |
| 139 | // Link the current piece to the array where its |
| 140 | // number is stored. |
| 141 | element(*this, x, p1[dominoCount], dominoCount); |
| 142 | element(*this, x, p2[dominoCount], dominoCount); |
| 143 | dominoCount++; |
| 144 | } |
| 145 | } else { |
nothing calls this directly
no test coverage detected