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

Method SudokuInt

examples/sudoku-advanced.cpp:105–179  ·  view source on GitHub ↗

Constructor

Source from the content-addressed store, hash-verified

103#endif
104 /// Constructor
105 SudokuInt(const SizeOptions& opt)
106 : Sudoku(opt), x(*this, n*n*n*n, 1, n*n) {
107 const int nn = n*n;
108 Matrix<IntVarArray> m(x, nn, nn);
109
110 // Constraints for rows and columns
111 for (int i=0; i<nn; i++) {
112 distinct(*this, m.row(i), opt.ipl());
113 distinct(*this, m.col(i), opt.ipl());
114 }
115
116 // Constraints for squares
117 for (int i=0; i<nn; i+=n) {
118 for (int j=0; j<nn; j+=n) {
119 distinct(*this, m.slice(i, i+n, j, j+n), opt.ipl());
120 }
121 }
122
123 // Fill-in predefined fields
124 for (int i=0; i<nn; i++)
125 for (int j=0; j<nn; j++)
126 if (int v = sudokuField(examples[opt.size()], nn, i, j))
127 rel(*this, m(i,j), IRT_EQ, v );
128
129#ifdef GECODE_HAS_SET_VARS
130 if (opt.propagation() == PROP_SAME) {
131 // Implied constraints linking squares and rows
132 for (int b=0; b<n; b++) {
133 int b1c = 0;
134 int b2c = 0;
135 IntVarArgs bc1(nn-n);
136 IntVarArgs bc2(nn-n);
137 IntVarArgs br1(nn-n);
138 IntVarArgs br2(nn-n);
139 for (int i=0; i<n; i++)
140 for (int j=0; j<n; j++) {
141 b1c = 0; b2c = 0;
142 for (int k=0; k<n; k++) {
143 if (k != j) {
144 IntVarArgs bc1s = block_col(m, b, i, k);
145 IntVarArgs br1s = block_row(m, b, i, k);
146 for (int count=0; count<n; count++) {
147 bc1[b1c] = bc1s[count];
148 br1[b1c] = br1s[count];
149 ++b1c;
150 }
151 }
152 if (k != i) {
153 IntVarArgs bc2s = block_col(m, b, k, j);
154 IntVarArgs br2s = block_row(m, b, k, j);
155 for (int count=0; count<n; count++) {
156 bc2[b2c] = bc2s[count];
157 br2[b2c] = br2s[count];
158 ++b2c;
159 }
160 }
161 }
162 same(*this, nn, bc1, bc2);

Callers

nothing calls this directly

Calls 15

distinctFunction · 0.85
sudokuFieldFunction · 0.85
mFunction · 0.85
INT_VAR_NONEFunction · 0.85
INT_VAL_SPLIT_MINFunction · 0.85
INT_VAR_SIZE_MINFunction · 0.85
INT_VAR_DEGREE_SIZE_MAXFunction · 0.85
INT_VAR_AFC_SIZE_MAXFunction · 0.85
INT_VAR_AFC_MAXFunction · 0.85
propagationMethod · 0.80
branchingMethod · 0.80
relFunction · 0.50

Tested by

no test coverage detected