40 namespace Test {
namespace Int {
52 if (
dsv[
i]() || (
i == 0))
64 for (
int i =
n;
i--; )
73 for (
int i=
_n1;
i--; )
84 for (
int i=0;
i<
n;
i++)
85 os <<
a[
i] << ((
i!=
n-1) ?
"," :
"}");
89 namespace Test {
namespace Int {
92 :
d(d0),
x(*this,
n,Gecode::Int::Limits::min,Gecode::Int::Limits::max),
93 test(
t), reified(false) {
96 Gecode::dom(*
this,
x[0],_x[0]);
98 Gecode::dom(*
this,
x,_x);
102 olog <<
ind(2) <<
"Initial: x[]=" <<
x
108 :
d(d0),
x(*this,
n,Gecode::Int::Limits::min,Gecode::Int::Limits::max),
109 test(
t), reified(true) {
112 Gecode::dom(*
this,
x[0],_x[0]);
114 Gecode::dom(*
this,
x,_x);
118 olog <<
ind(2) <<
"Initial: x[]=" <<
x
119 <<
" b=" <<
r.
var() << std::endl;
123 : Gecode::Space(s),
d(s.
d), test(s.test), reified(s.reified) {
149 olog <<
ind(3) <<
"Posting reified propagator" << std::endl;
153 olog <<
ind(3) <<
"Posting propagator" << std::endl;
160 olog <<
ind(3) <<
"Fixpoint: " <<
x;
162 olog << std::endl <<
ind(3) <<
" --> " <<
x << std::endl;
183 using namespace Gecode;
188 if (
a[
i] <
x[
i].max()) {
191 <
unsigned int>(
x[
i].max()-
a[
i])));
192 assert((
v >
a[
i]) && (
v <=
x[
i].max()));
197 if (
a[
i] >
x[
i].min()) {
200 <
unsigned int>(
a[
i]-
x[
i].min())));
201 assert((
v <
a[
i]) && (
v >=
x[
i].min()));
211 if (it.
width() > skip) {
212 v = it.
min() +
static_cast<int>(skip);
214 if (it.
width() == 1) {
216 }
else if (
v < it.
max()) {
224 skip -= it.
width(); ++it;
235 olog <<
ind(4) <<
"x[" <<
i <<
"] ";
244 olog <<
" " <<
n << std::endl;
254 olog <<
ind(4) <<
"b = " <<
n << std::endl;
260 using namespace Gecode;
262 static_cast<int>(
Base::rand(
static_cast<unsigned int>(
a.size()))) : -1;
263 for (
int j=
a.size(); j--; )
273 using namespace Gecode;
281 using namespace Gecode;
287 <
unsigned int>(
x[
i].max()-
x[
i].min())));
288 assert((
v >
x[
i].min()) && (
v <=
x[
i].max()));
294 <
unsigned int>(
x[
i].max()-
x[
i].min())));
295 assert((
v <
x[
i].max()) && (
v >=
x[
i].min()));
300 static_cast<int>(
Base::rand(
static_cast<unsigned int>(
x[
i].
size()-1))+1); vals--; ) {
305 if (it.
width() > skip) {
306 v = it.
min() +
static_cast<int>(skip);
break;
308 skip -= it.
width(); ++it;
322 using namespace Gecode;
336 olog <<
ind(3) <<
"Testing fixpoint on copy" << std::endl;
340 olog <<
ind(4) <<
"Copy failed after posting" << std::endl;
341 delete c;
return false;
343 for (
int j=
x.
size(); j--; )
344 if (
x[j].
size() !=
c->x[j].size()) {
346 olog <<
ind(4) <<
"Different domain size" << std::endl;
347 delete c;
return false;
351 olog <<
ind(4) <<
"Different control variable" << std::endl;
352 delete c;
return false;
355 olog <<
ind(3) <<
"Finished testing fixpoint on copy" << std::endl;
375 using namespace Gecode;
395 olog <<
ind(3) <<
"No failure on disabled copy" << std::endl;
402 olog <<
ind(3) <<
"Failure on disabled copy" << std::endl;
405 for (
int j=
x.
size(); j--; ) {
406 if (
x[j].
size() !=
c.x[j].size()) {
408 olog <<
ind(4) <<
"Different domain size" << std::endl;
413 olog <<
ind(4) <<
"Different control variable" << std::endl;
446 #define CHECK_TEST(T,M) \
448 olog << ind(3) << "Check: " << (M) << std::endl; \
450 problem = (M); delete s; goto failed; \
454 #define START_TEST(T) \
457 olog << ind(2) << "Testing: " << (T) << std::endl; \
472 using namespace Gecode;
473 const char*
test =
"NONE";
474 const char* problem =
"NONE";
482 post(*search_s,search_s->
x);
490 bool sol = solution(
a);
492 olog <<
ind(1) <<
"Assignment: " <<
a
493 << (sol ?
" (solution)" :
" (no solution)")
505 olog <<
ind(3) <<
"No copy" << std::endl;
511 olog <<
ind(3) <<
"Copy" << std::endl;
518 default: assert(
false);
529 START_TEST(
"Partial assignment (after posting)");
544 START_TEST(
"Assignment (after posting, disable)");
559 START_TEST(
"Partial assignment (after posting, disable)");
589 START_TEST(
"Partial assignment (before posting)");
609 if (!s->
prune(
a,testfix)) {
610 problem =
"No fixpoint";
627 s->
post();
c->post();
630 problem =
"Different result after re-enable";
634 if (testfix && (s->
failed() !=
c->failed())) {
635 problem =
"Different failure after re-enable";
644 START_TEST(
"Assignment reified (rewrite after post, <=>)");
654 START_TEST(
"Assignment reified (rewrite failure, <=>)");
663 START_TEST(
"Assignment reified (immediate rewrite, <=>)");
673 START_TEST(
"Assignment reified (immediate failure, <=>)");
682 START_TEST(
"Assignment reified (before posting, <=>)");
697 START_TEST(
"Assignment reified (after posting, <=>)");
712 START_TEST(
"Assignment reified (after posting, <=>, disable)");
734 if (!s->
prune(
a,testfix)) {
735 problem =
"No fixpoint";
753 s->
post();
c->post();
757 problem =
"No fixpoint";
764 CHECK_TEST(
c->r.var().assigned(),
"Control variable unassigned");
766 CHECK_TEST(
c->r.var().val()==1,
"Zero on solution");
768 CHECK_TEST(
c->r.var().val()==0,
"One on non-solution");
777 START_TEST(
"Assignment reified (rewrite after post, =>)");
787 START_TEST(
"Assignment reified (rewrite failure, =>)");
801 START_TEST(
"Assignment reified (immediate rewrite, =>)");
811 START_TEST(
"Assignment reified (immediate failure, =>)");
825 START_TEST(
"Assignment reified (before posting, =>)");
840 START_TEST(
"Assignment reified (after posting, =>)");
855 START_TEST(
"Assignment reified (after posting, =>, disable)");
877 if (!s->
prune(
a,testfix)) {
878 problem =
"No fixpoint";
896 s->
post();
c->post();
900 problem =
"No fixpoint";
908 CHECK_TEST(!
c->r.var().assigned(),
"Control variable assigned");
910 CHECK_TEST(
c->r.var().assigned(),
"Control variable unassigned");
911 CHECK_TEST(
c->r.var().val()==0,
"One on non-solution");
920 START_TEST(
"Assignment reified (rewrite after post, <=)");
930 START_TEST(
"Assignment reified (rewrite failure, <=)");
944 START_TEST(
"Assignment reified (immediate rewrite, <=)");
954 START_TEST(
"Assignment reified (immediate failure, <=)");
968 START_TEST(
"Assignment reified (before posting, <=)");
983 START_TEST(
"Assignment reified (after posting, <=)");
998 START_TEST(
"Assignment reified (after posting, <=, disable)");
1020 if (!s->
prune(
a,testfix)) {
1021 problem =
"No fixpoint";
1039 s->
post();
c->post();
1043 problem =
"No fixpoint";
1049 CHECK_TEST(
c->propagators()==0,
"No subsumption");
1051 CHECK_TEST(
c->r.var().assigned(),
"Control variable unassigned");
1052 CHECK_TEST(
c->r.var().val()==1,
"Zero on solution");
1054 CHECK_TEST(!
c->r.var().assigned(),
"Control variable assigned");
1066 CHECK_TEST(s != NULL,
"Solutions exhausted");
1068 for (
int i=
a.size();
i--; ) {
1081 if (e_s.
next() != NULL) {
1082 problem =
"Excess solutions";
1106 for (
int i = s->
x.
size();
i--; )
1121 for (
int i = s->
x.
size();
i--; )
1139 olog <<
"FAILURE" << std::endl
1140 <<
ind(1) <<
"Test: " <<
test << std::endl
1141 <<
ind(1) <<
"Problem: " << problem << std::endl;
1143 olog <<
ind(1) <<
"Assignment: " <<
a << std::endl;
struct Gecode::@602::NNF::@65::@66 b
For binary nodes (and, or, eqv)
int n
Number of negative literals for node type.
Node * x
Pointer to corresponding Boolean expression node.
struct Gecode::@602::NNF::@65::@67 a
For atomic nodes.
Boolean integer variables.
unsigned int size(void) const
Return size (cardinality) of domain.
int val(void) const
Return assigned value.
Depth-first search engine.
std::basic_ostream< Char, Traits > & operator<<(std::basic_ostream< Char, Traits > &os, const FloatView &x)
Print float variable view.
void init(const IntSet &s)
Initialize with values for s.
Passing integer variables.
int max(void) const
Return largest value of range.
int min(void) const
Return smallest value of range.
unsigned int width(void) const
Return width of range (distance between minimum and maximum)
void threads(double n)
Set number of parallel threads.
unsigned int size(Space &home) const
Return number of propagators in a group.
void disable(Space &home)
Disable all propagators in a group.
void enable(Space &home, bool s=true)
Enable all propagators in a group.
static PropagatorGroup all
Group of all propagators.
Reification specification.
BoolVar var(void) const
Return Boolean control variable.
ReifyMode mode(void) const
Return reification mode.
virtual T * next(void)
Return next solution (NULL, if none exists or search has been stopped)
struct Gecode::Space::@61::@63 c
Data available only during copying.
bool assigned(void) const
Test if all variables are assigned.
int size(void) const
Return size of array (number of elements)
void update(Space &home, VarArray< Var > &a)
Update array to be a clone of array a.
bool assigned(void) const
Test whether view is assigned.
static Gecode::Support::RandomGenerator rand
Random number generator.
static bool fixpoint(void)
Throw a coin whether to compute a fixpoint.
Base class for assignments
Gecode::IntSet d
Domain for each variable.
int n
Number of variables.
Generate all assignments.
Gecode::IntSetValues * dsv
Iterator for each variable.
virtual void operator++(void)
Move to next assignment.
int a
How many assigments still to be generated Generate new value according to domain.
int * vals
The current values for the variables.
virtual void operator++(void)
Move to next assignment.
int _n1
How many variables in the second set.
Gecode::IntSet _d1
Domain for second set of variables Generate new value according to domain d.
int a
How many assigments still to be generated.
int * vals
The current values for the variables.
virtual void operator++(void)
Move to next assignment.
int randval(const Gecode::IntSet &d)
Space for executing tests.
Gecode::Reify r
Reification information.
TestSpace(int n, Gecode::IntSet &d, Test *t)
Create test space without reification.
Gecode::IntSet d
Initial domain.
void rndrel(const Assignment &a, int i, Gecode::IntRelType &irt, int &v)
Randomly select a pruning rel for variable i.
Test * test
The test currently run.
virtual Gecode::Space * copy(void)
Copy space during cloning.
void post(void)
Post propagator.
bool assigned(void) const
Test whether all variables are assigned.
void prune(void)
Prune some random values for some random variable.
void bound(void)
Assing a random variable to a random bound.
void assign(const Assignment &a, bool skip=false)
Assign all (or all but one, if skip is true) variables to values in a.
bool failed(void)
Compute a fixpoint and check for failure.
bool reified
Whether the test is for a reified propagator.
void prune(int i, bool bounds_only)
Prune some random values from variable i.
int rndvar(void)
Randomly select an unassigned variable.
bool disabled(const Assignment &a, TestSpace &c, bool testfix)
Prune values also in a space c with disabled propagators, but not those in assignment a.
void disable(void)
Disable propagators in space and compute fixpoint (make all idle)
Gecode::IntVarArray x
Variables to be tested.
void enable(void)
Enable propagators in space.
void rel(int i, Gecode::IntRelType irt, int n)
Perform integer tell operation on x[i].
unsigned int propagators(void)
Return the number of propagators.
virtual bool run(void)
Perform test.
virtual bool ignore(const Assignment &) const
Whether to ignore assignment for reification.
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)=0
Post constraint.
virtual Assignment * assignment(void) const
Create assignment.
bool log
Whether to log the tests.
Simple class for describing identation.
void dom(Home home, FloatVar x, FloatVal n)
Propagates .
void ignore(Actor &a, ActorProperty p, bool duplicate=false)
Ignore actor property.
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVal n)
Propagates .
Reify imp(BoolVar x)
Use implication for reification.
IntRelType
Relation types for integers.
Reify eqv(BoolVar x)
Use equivalence for reification.
ReifyMode
Mode for reification.
BoolOpType
Operation types for Booleans.
Reify pmi(BoolVar x)
Use reverse implication for reification.
IntPropLevel
Propagation levels for integer propagators.
@ IRT_GQ
Greater or equal ( )
@ IRT_LQ
Less or equal ( )
@ RM_IMP
Implication for reification.
@ RM_PMI
Inverse implication for reification.
@ RM_EQV
Equivalence for reification (default)
@ IPL_BASIC
Use basic propagation algorithm.
@ IPL_BASIC_ADVANCED
Use both.
@ IPL_DOM
Domain propagation Options: basic versus advanced propagation.
@ IPL_VAL
Value propagation.
@ IPL_ADVANCED
Use advanced propagation algorithm.
@ IPL_BND
Bounds propagation.
SpaceStatus status(StatusStatistics &stat=unused_status)
Query space status.
Space * clone(CloneStatistics &stat=unused_clone) const
Clone space.
@ SS_FAILED
Space is failed
IntValBranch INT_VAL_MIN(void)
Select smallest value.
IntVarBranch INT_VAR_NONE(void)
Select first unassigned variable.
unsigned int size(I &i)
Size of all ranges of range iterator i.
Gecode::IntArgs i({1, 2, 3, 4})
@ CTL_BOUNDS_Z
Test for bounds(z)-consistency.
@ CTL_BOUNDS_D
Test for bounds(d)-consistency.
@ CTL_NONE
No consistency-test.
@ CTL_DOMAIN
Test for domain-consistency.
std::ostringstream olog
Stream used for logging.
#define START_TEST(T)
Start new test.
#define CHECK_TEST(T, M)
Check the test result and handle failed test.