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

Method solution

test/set/rel-op.cpp:189–304  ·  view source on GitHub ↗

%Test whether \a x is solution

Source from the content-addressed store, hash-verified

187 }
188 /// %Test whether \a x is solution
189 bool solution(const SetAssignment& x) const {
190 int realN = shared == 0 ? n : 3;
191
192 CountableSetRanges* isrs = new CountableSetRanges[realN];
193
194 switch (shared) {
195 case 0:
196 for (int i=realN; i--; )
197 isrs[i].init(x.lub, x[i]);
198 break;
199 case 1:
200 isrs[0].init(x.lub, x[0]);
201 isrs[1].init(x.lub, x[0]);
202 isrs[2].init(x.lub, x[1]);
203 break;
204 case 2:
205 isrs[0].init(x.lub, x[0]);
206 isrs[1].init(x.lub, x[1]);
207 isrs[2].init(x.lub, x[2]);
208 break;
209 case 3:
210 isrs[0].init(x.lub, x[0]);
211 isrs[1].init(x.lub, x[1]);
212 isrs[2].init(x.lub, x[0]);
213 break;
214 default:
215 GECODE_NEVER;
216 }
217
218 int result = shared == 0 ? x.size() - 1 : (shared <= 2 ? 2 : 0);
219 CountableSetRanges xnr(x.lub, x[result]);
220
221 switch (sot) {
222 case SOT_DUNION:
223 {
224 if (shared == 1 && (isrs[0]() || isrs[1]())) {
225 delete[] isrs; return false;
226 }
227 if (shared == 3 && (isrs[0]() || isrs[2]())) {
228 delete[] isrs; return false;
229 }
230 unsigned int cardSum = 0;
231 if (shared == 1 || shared == 3) {
232 CountableSetRanges x1r(x.lub, x[1]);
233 cardSum = Iter::Ranges::size(x1r);
234 } else {
235 for (int i=0; i<realN; i++) {
236 CountableSetRanges xir(x.lub, x[i]);
237 cardSum += Iter::Ranges::size(xir);
238 }
239 }
240 if (withConst)
241 cardSum += 2;
242 CountableSetRanges xnr2(x.lub, x[result]);
243 if (cardSum != Iter::Ranges::size(xnr2)) {
244 delete[] isrs; return false;
245 }
246 }

Callers

nothing calls this directly

Calls 4

sizeFunction · 0.50
equalFunction · 0.50
initMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected