Actual model
| 357 | |
| 358 | /// Actual model |
| 359 | ColoredMatrix(const ColoredMatrixOptions& opt0) |
| 360 | : IntMinimizeScript(opt0), |
| 361 | opt(opt0), height(opt.height()), width(opt.width()), colors(opt.colors()), |
| 362 | x(*this, height*width, 1, colors), |
| 363 | max_color(*this, 1, colors) |
| 364 | { |
| 365 | |
| 366 | max(*this, x, max_color); |
| 367 | |
| 368 | Matrix<IntVarArray> m(x, width, height); |
| 369 | |
| 370 | // For each pair of columns and rows, the intersections may not be equal. |
| 371 | if (opt.model() & MODEL_CORNERS) { |
| 372 | for (int c1 = 0; c1 < width; ++c1) { |
| 373 | for (int c2 = c1+1; c2 < width; ++c2) { |
| 374 | for (int r1 = 0; r1 < height; ++r1) { |
| 375 | for (int r2 = r1+1; r2 < height; ++r2) { |
| 376 | not_all_equal(IntVarArgs() << m(c1,r1) << m(c1,r2) << m(c2,r1) << m(c2,r2)); |
| 377 | } |
| 378 | } |
| 379 | } |
| 380 | } |
| 381 | } |
| 382 | // Given two rows/columns, construct variables representing if |
| 383 | // the corresponding places are equal (and if so, what value). |
| 384 | // For the new values, no non-zero value may appear more than |
| 385 | // once. |
| 386 | if (opt.model() & MODEL_ROWS) { |
| 387 | for (int r1 = 0; r1 < height; ++r1) { |
| 388 | for (int r2 = r1+1; r2 < height; ++r2) { |
| 389 | no_monochrome_rectangle(m.row(r1), m.row(r2)); |
| 390 | } |
| 391 | } |
| 392 | } |
| 393 | if (opt.model() & MODEL_COLUMNS) { |
| 394 | for (int c1 = 0; c1 < width; ++c1) { |
| 395 | for (int c2 = c1+1; c2 < width; ++c2) { |
| 396 | no_monochrome_rectangle(m.col(c1), m.col(c2)); |
| 397 | } |
| 398 | } |
| 399 | } |
| 400 | |
| 401 | // Symmetry breaking constraints. |
| 402 | { |
| 403 | // Lexical order for all columns and rows (all are interchangeable) |
| 404 | if (opt.symmetry() & SYMMETRY_MATRIX) { |
| 405 | for (int r = 0; r < height-1; ++r) { |
| 406 | rel(*this, m.row(r), IRT_LE, m.row(r+1)); |
| 407 | } |
| 408 | for (int c = 0; c < width-1; ++c) { |
| 409 | rel(*this, m.col(c), IRT_LE, m.col(c+1)); |
| 410 | } |
| 411 | } |
| 412 | |
| 413 | // Value precedence. Compatible with row/column ordering |
| 414 | if (opt.symmetry() & SYMMETRY_VALUES) { |
| 415 | precede(*this, x, IntArgs::create(colors, 1)); |
| 416 | } |
nothing calls this directly
no test coverage detected