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

Method Nonogram

examples/nonogram.cpp:107–167  ·  view source on GitHub ↗

Construction of the model.

Source from the content-addressed store, hash-verified

105
106 /// Construction of the model.
107 Nonogram(const SizeOptions& opt)
108 : Script(opt), spec(specs[opt.size()]), b(*this,width()*height(),0,1) {
109 Matrix<BoolVarArray> m(b, width(), height());
110
111 {
112 int spos = 2;
113 // Post constraints for columns
114 for (int w=0; w<width(); w++)
115 extensional(*this, m.col(w), line(spos));
116 // Post constraints for rows
117 for (int h=0; h<height(); h++)
118 extensional(*this, m.row(h), line(spos));
119 }
120
121
122
123 switch (opt.branching()) {
124 case BRANCH_NONE:
125 {
126 /*
127 * The following branches either by columns or rows, depending on
128 * whether there are more hints relative to the height or width
129 * for columns or rows.
130 *
131 * This idea is due to Pascal Van Hentenryck and has been suggested
132 * to us by Hakan Kjellerstrand.
133 */
134
135 // Number of hints for columns
136 int cols = 0;
137 // Number of hints for rows
138 int rows = 0;
139 int spos = 2;
140 for (int w=0; w<width(); w++) {
141 int hint = spec[spos++];
142 cols += hint; spos += hint;
143 }
144 for (int h=0; h<height(); h++) {
145 int hint = spec[spos++];
146 rows += hint; spos += hint;
147 }
148
149 if (rows*width() > cols*height()) {
150 for (int w=0; w<width(); w++)
151 branch(*this, m.col(w), BOOL_VAR_NONE(), BOOL_VAL_MAX());
152 } else {
153 for (int h=0; h<height(); h++)
154 branch(*this, m.row(h), BOOL_VAR_NONE(), BOOL_VAL_MAX());
155 }
156 }
157 break;
158 case BRANCH_AFC:
159 /*
160 * The following just uses the AFC for branching. This is
161 * equivalent to SIZE/AFC in this case since the variables are
162 * binary.
163 */
164 branch(*this, b, BOOL_VAR_AFC_MAX(opt.decay()), BOOL_VAL_MAX());

Callers

nothing calls this directly

Calls 12

widthFunction · 0.85
BOOL_VAR_NONEFunction · 0.85
BOOL_VAL_MAXFunction · 0.85
BOOL_VAR_AFC_MAXFunction · 0.85
branchingMethod · 0.80
extensionalFunction · 0.50
branchFunction · 0.50
sizeMethod · 0.45
colMethod · 0.45
rowMethod · 0.45
decayMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected