Constructor
| 244 | public: |
| 245 | /// Constructor |
| 246 | SudokuSet(const SizeOptions& opt) |
| 247 | : Sudoku(opt), |
| 248 | y(*this,n*n,IntSet::empty,1,n*n*n*n, |
| 249 | static_cast<unsigned int>(n*n),static_cast<unsigned int>(n*n)) { |
| 250 | |
| 251 | const int nn = n*n; |
| 252 | |
| 253 | Region r; |
| 254 | IntSet* row = r.alloc<IntSet>(nn); |
| 255 | IntSet* col = r.alloc<IntSet>(nn); |
| 256 | IntSet* block = r.alloc<IntSet>(nn); |
| 257 | |
| 258 | // Set up the row and column set constants |
| 259 | int* dsc = r.alloc<int>(nn); |
| 260 | for (int i=0; i<nn; i++) { |
| 261 | row[i] = IntSet((i*nn)+1, (i+1)*nn); |
| 262 | |
| 263 | for (int j=0; j<nn; j++) { |
| 264 | dsc[j] = (j*nn)+1+i; |
| 265 | } |
| 266 | col[i] = IntSet(dsc, nn); |
| 267 | } |
| 268 | |
| 269 | // Set up the block set constants |
| 270 | int* dsb_arr = r.alloc<int>(nn); |
| 271 | for (int i=0; i<n; i++) { |
| 272 | for (int j=0; j<n; j++) { |
| 273 | |
| 274 | for (int ii=0; ii<n; ii++) { |
| 275 | for (int jj=0; jj<n; jj++) { |
| 276 | dsb_arr[ii*n+jj] = j*nn*n+i*n+jj*nn+ii+1; |
| 277 | } |
| 278 | } |
| 279 | block[i*n+j] = IntSet(dsb_arr, nn); |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | IntSet full(1, nn*nn); |
| 284 | // All x must be pairwise disjoint and partition the field indices |
| 285 | rel(*this, SOT_DUNION, y, SetVar(*this, full, full)); |
| 286 | |
| 287 | // The x must intersect in exactly one element with each |
| 288 | // row, column, and block |
| 289 | for (int i=0; i<nn; i++) |
| 290 | for (int j=0; j<nn; j++) { |
| 291 | SetVar inter_row(*this, IntSet::empty, full, 1U, 1U); |
| 292 | rel(*this, y[i], SOT_INTER, row[j], SRT_EQ, inter_row); |
| 293 | SetVar inter_col(*this, IntSet::empty, full, 1U, 1U); |
| 294 | rel(*this, y[i], SOT_INTER, col[j], SRT_EQ, inter_col); |
| 295 | SetVar inter_block(*this, IntSet::empty, full, 1U, 1U); |
| 296 | rel(*this, y[i], SOT_INTER, block[j], SRT_EQ, inter_block); |
| 297 | } |
| 298 | |
| 299 | // Fill-in predefined fields |
| 300 | for (int i=0; i<nn; i++) |
| 301 | for (int j=0; j<nn; j++) |
| 302 | if (int idx = sudokuField(examples[opt.size()], nn, i, j)) |
| 303 | dom(*this, y[idx-1], SRT_SUP, (i+1)+(j*nn) ); |
nothing calls this directly
no test coverage detected