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

Method solution

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

%Test whether \a x is solution

Source from the content-addressed store, hash-verified

374 }
375 /// %Test whether \a x is solution
376 bool solution(const SetAssignment& x) const {
377 int* isrs = new int[n];
378 for (int i=0; i<n; i++)
379 isrs[i] = x.ints()[i];
380
381 IntSet iss(isrs,n);
382 CountableSetRanges xnr(x.lub, x[0]);
383
384 switch (sot) {
385 case SOT_DUNION:
386 {
387 IntSetRanges issr(iss);
388 unsigned int cardSum = Iter::Ranges::size(issr);
389 if (cardSum != static_cast<unsigned int>(n)) {
390 delete[] isrs;
391 return false;
392 }
393 if (withConst) {
394 IntSetRanges isr(is);
395 cardSum += Iter::Ranges::size(isr);
396 }
397 CountableSetRanges xnr2(x.lub, x[0]);
398 if (cardSum != Iter::Ranges::size(xnr2)) {
399 delete[] isrs;
400 return false;
401 }
402 }
403 // fall through to union case
404 case SOT_UNION:
405 {
406 if (withConst) {
407 IntSetRanges issr(iss);
408 IntSetRanges isr(is);
409 Iter::Ranges::Union<IntSetRanges,IntSetRanges > uu(isr, issr);
410 delete[] isrs;
411 return Iter::Ranges::equal(uu, xnr);
412 } else {
413 IntSetRanges issr(iss);
414 delete[] isrs;
415 return Iter::Ranges::equal(issr, xnr);
416 }
417 }
418 case SOT_INTER:
419 {
420 bool allEqual = true;
421 for (int i=1; i<n; i++) {
422 if (isrs[i] != isrs[0]) {
423 allEqual = false;
424 break;
425 }
426 }
427 if (withConst) {
428 if (allEqual) {
429 if (n == 0) {
430 IntSetRanges isr(is);
431 delete[] isrs;
432 return Iter::Ranges::equal(isr, xnr);
433 } else {

Callers

nothing calls this directly

Calls 2

sizeFunction · 0.50
equalFunction · 0.50

Tested by

no test coverage detected