46 namespace Test {
namespace Set {
51 static_cast<unsigned int>(
pow(static_cast<double>(2.0),
64 static_cast<unsigned int>(
pow(static_cast<double>(2.0),
73 :
n(n0), dsv(new
CountableSet[
n]), ir(_withInt, d0), done(false), lub(d0),
112 for (
int i=0;
i<
n;
i++) {
115 os << icsv << ((
i!=
n-1) ?
"," :
"}");
122 namespace Test {
namespace Set {
126 :
d(d0),
y(*this,
i,
d),
128 reified(false), test(
t) {
134 dom(*
this,
x[0],_x[0]);
138 olog <<
ind(2) <<
"Initial: x[]=" <<
x;
139 olog <<
" y[]=" <<
y;
150 olog <<
ind(2) <<
"Initial: x[]=" <<
x;
151 olog <<
" y[]=" <<
y;
159 reified(s.reified), test(s.test) {
164 b.update(*
this, share, sr);
178 olog <<
ind(3) <<
"Posting reified propagator" << std::endl;
182 olog <<
ind(3) <<
"Posting propagator" << std::endl;
189 olog <<
ind(3) <<
"Fixpoint: x[]=" <<
x 190 <<
" y[]=" <<
y << std::endl;
193 <<
" y[]=" <<
y << std::endl;
208 olog <<
ind(4) <<
"x[" <<
i <<
"] ";
221 olog << is << std::endl;
229 olog <<
ind(4) << cmin <<
" <= #(x[" <<
i <<
"]) <= " << cmax
238 olog <<
ind(4) <<
"y[" <<
i <<
"] ";
247 olog <<
" " <<
n << std::endl;
257 olog <<
ind(4) <<
"b = " <<
n << std::endl;
263 for (
int i=
a.size();
i--; ) {
297 for (
int j=0; j<
v; j++, ++diffV) {}
311 for (
int j=0; j<
v; j++, ++diffV) {}
325 for (
int j=0; j<
v; j++, ++interV) {}
339 for (
int j=0; j<
v; j++, ++interV) {}
350 olog <<
ind(3) <<
"Testing fixpoint on copy" << std::endl;
353 delete c;
return false;
357 if (
x[
i].glbSize() !=
c->x[
i].glbSize() ||
358 x[
i].lubSize() !=
c->x[
i].lubSize() ||
359 x[
i].cardMin() !=
c->x[
i].cardMin() ||
360 x[
i].cardMax() !=
c->x[
i].cardMax()) {
365 if (
y[
i].
size() !=
c->y[
i].size()) {
366 delete c;
return false;
369 delete c;
return false;
372 olog <<
ind(3) <<
"Finished testing fixpoint on copy" << std::endl;
380 olog <<
ind(3) <<
"Testing whether enabled space is the same" 383 bool cf =
c.failed();
390 if (
x[
i].glbSize() !=
c.x[
i].glbSize() ||
391 x[
i].lubSize() !=
c.x[
i].lubSize() ||
392 x[
i].cardMin() !=
c.x[
i].cardMin() ||
393 x[
i].cardMax() !=
c.x[
i].cardMax())
403 olog <<
ind(3) <<
"Finished testing whether enabled space is the same" 411 bool setsAssigned =
true;
412 for (
int j=
x.
size(); j--; )
414 setsAssigned =
false;
417 bool intsAssigned =
true;
418 for (
int j=
y.
size(); j--; )
420 intsAssigned =
false;
428 }
else if (setsAssigned) {
434 if (setsAssigned ||
i>=
x.
size()) {
445 if (
a.ints()[
i] <
y[
i].max()) {
448 assert((
v >
a.ints()[
i]) && (
v <=
y[
i].
max()));
453 if (
a.ints()[
i] >
y[
i].min()) {
456 assert((
v <
a.ints()[
i]) && (
v >=
y[
i].
min()));
465 if (it.
width() > skip) {
467 if (
v ==
a.ints()[
i]) {
468 if (it.
width() == 1) {
470 }
else if (
v < it.
max()) {
515 if (
x[
i].cardMin() < aisize) {
516 unsigned int newc =
x[
i].cardMin() + 1 +
518 assert( newc >
x[
i].cardMin() );
519 assert( newc <= aisize );
524 if (
x[
i].cardMax() > aisize) {
525 unsigned int newc =
x[
i].cardMax() - 1 -
527 assert( newc <
x[
i].cardMax() );
528 assert( newc >= aisize );
548 bool setsAssigned =
true;
549 for (
int j=
x.
size(); j--; )
551 setsAssigned =
false;
554 bool intsAssigned =
true;
555 for (
int j=
y.
size(); j--; )
557 intsAssigned =
false;
565 }
else if (setsAssigned) {
571 if (setsAssigned ||
i>=
x.
size()) {
582 if (
a.ints()[
i] <
y[
i].max()) {
585 assert((
v >
a.ints()[
i]) && (
v <=
y[
i].
max()));
591 if (
a.ints()[
i] >
y[
i].min()) {
594 assert((
v <
a.ints()[
i]) && (
v >=
y[
i].
min()));
604 if (it.
width() > skip) {
606 if (
v ==
a.ints()[
i]) {
607 if (it.
width() == 1) {
609 }
else if (
v < it.
max()) {
656 if (
x[
i].cardMin() < aisize) {
657 unsigned int newc =
x[
i].cardMin() + 1 +
659 assert( newc >
x[
i].cardMin() );
660 assert( newc <= aisize );
666 if (
x[
i].cardMax() > aisize) {
667 unsigned int newc =
x[
i].cardMax() - 1 -
669 assert( newc <
x[
i].cardMax() );
670 assert( newc >= aisize );
672 c.cardinality(
i, 0, newc);
706 #define CHECK_TEST(T,M) \ 708 olog << ind(3) << "Check: " << (M) << std::endl; \ 710 problem = (M); delete s; goto failed; \ 714 #define START_TEST(T) \ 717 olog << ind(2) << "Testing: " << (T) << std::endl; \ 724 const char*
test =
"NONE";
725 const char* problem =
"NONE";
730 bool is_sol = solution(
a);
732 olog <<
ind(1) <<
"Assignment: " <<
a 733 << (is_sol ?
" (solution)" :
" (no solution)")
743 olog <<
ind(3) <<
"No copy" << std::endl;
749 olog <<
ind(3) <<
"Unshared copy" << std::endl;
758 olog <<
ind(3) <<
"Unshared copy" << std::endl;
765 default: assert(
false);
776 START_TEST(
"Assignment (after posting, disable)");
810 problem =
"No fixpoint";
828 s->
post();
c->post();
831 problem =
"Different result after re-enable";
836 if (s->
failed() !=
c->failed()) {
837 problem =
"Different failure after re-enable";
845 START_TEST(
"Assignment reified (rewrite after post, <=>)");
855 START_TEST(
"Assignment reified (rewrite after post, =>)");
865 START_TEST(
"Assignment reified (rewrite after post, <=)");
876 START_TEST(
"Assignment reified (rewrite failure, <=>)");
885 START_TEST(
"Assignment reified (rewrite failure, =>)");
899 START_TEST(
"Assignment reified (rewrite failure, <=)");
912 START_TEST(
"Assignment reified (immediate rewrite, <=>)");
922 START_TEST(
"Assignment reified (immediate rewrite, =>)");
932 START_TEST(
"Assignment reified (immediate rewrite, <=)");
942 START_TEST(
"Assignment reified (immediate failure, <=>)");
951 START_TEST(
"Assignment reified (immediate failure, =>)");
965 START_TEST(
"Assignment reified (immediate failure, <=)");
979 START_TEST(
"Assignment reified (before posting, <=>)");
994 START_TEST(
"Assignment reified (before posting, =>)");
1009 START_TEST(
"Assignment reified (before posting, <=)");
1024 START_TEST(
"Assignment reified (after posting, <=>)");
1039 START_TEST(
"Assignment reified (after posting, =>)");
1054 START_TEST(
"Assignment reified (after posting, <=)");
1069 START_TEST(
"Assignment reified (after posting, <=>, disable)");
1086 START_TEST(
"Assignment reified (after posting, =>, disable)");
1103 START_TEST(
"Assignment reified (after posting, <=, disable)");
1127 problem =
"No fixpoint";
1148 problem =
"No fixpoint";
1170 problem =
"No fixpoint";
1191 olog <<
"FAILURE" << std::endl
1192 <<
ind(1) <<
"Test: " <<
test << std::endl
1193 <<
ind(1) <<
"Problem: " << problem << std::endl;
1195 olog <<
ind(1) <<
"Assignment: " <<
a << std::endl;
void removeFromLub(int v, int i, const SetAssignment &a)
Remove value v from the upper bound of x[i].
unsigned int width(void) const
Return width of range (distance between minimum and maximum)
void operator++(void)
Move to next subset.
void cardinality(int i, int cmin, int cmax)
Perform cardinality tell operation on x[i].
void disable(void)
Disable propagators in space and compute fixpoint (make all idle)
SetRelType
Common relation types for sets.
Inverse implication for reification.
Simple class for describing identation.
union Gecode::@579::NNF::@61 u
Union depending on nodetype t.
Gecode::Reify r
Reification information.
const int min
Smallest allowed integer in integer set.
Range iterator for integer sets.
void log(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
int size(void) const
Return size of array (number of elements)
const FloatNum max
Largest allowed float value.
ReifyMode mode(void) const
Return reification mode.
static Gecode::Support::RandomGenerator rand
Random number generator.
Gecode::SetVarArray x
Set variables to be tested.
unsigned int size(void) const
Return size (cardinality) of domain.
void enable(void)
Enable propagators in space.
void disable(Space &home)
Disable all propagators in a group.
static PropagatorGroup all
Group of all propagators.
bool assigned(void) const
Test whether view is assigned.
void assign(const SetAssignment &a)
Assign all variables to values in a.
void pow(Home home, FloatVar x0, int n, FloatVar x1)
Post propagator for for $n 0$.
CountableSet(void)
Default constructor.
void dom(Home home, FloatVar x, FloatVal n)
Propagates .
bool same(SetTestSpace &c)
Check whether propagation is the same as in c.
int val(void) const
Return current subset.
Space * clone(bool share_data=true, bool share_info=true, CloneStatistics &stat=unused_clone) const
Clone space.
SetOpType
Common operations for sets.
const unsigned int card
Maximum cardinality of an integer set.
SetAssignment(int n, const Gecode::IntSet &d, int i=0)
Initialize with n set variables, initial bound d and i int variables.
const int max
Largest allowed integer in integer set.
unsigned int size(Space &home) const
Return number of propagators in a group.
Iterator for the unknown ranges of a set variable.
bool reified
Whether the test is for a reified propagator.
void update(Space &, bool share, VarArray< Var > &a)
Update array to be a clone of array a.
struct Gecode::@579::NNF::@61::@63 a
For atomic nodes.
void rel(int i, Gecode::SetRelType srt, const Gecode::IntSet &is)
Perform set tell operation on x[i].
const FloatNum min
Smallest allowed float value.
Gecode::IntArgs i(4, 1, 2, 3, 4)
int n
Number of negative literals for node type.
IntRelType
Relation types for integers.
Range iterator for computing intersection (binary)
ChannelShared csv(Gecode::IPL_VAL)
static bool fixpoint(void)
Throw a coin whether to compute a fixpoint.
void post(void)
Post propagator.
bool failed(void)
Compute a fixpoint and check for failure.
Value iterator from range iterator.
unsigned int size(I &i)
Size of all ranges of range iterator i.
struct Gecode::@579::NNF::@61::@62 b
For binary nodes (and, or, eqv)
int min(void) const
Return smallest value of range.
virtual bool run(void)
Perform test.
bool log
Whether to log the tests.
Gecode::IntSet lub
The common superset for all domains.
#define START_TEST(T)
Start new test.
bool assigned(void) const
Test whether all variables are assigned.
static const IntSet empty
Empty set.
Gecode::IntSet d
Initial domain.
SetTestSpace(int n, Gecode::IntSet &d0, int i, SetTest *t, bool log=true)
Create test space without reification.
Boolean integer variables.
LinIntExpr cardinality(const SetExpr &e)
Cardinality of set expression.
SetExpr inter(const SetVarArgs &x)
Intersection of set variables.
bool prune(const SetAssignment &a)
Perform random pruning.
unsigned int propagators(void)
Return the number of propagators.
Post propagator for f(x \diamond_{\mathit{op}} y) \sim_r z \f$ void rel(Home home
Post propagator for SetVar SetOpType SetVar y
int withInt
How many integer variables to iterate.
void addToGlb(int v, int i, const SetAssignment &a)
Remove value v from the lower bound of x[i].
bool disabled(const SetAssignment &a, SetTestSpace &c)
Prune values also in a space c with disabled propagators, but not those in assignment a...
virtual void post(Gecode::Space &home, Gecode::SetVarArray &x, Gecode::IntVarArray &y)=0
Post propagator.
Base class for tests with set constraints
Generate all set assignments.
void operator++(void)
Move to next assignment.
bool fixprob(void)
Perform fixpoint computation.
void enable(Space &home, bool s=true)
Enable all propagators in a group.
std::ostringstream olog
Stream used for logging.
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVal n)
Propagates .
Gecode::IntVarArray y
Int variables to be tested.
bool subsumed(bool b)
Check for subsumption if b is true.
struct Gecode::Space::@56::@58 c
Data available only during copying.
BoolVar var(void) const
Return Boolean control variable.
Range iterator producing subsets of an IntSet.
SpaceStatus status(StatusStatistics &stat=unused_status)
Query space status.
int withInt
How many integer variables are used by the test.
int max(void) const
Return largest value of range.
Gecode toplevel namespace
Implication for reification.
std::basic_ostream< Char, Traits > & operator<<(std::basic_ostream< Char, Traits > &os, const FloatView &x)
Print float variable view.
Range iterator for computing set difference.
#define CHECK_TEST(T, M)
Check the test result and handle failed test.
SetTest * test
The test currently run.
Space for executing set tests.
Iterate all subsets of a given set.
ReifyMode
Mode for reification.
virtual Gecode::Space * copy(bool share)
Copy space during cloning.
void init(const Gecode::IntSet &s)
Initialize with set s.
Equivalence for reification (default)
int val(void) const
Return assigned value.