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

Class IntVar

test/int/count.cpp:120–143  ·  view source on GitHub ↗

%Test number of equal integers equal to integer variable

Source from the content-addressed store, hash-verified

118
119 /// %Test number of equal integers equal to integer variable
120 class IntVar : public Test {
121 protected:
122 /// Integer relation type to propagate
123 Gecode::IntRelType irt;
124 public:
125 /// Create and register test
126 IntVar(Gecode::IntRelType irt0)
127 : Test("Count::Int::Var::"+str(irt0),5,-2,2), irt(irt0) {}
128 /// %Test whether \a x is solution
129 virtual bool solution(const Assignment& x) const {
130 int m = 0;
131 for (int i=0; i<4; i++)
132 if (x[i] == 0)
133 m++;
134 return cmp(m,irt,x[4]);
135 }
136 /// Post constraint on \a x
137 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
138 Gecode::IntVarArgs y(4);
139 for (int i=0; i<4; i++)
140 y[i]=x[i];
141 Gecode::count(home, y, 0, irt, x[4]);
142 }
143 };
144
145 /// %Test number of integers contained in an integer set equal to integer variable
146 class SetVar : public Test {

Callers 3

runMethod · 0.70
postMethod · 0.70
constrainMethod · 0.50

Calls

no outgoing calls

Tested by

no test coverage detected