53 if (
dsv[i]() || (i == 0))
64 for (
int i = this->
n; i--; )
71 for (
int i=
n-
_n1; i--; )
73 for (
int i=
_n1; i--; )
84 for (
int i=0; i<n; i++)
85 os << a[i] << ((i!=n-1) ?
"," :
"}");
102 olog <<
ind(2) <<
"Initial: x[]=" <<
x
118 olog <<
ind(2) <<
"Initial: x[]=" <<
x
119 <<
" b=" <<
r.var() << std::endl;
124 x.update(*
this, s.
x);
138 for (
int i=
x.size(); i--; )
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;
173 int i =
static_cast<int>(rand(
static_cast<unsigned int>(
x.size())));
175 i = (i+1) %
x.size();
188 if (a[i] <
x[i].
max()) {
190 static_cast<unsigned int>(
x[i].max()) -
static_cast<unsigned int>(a[i]);
191 unsigned int offset = rand(n);
192 v =
static_cast<int>(
static_cast<long long>(a[i]) + 1LL + offset);
193 assert((v > a[i]) && (v <=
x[i].
max()));
198 if (a[i] >
x[i].
min()) {
200 static_cast<unsigned int>(a[i]) -
static_cast<unsigned int>(
x[i].
min());
201 unsigned int offset = rand(n);
202 v =
static_cast<int>(
static_cast<long long>(
x[i].min()) + offset);
203 assert((v < a[i]) && (v >=
x[i].
min()));
210 unsigned int skip = rand(
static_cast<unsigned int>(
x[i].size()-1));
212 if (it.
width() > skip) {
213 v =
static_cast<int>(
static_cast<long long>(it.
min()) + skip);
215 if (it.
width() == 1) {
217 }
else if (v < it.
max()) {
225 skip -= it.
width(); ++it;
236 olog <<
ind(4) <<
"x[" << i <<
"] ";
245 olog <<
" " << n << std::endl;
255 olog <<
ind(4) <<
"b = " << n << std::endl;
263 static_cast<int>(rand(
static_cast<unsigned int>(a.
size()))) : -1;
264 for (
int j=a.
size(); j--; )
287 static_cast<unsigned int>(
x[i].max()) -
288 static_cast<unsigned int>(
x[i].min());
289 unsigned int offset = rand(n);
290 int v =
static_cast<int>(
static_cast<long long>(
x[i].min()) +
292 assert((v >
x[i].
min()) && (v <=
x[i].
max()));
297 static_cast<unsigned int>(
x[i].max()) -
298 static_cast<unsigned int>(
x[i].min());
299 unsigned int offset = rand(n);
300 int v =
static_cast<int>(
static_cast<long long>(
x[i].min()) + offset);
301 assert((v <
x[i].
max()) && (v >=
x[i].
min()));
306 static_cast<int>(rand(
static_cast<unsigned int>(
x[i].size()-1))+1); vals--; ) {
309 unsigned int skip = rand(
x[i].size()-1);
311 if (it.
width() > skip) {
312 v =
static_cast<int>(
static_cast<long long>(it.
min()) + skip);
315 skip -= it.
width(); ++it;
335 rndrel(a, i, irt, v, rand);
343 olog <<
ind(3) <<
"Testing fixpoint on copy" << std::endl;
347 olog <<
ind(4) <<
"Copy failed after posting" << std::endl;
348 delete c;
return false;
350 for (
int j=
x.size(); j--; )
351 if (
x[j].size() !=
c->x[j].size()) {
353 olog <<
ind(4) <<
"Different domain size" << std::endl;
354 delete c;
return false;
356 if (
reified && (
r.var().size() !=
c->r.var().size())) {
358 olog <<
ind(4) <<
"Different control variable" << std::endl;
359 delete c;
return false;
362 olog <<
ind(3) <<
"Finished testing fixpoint on copy" << std::endl;
389 rndrel(a, i, irt, v, rand);
401 olog <<
ind(3) <<
"No failure on disabled copy" << std::endl;
408 olog <<
ind(3) <<
"Failure on disabled copy" << std::endl;
411 for (
int j=
x.size(); j--; ) {
412 if (
x[j].size() !=
c.x[j].size()) {
414 olog <<
ind(4) <<
"Different domain size" << std::endl;
417 if (
reified && (
r.var().size() !=
c.r.var().size())) {
419 olog <<
ind(4) <<
"Different control variable" << std::endl;
452#define CHECK_TEST(T,M) \
455 olog << ind(3) << "Check: " << (M) << std::endl; \
457 problem = (M); delete s; goto failed; \
462#define START_TEST(T) \
466 olog << ind(2) << "Testing: " << (T) << std::endl; \
483 const char* test =
"NONE";
484 const char* problem =
"NONE";
492 post(*search_s,search_s->
x);
499 while (a.has_more()) {
502 olog <<
ind(1) <<
"Assignment: " << a
503 << (sol ?
" (solution)" :
" (no solution)")
515 olog <<
ind(3) <<
"No copy" << std::endl;
521 olog <<
ind(3) <<
"Copy" << std::endl;
528 default: assert(
false);
539 START_TEST(
"Partial assignment (after posting)");
554 START_TEST(
"Assignment (after posting, disable)");
569 START_TEST(
"Partial assignment (after posting, disable)");
599 START_TEST(
"Partial assignment (before posting)");
620 problem =
"No fixpoint";
637 s->
post(); c->post();
640 problem =
"Different result after re-enable";
645 problem =
"Different failure after re-enable";
654 START_TEST(
"Assignment reified (rewrite after post, <=>)");
664 START_TEST(
"Assignment reified (rewrite failure, <=>)");
673 START_TEST(
"Assignment reified (immediate rewrite, <=>)");
683 START_TEST(
"Assignment reified (immediate failure, <=>)");
692 START_TEST(
"Assignment reified (before posting, <=>)");
707 START_TEST(
"Assignment reified (after posting, <=>)");
722 START_TEST(
"Assignment reified (after posting, <=>, disable)");
745 problem =
"No fixpoint";
763 s->
post(); c->post();
767 problem =
"No fixpoint";
773 CHECK_TEST(c->propagators()==0,
"No subsumption");
774 CHECK_TEST(c->r.var().assigned(),
"Control variable unassigned");
776 CHECK_TEST(c->r.var().val()==1,
"Zero on solution");
778 CHECK_TEST(c->r.var().val()==0,
"One on non-solution");
787 START_TEST(
"Assignment reified (rewrite after post, =>)");
797 START_TEST(
"Assignment reified (rewrite failure, =>)");
811 START_TEST(
"Assignment reified (immediate rewrite, =>)");
821 START_TEST(
"Assignment reified (immediate failure, =>)");
835 START_TEST(
"Assignment reified (before posting, =>)");
850 START_TEST(
"Assignment reified (after posting, =>)");
865 START_TEST(
"Assignment reified (after posting, =>, disable)");
888 problem =
"No fixpoint";
906 s->
post(); c->post();
910 problem =
"No fixpoint";
916 CHECK_TEST(c->propagators()==0,
"No subsumption");
918 CHECK_TEST(!c->r.var().assigned(),
"Control variable assigned");
920 CHECK_TEST(c->r.var().assigned(),
"Control variable unassigned");
921 CHECK_TEST(c->r.var().val()==0,
"One on non-solution");
930 START_TEST(
"Assignment reified (rewrite after post, <=)");
940 START_TEST(
"Assignment reified (rewrite failure, <=)");
954 START_TEST(
"Assignment reified (immediate rewrite, <=)");
964 START_TEST(
"Assignment reified (immediate failure, <=)");
978 START_TEST(
"Assignment reified (before posting, <=)");
993 START_TEST(
"Assignment reified (after posting, <=)");
1008 START_TEST(
"Assignment reified (after posting, <=, disable)");
1031 problem =
"No fixpoint";
1049 s->
post(); c->post();
1053 problem =
"No fixpoint";
1059 CHECK_TEST(c->propagators()==0,
"No subsumption");
1061 CHECK_TEST(c->r.var().assigned(),
"Control variable unassigned");
1062 CHECK_TEST(c->r.var().val()==1,
"Zero on solution");
1064 CHECK_TEST(!c->r.var().assigned(),
"Control variable assigned");
1076 CHECK_TEST(s !=
nullptr,
"Solutions exhausted");
1078 for (
int i=a.
size(); i--; ) {
1080 CHECK_TEST(a[i] == s->
x[i].val(),
"Wrong value in solution");
1091 if (e_s.
next() !=
nullptr) {
1092 problem =
"Excess solutions";
1116 for (
int i = s->
x.
size(); i--; )
1131 for (
int i = s->
x.
size(); i--; )
1149 olog <<
"FAILURE" << std::endl
1150 <<
ind(1) <<
"Test: " << test << std::endl
1151 <<
ind(1) <<
"Problem: " << problem << std::endl;
1152 if (a.has_more() &&
opt.log)
1153 olog <<
ind(1) <<
"Assignment: " << a << std::endl;
1161 :
Test(
name,items0+extra,domain,false,level),
items(items0) {}
1167 for (
int i=0; i<
items; i++)
1197 olog <<
ind(3) <<
"Posting with " <<
list.known_length()
1198 <<
" open-list items" << std::endl;
1206 for (
int i=0; i<
x.size(); i++)
1221 int nonsolutions = 0;
1222 std::unique_ptr<Assignment> assignments(
assignment());
1224 for (; a.has_more() && ((solutions < 16) || (nonsolutions < 16));
1227 int& checked = sol ? solutions : nonsolutions;
1233 olog <<
ind(1) <<
"Open-list assignment: " << a
1234 << (sol ?
" (solution)" :
" (no solution)") << std::endl;
1238 s.list.materialize(s,
items);
1241 s.assign(a,
false,
_rand);
1244 return s.failed() == !sol;
1247 const auto history = [&]() {
1249 const int post_at = (
items == 0) ? 0 :
1250 static_cast<int>(
_rand(
static_cast<unsigned int>(
items)));
1251 const int clone_at = (
items == 0) ? 0 : post_at +
1252 static_cast<int>(
_rand(
static_cast<unsigned int>(
items-post_at)));
1253 for (
int n=0; n<=
items; n++) {
1262 if (available > 0) {
1263 int i =
static_cast<int>
1264 (
_rand(
static_cast<unsigned int>(available)));
1268 if (
_rand(4) == 0) {
1275 s.
rel(i,relation,value);
1282 if (n == clone_at) {
1284 olog <<
ind(3) <<
"Cloning open list" << std::endl;
1289 for (
int i=0; i<
arity; i++)
1290 sizes[i] =
static_cast<int>(s.
x[i].
size());
1291 std::unique_ptr<OpenTestSpace> c
1299 for (
int i=0; i<
arity; i++)
1300 if (s.
x[i].
size() !=
static_cast<unsigned int>(sizes[i]))
1305 const int end = std::min(
items,n+1+
static_cast<int>(
_rand(2)));
1306 if (
_rand(2) == 0) {
1308 olog <<
ind(3) <<
"Appending through item " << end-1
1314 olog <<
ind(3) <<
"Requiring " << end <<
" items"
1325 olog <<
"FAILURE in incremental open-list history" << std::endl;
Boolean integer variables.
int val(void) const
Return assigned value.
Depth-first search engine.
FloatNum size(void) const
Return size of float value (distance between maximum and minimum).
Passing integer arguments.
Passing integer variables.
int min(void) const
Return minimum of domain.
int max(void) const
Return maximum of domain.
Range iterator for integer views.
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).
Open list of integer variables.
Space-local list of variables with an open length.
void close(Space &home)
Close the list at its materialized length.
int known_length(void) const
Return the number of constructed positions (their values may be unassigned).
IntVar length(void) const
Return the eventual-length variable.
void append(Space &home, Var x)
Append variable x.
void threads(double n)
Set number of parallel threads.
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 (nullptr, if none exists or search has been stopped).
struct Gecode::Space::@055132133326276162005044145100211202071356247106::@155123175027073262103111264343315000271204104107 c
Data available only during copying.
SpaceStatus status(void)
Query space status without collecting statistics.
bool assigned(void) const
Test if all variables are assigned.
int size(void) const
Return size of array (number of elements).
bool assigned(void) const
Test whether view is assigned.
Gecode::Support::RandomGenerator _rand
Random number generator.
bool fixpoint(void)
Throw a coin whether to compute a fixpoint.
const std::string & name(void) const
Return name of test.
Base class for assignments
Gecode::IntSet d
Domain for each variable.
int n
Number of variables.
Generate all assignments.
virtual void next(Gecode::Support::RandomGenerator &rand)
Move to next assignment.
Gecode::IntSetValues * dsv
Iterator for each variable.
The item factory uses variables from the space being materialized.
Gecode::OpenIntVarList list
Gecode::Space * copy(void) override
Copy space during cloning.
OpenTestSpace(int arity, Gecode::IntSet &domain, OpenTest *test, int items0)
OpenTestSpace(OpenTestSpace &s)
bool retains(const Assignment &a)
Whether the target assignment and length are possible after propagation.
Integer constraint tests with incremental open-list histories.
OpenTest(const std::string &name, int items, int extra, const Gecode::IntSet &domain, Gecode::IntPropLevel ipl=Gecode::IPL_DEF)
Initialize item and auxiliary variables with the common domain.
int items
Number of items in the completed list.
virtual void post(Gecode::Space &home, Gecode::OpenIntVarList list, Gecode::IntVarArray &x)=0
Post the tested relation on an open list and its variable array.
bool run(void) override
Run closed-list tests and incremental histories.
int a
How many assignments still to be generated Generate new value according to domain.
int * vals
The current values for the variables.
int randval(Gecode::Support::RandomGenerator &rand)
virtual void next(Gecode::Support::RandomGenerator &rand)
Move to next assignment.
int _n1
How many variables in the second set.
int randval(const Gecode::IntSet &d, Gecode::Support::RandomGenerator &rand)
Gecode::IntSet _d1
Domain for second set of variables Generate new value according to domain d.
virtual void next(Gecode::Support::RandomGenerator &rand)
Move to next assignment.
int a
How many assignments still to be generated.
int * vals
The current values for the variables.
Space for executing tests.
int rndvar(Gecode::Support::RandomGenerator &rand)
Randomly select an unassigned variable.
Gecode::Reify r
Reification information.
void assign(const Assignment &a, bool skip, Gecode::Support::RandomGenerator &rand)
Assign all (or all but one, if skip is true) variables to values in a.
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, Gecode::Support::RandomGenerator &rand)
Randomly select a pruning rel for variable i.
Test * test
The test currently run.
virtual Gecode::Space * copy(void)
Copy space during cloning.
bool disabled(const Assignment &a, TestSpace &c, bool testfix, Gecode::Support::RandomGenerator &rand)
Prune values also in a space c with disabled propagators, but not those in assignment a.
void post(void)
Post propagator.
bool assigned(void) const
Test whether all variables are assigned.
void prune(int i, bool bounds_only, Gecode::Support::RandomGenerator &rand)
Prune some random values from variable i.
bool failed(void)
Compute a fixpoint and check for failure.
bool reified
Whether the test is for a reified propagator.
void disable(void)
Disable propagators in space and compute fixpoint (make all idle).
Gecode::IntVarArray x
Variables to be tested.
void bound(Gecode::Support::RandomGenerator &rand)
Assign a random variable to a random bound.
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.
bool pmi(void) const
Test whether reverse implication as reification mode is supported.
virtual bool run(void)
Perform test.
virtual bool ignore(const Assignment &) const
Whether to ignore assignment for reification.
bool testsearch
Whether to perform search test.
bool testfix
Whether to perform fixpoint test.
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)=0
Post constraint.
bool eqv(void) const
Test whether equivalence as reification mode is supported.
int arity
Number of variables.
virtual bool solution(const Assignment &) const =0
Check for solution.
virtual Assignment * assignment(void) const
Create the assignment generator (complete by default).
Gecode::IntSet dom
Domain of variables.
bool imp(void) const
Test whether implication as reification mode is supported.
ConTestLevel contest
Whether to test for certain consistency.
Simple class for describing indentation.
LinearCongruentialGenerator< 2147483647, 48271, 44488, 3399 > RandomGenerator
Default values for linear congruential generator.
void branch(Home home, const FloatVarArgs &x, FloatVarBranch vars, FloatValBranch vals, FloatBranchFilter bf=nullptr, FloatVarValPrint vvp=nullptr)
Branch over x with variable selection vars and value selection vals.
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVar x1)
Post propagator for .
IntRelType
Relation types for integers.
ReifyMode
Mode for reification.
BoolOpType
Operation types for Booleans.
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.
Space(void)
Default constructor.
Space * clone(void) const
Clone space.
SpaceStatus status(StatusStatistics &stat)
Query space status.
@ SS_FAILED
Space is failed
Gecode toplevel namespace
void min(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
IntVarBranch INT_VAR_NONE(void)
Select first unassigned variable.
void dom(Home home, FloatVar x, FloatVal n)
Propagates .
IntValBranch INT_VAL_MIN(void)
Select smallest value.
void max(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Testing finite domain integers.
@ 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.
std::ostream & operator<<(std::ostream &os, const Test::Int::Assignment &a)