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

Method solution

test/set/channel.cpp:108–126  ·  view source on GitHub ↗

%Test whether \a x is solution

Source from the content-addressed store, hash-verified

106 : SetTest(t,_ssize,d,false,_isize), ssize(_ssize), isize(_isize) {}
107 /// %Test whether \a x is solution
108 virtual bool solution(const SetAssignment& x) const {
109 for (int i=0; i<isize; i++) {
110 if (x.ints()[i] < 0 || x.ints()[i] >= ssize)
111 return false;
112 Iter::Ranges::Singleton single(i,i);
113 CountableSetRanges csr(x.lub, x[x.ints()[i]]);
114 if (!Iter::Ranges::subset(single, csr))
115 return false;
116 }
117 for (int i=0; i<ssize; i++) {
118 int size = 0;
119 for (CountableSetValues csv(x.lub, x[i]); csv(); ++csv) {
120 if (csv.val() < 0 || csv.val() >= isize) return false;
121 if (x.ints()[csv.val()] != i) return false;
122 size++;
123 }
124 }
125 return true;
126 }
127 /// Post constraint on \a x
128 virtual void post(Space& home, SetVarArray& x, IntVarArray& y) {
129 Gecode::channel(home, y, x);

Callers

nothing calls this directly

Calls 2

subsetFunction · 0.50
valMethod · 0.45

Tested by

no test coverage detected