MCPcopy Create free account
hub / github.com/Gecode/gecode / ColoredMatrix

Method ColoredMatrix

examples/colored-matrix.cpp:359–420  ·  view source on GitHub ↗

Actual model

Source from the content-addressed store, hash-verified

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 }

Callers

nothing calls this directly

Calls 15

mFunction · 0.85
tiebreakFunction · 0.85
INT_VAR_MIN_MINFunction · 0.85
INT_VAR_SIZE_MINFunction · 0.85
INT_VAL_MINFunction · 0.85
colorsMethod · 0.80
modelMethod · 0.80
maxFunction · 0.50
IntVarArgsClass · 0.50
relFunction · 0.50
precedeFunction · 0.50
branchFunction · 0.50

Tested by

no test coverage detected