00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #include "test/int.hh"
00037
00038 #include <algorithm>
00039
00040 namespace Test { namespace Int {
00041
00042
00043
00044
00045
00046
00047 void
00048 CpltAssignment::operator++(void) {
00049 int i = n-1;
00050 while (true) {
00051 ++dsv[i];
00052 if (dsv[i]() || (i == 0))
00053 return;
00054 dsv[i--].init(d);
00055 }
00056 }
00057
00058
00059
00060
00061
00062 void
00063 RandomAssignment::operator++(void) {
00064 for (int i = n; i--; )
00065 vals[i]=randval();
00066 a--;
00067 }
00068
00069 void
00070 RandomMixAssignment::operator++(void) {
00071 for (int i=n-_n1; i--; )
00072 vals[i] = randval(d);
00073 for (int i=_n1; i--; )
00074 vals[n-_n1+i] = randval(_d1);
00075 a--;
00076 }
00077
00078 }}
00079
00080 std::ostream&
00081 operator<<(std::ostream& os, const Test::Int::Assignment& a) {
00082 int n = a.size();
00083 os << "{";
00084 for (int i=0; i<n; i++)
00085 os << a[i] << ((i!=n-1) ? "," : "}");
00086 return os;
00087 }
00088
00089 namespace Test { namespace Int {
00090
00091 TestSpace::TestSpace(int n, Gecode::IntSet& d0, Test* t)
00092 : d(d0), x(*this,n,Gecode::Int::Limits::min,Gecode::Int::Limits::max),
00093 test(t), reified(false) {
00094 Gecode::IntVarArgs _x(*this,n,d);
00095 if (x.size() == 1)
00096 Gecode::dom(*this,x[0],_x[0]);
00097 else
00098 Gecode::dom(*this,x,_x);
00099 Gecode::BoolVar b(*this,0,1);
00100 r = Gecode::Reify(b,Gecode::RM_EQV);
00101 if (opt.log)
00102 olog << ind(2) << "Initial: x[]=" << x
00103 << std::endl;
00104 }
00105
00106 TestSpace::TestSpace(int n, Gecode::IntSet& d0, Test* t,
00107 Gecode::ReifyMode rm)
00108 : d(d0), x(*this,n,Gecode::Int::Limits::min,Gecode::Int::Limits::max),
00109 test(t), reified(true) {
00110 Gecode::IntVarArgs _x(*this,n,d);
00111 if (x.size() == 1)
00112 Gecode::dom(*this,x[0],_x[0]);
00113 else
00114 Gecode::dom(*this,x,_x);
00115 Gecode::BoolVar b(*this,0,1);
00116 r = Gecode::Reify(b,rm);
00117 if (opt.log)
00118 olog << ind(2) << "Initial: x[]=" << x
00119 << " b=" << r.var() << std::endl;
00120 }
00121
00122 TestSpace::TestSpace(TestSpace& s)
00123 : Gecode::Space(s), d(s.d), test(s.test), reified(s.reified) {
00124 x.update(*this, s.x);
00125 Gecode::BoolVar b;
00126 Gecode::BoolVar sr(s.r.var());
00127 b.update(*this, sr);
00128 r.var(b); r.mode(s.r.mode());
00129 }
00130
00131 Gecode::Space*
00132 TestSpace::copy(void) {
00133 return new TestSpace(*this);
00134 }
00135
00136 bool
00137 TestSpace::assigned(void) const {
00138 for (int i=x.size(); i--; )
00139 if (!x[i].assigned())
00140 return false;
00141 return true;
00142 }
00143
00144 void
00145 TestSpace::post(void) {
00146 if (reified){
00147 test->post(*this,x,r);
00148 if (opt.log)
00149 olog << ind(3) << "Posting reified propagator" << std::endl;
00150 } else {
00151 test->post(*this,x);
00152 if (opt.log)
00153 olog << ind(3) << "Posting propagator" << std::endl;
00154 }
00155 }
00156
00157 bool
00158 TestSpace::failed(void) {
00159 if (opt.log) {
00160 olog << ind(3) << "Fixpoint: " << x;
00161 bool f=(status() == Gecode::SS_FAILED);
00162 olog << std::endl << ind(3) << " --> " << x << std::endl;
00163 return f;
00164 } else {
00165 return status() == Gecode::SS_FAILED;
00166 }
00167 }
00168
00169 int
00170 TestSpace::rndvar(void) {
00171 assert(!assigned());
00172
00173 int i = Base::rand(x.size());
00174 while (x[i].assigned()) {
00175 i = (i+1) % x.size();
00176 }
00177 return i;
00178 }
00179
00180 void
00181 TestSpace::rndrel(const Assignment& a, int i,
00182 Gecode::IntRelType& irt, int& v) {
00183 using namespace Gecode;
00184
00185 irt = IRT_EQ;
00186 switch (Base::rand(3)) {
00187 case 0:
00188 if (a[i] < x[i].max()) {
00189 v=a[i]+1+Base::rand(static_cast
00190 <unsigned int>(x[i].max()-a[i]));
00191 assert((v > a[i]) && (v <= x[i].max()));
00192 irt = IRT_LE;
00193 }
00194 break;
00195 case 1:
00196 if (a[i] > x[i].min()) {
00197 v=x[i].min()+Base::rand(static_cast
00198 <unsigned int>(a[i]-x[i].min()));
00199 assert((v < a[i]) && (v >= x[i].min()));
00200 irt = IRT_GR;
00201 }
00202 break;
00203 default:
00204 {
00205 Gecode::Int::ViewRanges<Gecode::Int::IntView> it(x[i]);
00206 unsigned int skip = Base::rand(x[i].size()-1);
00207 while (true) {
00208 if (it.width() > skip) {
00209 v = it.min() + skip;
00210 if (v == a[i]) {
00211 if (it.width() == 1) {
00212 ++it; v = it.min();
00213 } else if (v < it.max()) {
00214 ++v;
00215 } else {
00216 --v;
00217 }
00218 }
00219 break;
00220 }
00221 skip -= it.width(); ++it;
00222 }
00223 irt = IRT_NQ;
00224 break;
00225 }
00226 }
00227 }
00228
00229 void
00230 TestSpace::rel(int i, Gecode::IntRelType irt, int n) {
00231 if (opt.log) {
00232 olog << ind(4) << "x[" << i << "] ";
00233 switch (irt) {
00234 case Gecode::IRT_EQ: olog << "="; break;
00235 case Gecode::IRT_NQ: olog << "!="; break;
00236 case Gecode::IRT_LQ: olog << "<="; break;
00237 case Gecode::IRT_LE: olog << "<"; break;
00238 case Gecode::IRT_GQ: olog << ">="; break;
00239 case Gecode::IRT_GR: olog << ">"; break;
00240 }
00241 olog << " " << n << std::endl;
00242 }
00243 Gecode::rel(*this, x[i], irt, n);
00244 }
00245
00246 void
00247 TestSpace::rel(bool sol) {
00248 int n = sol ? 1 : 0;
00249 assert(reified);
00250 if (opt.log)
00251 olog << ind(4) << "b = " << n << std::endl;
00252 Gecode::rel(*this, r.var(), Gecode::IRT_EQ, n);
00253 }
00254
00255 void
00256 TestSpace::assign(const Assignment& a, bool skip) {
00257 using namespace Gecode;
00258 int i = skip ? static_cast<int>(Base::rand(a.size())) : -1;
00259 for (int j=a.size(); j--; )
00260 if (i != j) {
00261 rel(j, IRT_EQ, a[j]);
00262 if (Base::fixpoint() && failed())
00263 return;
00264 }
00265 }
00266
00267 void
00268 TestSpace::bound(void) {
00269 using namespace Gecode;
00270 int i = rndvar();
00271 bool min = Base::rand(2);
00272 rel(i, IRT_EQ, min ? x[i].min() : x[i].max());
00273 }
00274
00275 void
00276 TestSpace::prune(int i, bool bounds_only) {
00277 using namespace Gecode;
00278
00279 if (bounds_only) {
00280 if (Base::rand(2) && !x[i].assigned()) {
00281 int v=x[i].min()+1+Base::rand(static_cast
00282 <unsigned int>(x[i].max()-x[i].min()));
00283 assert((v > x[i].min()) && (v <= x[i].max()));
00284 rel(i, Gecode::IRT_LE, v);
00285 }
00286 if (Base::rand(2) && !x[i].assigned()) {
00287 int v=x[i].min()+Base::rand(static_cast
00288 <unsigned int>(x[i].max()-x[i].min()));
00289 assert((v < x[i].max()) && (v >= x[i].min()));
00290 rel(i, Gecode::IRT_GR, v);
00291 }
00292 } else {
00293 for (int vals = Base::rand(x[i].size()-1)+1; vals--; ) {
00294 int v;
00295 Gecode::Int::ViewRanges<Gecode::Int::IntView> it(x[i]);
00296 unsigned int skip = Base::rand(x[i].size()-1);
00297 while (true) {
00298 if (it.width() > skip) {
00299 v = it.min() + skip; break;
00300 }
00301 skip -= it.width(); ++it;
00302 }
00303 rel(i, IRT_NQ, v);
00304 }
00305 }
00306 }
00307
00308 void
00309 TestSpace::prune(void) {
00310 prune(rndvar(), false);
00311 }
00312
00313 bool
00314 TestSpace::prune(const Assignment& a, bool testfix) {
00315 using namespace Gecode;
00316
00317 int i = rndvar();
00318
00319 IntRelType irt;
00320 int v;
00321 rndrel(a,i,irt,v);
00322 if (irt != IRT_EQ)
00323 rel(i, irt, v);
00324 if (Base::fixpoint()) {
00325 if (failed() || !testfix)
00326 return true;
00327 TestSpace* c = static_cast<TestSpace*>(clone());
00328 if (opt.log)
00329 olog << ind(3) << "Testing fixpoint on copy" << std::endl;
00330 c->post();
00331 if (c->failed()) {
00332 if (opt.log)
00333 olog << ind(4) << "Copy failed after posting" << std::endl;
00334 delete c; return false;
00335 }
00336 for (int i=x.size(); i--; )
00337 if (x[i].size() != c->x[i].size()) {
00338 if (opt.log)
00339 olog << ind(4) << "Different domain size" << std::endl;
00340 delete c; return false;
00341 }
00342 if (reified && (r.var().size() != c->r.var().size())) {
00343 if (opt.log)
00344 olog << ind(4) << "Different control variable" << std::endl;
00345 delete c; return false;
00346 }
00347 if (opt.log)
00348 olog << ind(3) << "Finished testing fixpoint on copy" << std::endl;
00349 delete c;
00350 }
00351 return true;
00352 }
00353
00354 void
00355 TestSpace::enable(void) {
00356 Gecode::PropagatorGroup::all.enable(*this);
00357 }
00358
00359 void
00360 TestSpace::disable(void) {
00361 Gecode::PropagatorGroup::all.disable(*this);
00362 (void) status();
00363 }
00364
00365 bool
00366 TestSpace::disabled(const Assignment& a, TestSpace& c,
00367 bool testfix) {
00368 using namespace Gecode;
00369
00370 c.disable();
00371
00372 int i = rndvar();
00373
00374 IntRelType irt;
00375 int v;
00376 rndrel(a,i,irt,v);
00377 if (irt != IRT_EQ) {
00378 rel(i, irt, v);
00379 c.rel(i, irt, v);
00380 }
00381
00382 c.enable();
00383 if (!testfix)
00384 return true;
00385 if (failed()) {
00386 if (!c.failed()) {
00387 if (opt.log)
00388 olog << ind(3) << "No failure on disabled copy" << std::endl;
00389 return false;
00390 }
00391 return true;
00392 }
00393 if (c.failed()) {
00394 if (opt.log)
00395 olog << ind(3) << "Failure on disabled copy" << std::endl;
00396 return false;
00397 }
00398 for (int i=x.size(); i--; ) {
00399 if (x[i].size() != c.x[i].size()) {
00400 if (opt.log)
00401 olog << ind(4) << "Different domain size" << std::endl;
00402 return false;
00403 }
00404 if (reified && (r.var().size() != c.r.var().size())) {
00405 if (opt.log)
00406 olog << ind(4) << "Different control variable" << std::endl;
00407 return false;
00408 }
00409 }
00410 return true;
00411 }
00412
00413 unsigned int
00414 TestSpace::propagators(void) {
00415 return Gecode::PropagatorGroup::all.size(*this);
00416 }
00417
00418 const Gecode::IntPropLevel IntPropLevels::ipls[] =
00419 {Gecode::IPL_DOM,Gecode::IPL_BND,Gecode::IPL_VAL};
00420
00421 const Gecode::IntPropLevel IntPropBasicAdvanced::ipls[] =
00422 {Gecode::IPL_BASIC_ADVANCED,Gecode::IPL_ADVANCED,Gecode::IPL_BASIC};
00423
00424 const Gecode::IntRelType IntRelTypes::irts[] =
00425 {Gecode::IRT_EQ,Gecode::IRT_NQ,Gecode::IRT_LQ,
00426 Gecode::IRT_LE,Gecode::IRT_GQ,Gecode::IRT_GR};
00427
00428 const Gecode::BoolOpType BoolOpTypes::bots[] =
00429 {Gecode::BOT_AND,Gecode::BOT_OR,Gecode::BOT_IMP,
00430 Gecode::BOT_EQV,Gecode::BOT_XOR};
00431
00432 Assignment*
00433 Test::assignment(void) const {
00434 return new CpltAssignment(arity,dom);
00435 }
00436
00437
00439 #define CHECK_TEST(T,M) \
00440 if (opt.log) \
00441 olog << ind(3) << "Check: " << (M) << std::endl; \
00442 if (!(T)) { \
00443 problem = (M); delete s; goto failed; \
00444 }
00445
00447 #define START_TEST(T) \
00448 if (opt.log) { \
00449 olog.str(""); \
00450 olog << ind(2) << "Testing: " << (T) << std::endl; \
00451 } \
00452 test = (T);
00453
00454 bool
00455 Test::ignore(const Assignment&) const {
00456 return false;
00457 }
00458
00459 void
00460 Test::post(Gecode::Space&, Gecode::IntVarArray&,
00461 Gecode::Reify) {}
00462
00463 bool
00464 Test::run(void) {
00465 using namespace Gecode;
00466 const char* test = "NONE";
00467 const char* problem = "NONE";
00468
00469
00470 Assignment* ap = assignment();
00471 Assignment& a = *ap;
00472
00473
00474 TestSpace* search_s = new TestSpace(arity,dom,this);
00475 post(*search_s,search_s->x);
00476 branch(*search_s,search_s->x,INT_VAR_NONE(),INT_VAL_MIN());
00477 Search::Options search_o;
00478 search_o.threads = 1;
00479 DFS<TestSpace> e_s(search_s,search_o);
00480 delete search_s;
00481
00482 while (a()) {
00483 bool sol = solution(a);
00484 if (opt.log) {
00485 olog << ind(1) << "Assignment: " << a
00486 << (sol ? " (solution)" : " (no solution)")
00487 << std::endl;
00488 }
00489
00490 START_TEST("Assignment (after posting)");
00491 {
00492 TestSpace* s = new TestSpace(arity,dom,this);
00493 TestSpace* sc = NULL;
00494 s->post();
00495 switch (Base::rand(2)) {
00496 case 0:
00497 if (opt.log)
00498 olog << ind(3) << "No copy" << std::endl;
00499 sc = s;
00500 s = NULL;
00501 break;
00502 case 1:
00503 if (opt.log)
00504 olog << ind(3) << "Copy" << std::endl;
00505 if (s->status() != SS_FAILED) {
00506 sc = static_cast<TestSpace*>(s->clone());
00507 } else {
00508 sc = s; s = NULL;
00509 }
00510 break;
00511 default: assert(false);
00512 }
00513 sc->assign(a);
00514 if (sol) {
00515 CHECK_TEST(!sc->failed(), "Failed on solution");
00516 CHECK_TEST(sc->propagators()==0, "No subsumption");
00517 } else {
00518 CHECK_TEST(sc->failed(), "Solved on non-solution");
00519 }
00520 delete s; delete sc;
00521 }
00522 START_TEST("Partial assignment (after posting)");
00523 {
00524 TestSpace* s = new TestSpace(arity,dom,this);
00525 s->post();
00526 s->assign(a,true);
00527 (void) s->failed();
00528 s->assign(a);
00529 if (sol) {
00530 CHECK_TEST(!s->failed(), "Failed on solution");
00531 CHECK_TEST(s->propagators()==0, "No subsumption");
00532 } else {
00533 CHECK_TEST(s->failed(), "Solved on non-solution");
00534 }
00535 delete s;
00536 }
00537 START_TEST("Assignment (after posting, disable)");
00538 {
00539 TestSpace* s = new TestSpace(arity,dom,this);
00540 s->post();
00541 s->disable();
00542 s->assign(a);
00543 s->enable();
00544 if (sol) {
00545 CHECK_TEST(!s->failed(), "Failed on solution");
00546 CHECK_TEST(s->propagators()==0, "No subsumption");
00547 } else {
00548 CHECK_TEST(s->failed(), "Solved on non-solution");
00549 }
00550 delete s;
00551 }
00552 START_TEST("Partial assignment (after posting, disable)");
00553 {
00554 TestSpace* s = new TestSpace(arity,dom,this);
00555 s->post();
00556 s->assign(a,true);
00557 s->disable();
00558 (void) s->failed();
00559 s->assign(a);
00560 s->enable();
00561 if (sol) {
00562 CHECK_TEST(!s->failed(), "Failed on solution");
00563 CHECK_TEST(s->propagators()==0, "No subsumption");
00564 } else {
00565 CHECK_TEST(s->failed(), "Solved on non-solution");
00566 }
00567 delete s;
00568 }
00569 START_TEST("Assignment (before posting)");
00570 {
00571 TestSpace* s = new TestSpace(arity,dom,this);
00572 s->assign(a);
00573 s->post();
00574 if (sol) {
00575 CHECK_TEST(!s->failed(), "Failed on solution");
00576 CHECK_TEST(s->propagators()==0, "No subsumption");
00577 } else {
00578 CHECK_TEST(s->failed(), "Solved on non-solution");
00579 }
00580 delete s;
00581 }
00582 START_TEST("Partial assignment (before posting)");
00583 {
00584 TestSpace* s = new TestSpace(arity,dom,this);
00585 s->assign(a,true);
00586 s->post();
00587 (void) s->failed();
00588 s->assign(a);
00589 if (sol) {
00590 CHECK_TEST(!s->failed(), "Failed on solution");
00591 CHECK_TEST(s->propagators()==0, "No subsumption");
00592 } else {
00593 CHECK_TEST(s->failed(), "Solved on non-solution");
00594 }
00595 delete s;
00596 }
00597 START_TEST("Prune");
00598 {
00599 TestSpace* s = new TestSpace(arity,dom,this);
00600 s->post();
00601 while (!s->failed() && !s->assigned())
00602 if (!s->prune(a,testfix)) {
00603 problem = "No fixpoint";
00604 delete s;
00605 goto failed;
00606 }
00607 s->assign(a);
00608 if (sol) {
00609 CHECK_TEST(!s->failed(), "Failed on solution");
00610 CHECK_TEST(s->propagators()==0, "No subsumption");
00611 } else {
00612 CHECK_TEST(s->failed(), "Solved on non-solution");
00613 }
00614 delete s;
00615 }
00616 START_TEST("Prune (disable)");
00617 {
00618 TestSpace* s = new TestSpace(arity,dom,this);
00619 TestSpace* c = static_cast<TestSpace*>(s->clone());
00620 s->post(); c->post();
00621 while (!s->failed() && !s->assigned())
00622 if (!s->disabled(a,*c,testfix)) {
00623 problem = "Different result after re-enable";
00624 delete s; delete c;
00625 goto failed;
00626 }
00627 if (testfix && (s->failed() != c->failed())) {
00628 problem = "Different failure after re-enable";
00629 delete s; delete c;
00630 goto failed;
00631 }
00632 delete s; delete c;
00633 }
00634 if (!ignore(a)) {
00635 if (eqv()) {
00636 {
00637 START_TEST("Assignment reified (rewrite after post, <=>)");
00638 TestSpace* s = new TestSpace(arity,dom,this,RM_EQV);
00639 s->post();
00640 s->rel(sol);
00641 s->assign(a);
00642 CHECK_TEST(!s->failed(), "Failed");
00643 CHECK_TEST(s->propagators()==0, "No subsumption");
00644 delete s;
00645 }
00646 {
00647 START_TEST("Assignment reified (rewrite failure, <=>)");
00648 TestSpace* s = new TestSpace(arity,dom,this,RM_EQV);
00649 s->post();
00650 s->rel(!sol);
00651 s->assign(a);
00652 CHECK_TEST(s->failed(), "Not failed");
00653 delete s;
00654 }
00655 {
00656 START_TEST("Assignment reified (immediate rewrite, <=>)");
00657 TestSpace* s = new TestSpace(arity,dom,this,RM_EQV);
00658 s->rel(sol);
00659 s->post();
00660 s->assign(a);
00661 CHECK_TEST(!s->failed(), "Failed");
00662 CHECK_TEST(s->propagators()==0, "No subsumption");
00663 delete s;
00664 }
00665 {
00666 START_TEST("Assignment reified (immediate failure, <=>)");
00667 TestSpace* s = new TestSpace(arity,dom,this,RM_EQV);
00668 s->rel(!sol);
00669 s->post();
00670 s->assign(a);
00671 CHECK_TEST(s->failed(), "Not failed");
00672 delete s;
00673 }
00674 {
00675 START_TEST("Assignment reified (before posting, <=>)");
00676 TestSpace* s = new TestSpace(arity,dom,this,RM_EQV);
00677 s->assign(a);
00678 s->post();
00679 CHECK_TEST(!s->failed(), "Failed");
00680 CHECK_TEST(s->propagators()==0, "No subsumption");
00681 CHECK_TEST(s->r.var().assigned(), "Control variable unassigned");
00682 if (sol) {
00683 CHECK_TEST(s->r.var().val()==1, "Zero on solution");
00684 } else {
00685 CHECK_TEST(s->r.var().val()==0, "One on non-solution");
00686 }
00687 delete s;
00688 }
00689 {
00690 START_TEST("Assignment reified (after posting, <=>)");
00691 TestSpace* s = new TestSpace(arity,dom,this,RM_EQV);
00692 s->post();
00693 s->assign(a);
00694 CHECK_TEST(!s->failed(), "Failed");
00695 CHECK_TEST(s->propagators()==0, "No subsumption");
00696 CHECK_TEST(s->r.var().assigned(), "Control variable unassigned");
00697 if (sol) {
00698 CHECK_TEST(s->r.var().val()==1, "Zero on solution");
00699 } else {
00700 CHECK_TEST(s->r.var().val()==0, "One on non-solution");
00701 }
00702 delete s;
00703 }
00704 {
00705 START_TEST("Assignment reified (after posting, <=>, disable)");
00706 TestSpace* s = new TestSpace(arity,dom,this,RM_EQV);
00707 s->post();
00708 s->disable();
00709 s->assign(a);
00710 s->enable();
00711 CHECK_TEST(!s->failed(), "Failed");
00712 CHECK_TEST(s->propagators()==0, "No subsumption");
00713 CHECK_TEST(s->r.var().assigned(), "Control variable unassigned");
00714 if (sol) {
00715 CHECK_TEST(s->r.var().val()==1, "Zero on solution");
00716 } else {
00717 CHECK_TEST(s->r.var().val()==0, "One on non-solution");
00718 }
00719 delete s;
00720 }
00721 {
00722 START_TEST("Prune reified, <=>");
00723 TestSpace* s = new TestSpace(arity,dom,this,RM_EQV);
00724 s->post();
00725 while (!s->failed() &&
00726 (!s->assigned() || !s->r.var().assigned()))
00727 if (!s->prune(a,testfix)) {
00728 problem = "No fixpoint";
00729 delete s;
00730 goto failed;
00731 }
00732 CHECK_TEST(!s->failed(), "Failed");
00733 CHECK_TEST(s->propagators()==0, "No subsumption");
00734 CHECK_TEST(s->r.var().assigned(), "Control variable unassigned");
00735 if (sol) {
00736 CHECK_TEST(s->r.var().val()==1, "Zero on solution");
00737 } else {
00738 CHECK_TEST(s->r.var().val()==0, "One on non-solution");
00739 }
00740 delete s;
00741 }
00742 {
00743 START_TEST("Prune reified, <=>, disable");
00744 TestSpace* s = new TestSpace(arity,dom,this,RM_EQV);
00745 TestSpace* c = static_cast<TestSpace*>(s->clone());
00746 s->post(); c->post();
00747 while (!s->failed() &&
00748 (!s->assigned() || !s->r.var().assigned()))
00749 if (!s->disabled(a,*c,testfix)) {
00750 problem = "No fixpoint";
00751 delete s;
00752 delete c;
00753 goto failed;
00754 }
00755 CHECK_TEST(!c->failed(), "Failed");
00756 CHECK_TEST(c->propagators()==0, "No subsumption");
00757 CHECK_TEST(c->r.var().assigned(), "Control variable unassigned");
00758 if (sol) {
00759 CHECK_TEST(c->r.var().val()==1, "Zero on solution");
00760 } else {
00761 CHECK_TEST(c->r.var().val()==0, "One on non-solution");
00762 }
00763 delete s;
00764 delete c;
00765 }
00766 }
00767
00768 if (imp()) {
00769 {
00770 START_TEST("Assignment reified (rewrite after post, =>)");
00771 TestSpace* s = new TestSpace(arity,dom,this,RM_IMP);
00772 s->post();
00773 s->rel(sol);
00774 s->assign(a);
00775 CHECK_TEST(!s->failed(), "Failed");
00776 CHECK_TEST(s->propagators()==0, "No subsumption");
00777 delete s;
00778 }
00779 {
00780 START_TEST("Assignment reified (rewrite failure, =>)");
00781 TestSpace* s = new TestSpace(arity,dom,this,RM_IMP);
00782 s->post();
00783 s->rel(!sol);
00784 s->assign(a);
00785 if (sol) {
00786 CHECK_TEST(!s->failed(), "Failed");
00787 CHECK_TEST(s->propagators()==0, "No subsumption");
00788 } else {
00789 CHECK_TEST(s->failed(), "Not failed");
00790 }
00791 delete s;
00792 }
00793 {
00794 START_TEST("Assignment reified (immediate rewrite, =>)");
00795 TestSpace* s = new TestSpace(arity,dom,this,RM_IMP);
00796 s->rel(sol);
00797 s->post();
00798 s->assign(a);
00799 CHECK_TEST(!s->failed(), "Failed");
00800 CHECK_TEST(s->propagators()==0, "No subsumption");
00801 delete s;
00802 }
00803 {
00804 START_TEST("Assignment reified (immediate failure, =>)");
00805 TestSpace* s = new TestSpace(arity,dom,this,RM_IMP);
00806 s->rel(!sol);
00807 s->post();
00808 s->assign(a);
00809 if (sol) {
00810 CHECK_TEST(!s->failed(), "Failed");
00811 CHECK_TEST(s->propagators()==0, "No subsumption");
00812 } else {
00813 CHECK_TEST(s->failed(), "Not failed");
00814 }
00815 delete s;
00816 }
00817 {
00818 START_TEST("Assignment reified (before posting, =>)");
00819 TestSpace* s = new TestSpace(arity,dom,this,RM_IMP);
00820 s->assign(a);
00821 s->post();
00822 CHECK_TEST(!s->failed(), "Failed");
00823 CHECK_TEST(s->propagators()==0, "No subsumption");
00824 if (sol) {
00825 CHECK_TEST(!s->r.var().assigned(), "Control variable assigned");
00826 } else {
00827 CHECK_TEST(s->r.var().assigned(), "Control variable unassigned");
00828 CHECK_TEST(s->r.var().val()==0, "One on non-solution");
00829 }
00830 delete s;
00831 }
00832 {
00833 START_TEST("Assignment reified (after posting, =>)");
00834 TestSpace* s = new TestSpace(arity,dom,this,RM_IMP);
00835 s->post();
00836 s->assign(a);
00837 CHECK_TEST(!s->failed(), "Failed");
00838 CHECK_TEST(s->propagators()==0, "No subsumption");
00839 if (sol) {
00840 CHECK_TEST(!s->r.var().assigned(), "Control variable assigned");
00841 } else {
00842 CHECK_TEST(s->r.var().assigned(), "Control variable unassigned");
00843 CHECK_TEST(s->r.var().val()==0, "One on non-solution");
00844 }
00845 delete s;
00846 }
00847 {
00848 START_TEST("Assignment reified (after posting, =>, disable)");
00849 TestSpace* s = new TestSpace(arity,dom,this,RM_IMP);
00850 s->post();
00851 s->disable();
00852 s->assign(a);
00853 s->enable();
00854 CHECK_TEST(!s->failed(), "Failed");
00855 CHECK_TEST(s->propagators()==0, "No subsumption");
00856 if (sol) {
00857 CHECK_TEST(!s->r.var().assigned(), "Control variable assigned");
00858 } else {
00859 CHECK_TEST(s->r.var().assigned(), "Control variable unassigned");
00860 CHECK_TEST(s->r.var().val()==0, "One on non-solution");
00861 }
00862 delete s;
00863 }
00864 {
00865 START_TEST("Prune reified, =>");
00866 TestSpace* s = new TestSpace(arity,dom,this,RM_IMP);
00867 s->post();
00868 while (!s->failed() &&
00869 (!s->assigned() || (!sol && !s->r.var().assigned())))
00870 if (!s->prune(a,testfix)) {
00871 problem = "No fixpoint";
00872 delete s;
00873 goto failed;
00874 }
00875 CHECK_TEST(!s->failed(), "Failed");
00876 CHECK_TEST(s->propagators()==0, "No subsumption");
00877 if (sol) {
00878 CHECK_TEST(!s->r.var().assigned(), "Control variable assigned");
00879 } else {
00880 CHECK_TEST(s->r.var().assigned(), "Control variable unassigned");
00881 CHECK_TEST(s->r.var().val()==0, "One on non-solution");
00882 }
00883 delete s;
00884 }
00885 {
00886 START_TEST("Prune reified, =>, disable");
00887 TestSpace* s = new TestSpace(arity,dom,this,RM_IMP);
00888 TestSpace* c = static_cast<TestSpace*>(s->clone());
00889 s->post(); c->post();
00890 while (!s->failed() &&
00891 (!s->assigned() || (!sol && !s->r.var().assigned())))
00892 if (!s->disabled(a,*c,testfix)) {
00893 problem = "No fixpoint";
00894 delete s;
00895 delete c;
00896 goto failed;
00897 }
00898 CHECK_TEST(!c->failed(), "Failed");
00899 CHECK_TEST(c->propagators()==0, "No subsumption");
00900 if (sol) {
00901 CHECK_TEST(!c->r.var().assigned(), "Control variable assigned");
00902 } else {
00903 CHECK_TEST(c->r.var().assigned(), "Control variable unassigned");
00904 CHECK_TEST(c->r.var().val()==0, "One on non-solution");
00905 }
00906 delete s;
00907 delete c;
00908 }
00909 }
00910
00911 if (pmi()) {
00912 {
00913 START_TEST("Assignment reified (rewrite after post, <=)");
00914 TestSpace* s = new TestSpace(arity,dom,this,RM_PMI);
00915 s->post();
00916 s->rel(sol);
00917 s->assign(a);
00918 CHECK_TEST(!s->failed(), "Failed");
00919 CHECK_TEST(s->propagators()==0, "No subsumption");
00920 delete s;
00921 }
00922 {
00923 START_TEST("Assignment reified (rewrite failure, <=)");
00924 TestSpace* s = new TestSpace(arity,dom,this,RM_PMI);
00925 s->post();
00926 s->rel(!sol);
00927 s->assign(a);
00928 if (sol) {
00929 CHECK_TEST(s->failed(), "Not failed");
00930 } else {
00931 CHECK_TEST(!s->failed(), "Failed");
00932 CHECK_TEST(s->propagators()==0, "No subsumption");
00933 }
00934 delete s;
00935 }
00936 {
00937 START_TEST("Assignment reified (immediate rewrite, <=)");
00938 TestSpace* s = new TestSpace(arity,dom,this,RM_PMI);
00939 s->rel(sol);
00940 s->post();
00941 s->assign(a);
00942 CHECK_TEST(!s->failed(), "Failed");
00943 CHECK_TEST(s->propagators()==0, "No subsumption");
00944 delete s;
00945 }
00946 {
00947 START_TEST("Assignment reified (immediate failure, <=)");
00948 TestSpace* s = new TestSpace(arity,dom,this,RM_PMI);
00949 s->rel(!sol);
00950 s->post();
00951 s->assign(a);
00952 if (sol) {
00953 CHECK_TEST(s->failed(), "Not failed");
00954 } else {
00955 CHECK_TEST(!s->failed(), "Failed");
00956 CHECK_TEST(s->propagators()==0, "No subsumption");
00957 }
00958 delete s;
00959 }
00960 {
00961 START_TEST("Assignment reified (before posting, <=)");
00962 TestSpace* s = new TestSpace(arity,dom,this,RM_PMI);
00963 s->assign(a);
00964 s->post();
00965 CHECK_TEST(!s->failed(), "Failed");
00966 CHECK_TEST(s->propagators()==0, "No subsumption");
00967 if (sol) {
00968 CHECK_TEST(s->r.var().assigned(), "Control variable unassigned");
00969 CHECK_TEST(s->r.var().val()==1, "Zero on solution");
00970 } else {
00971 CHECK_TEST(!s->r.var().assigned(), "Control variable assigned");
00972 }
00973 delete s;
00974 }
00975 {
00976 START_TEST("Assignment reified (after posting, <=)");
00977 TestSpace* s = new TestSpace(arity,dom,this,RM_PMI);
00978 s->post();
00979 s->assign(a);
00980 CHECK_TEST(!s->failed(), "Failed");
00981 CHECK_TEST(s->propagators()==0, "No subsumption");
00982 if (sol) {
00983 CHECK_TEST(s->r.var().assigned(), "Control variable unassigned");
00984 CHECK_TEST(s->r.var().val()==1, "Zero on solution");
00985 } else {
00986 CHECK_TEST(!s->r.var().assigned(), "Control variable assigned");
00987 }
00988 delete s;
00989 }
00990 {
00991 START_TEST("Assignment reified (after posting, <=, disable)");
00992 TestSpace* s = new TestSpace(arity,dom,this,RM_PMI);
00993 s->post();
00994 s->disable();
00995 s->assign(a);
00996 s->enable();
00997 CHECK_TEST(!s->failed(), "Failed");
00998 CHECK_TEST(s->propagators()==0, "No subsumption");
00999 if (sol) {
01000 CHECK_TEST(s->r.var().assigned(), "Control variable unassigned");
01001 CHECK_TEST(s->r.var().val()==1, "Zero on solution");
01002 } else {
01003 CHECK_TEST(!s->r.var().assigned(), "Control variable assigned");
01004 }
01005 delete s;
01006 }
01007 {
01008 START_TEST("Prune reified, <=");
01009 TestSpace* s = new TestSpace(arity,dom,this,RM_PMI);
01010 s->post();
01011 while (!s->failed() &&
01012 (!s->assigned() || (sol && !s->r.var().assigned())))
01013 if (!s->prune(a,testfix)) {
01014 problem = "No fixpoint";
01015 delete s;
01016 goto failed;
01017 }
01018 CHECK_TEST(!s->failed(), "Failed");
01019 CHECK_TEST(s->propagators()==0, "No subsumption");
01020 if (sol) {
01021 CHECK_TEST(s->r.var().assigned(), "Control variable unassigned");
01022 CHECK_TEST(s->r.var().val()==1, "Zero on solution");
01023 } else {
01024 CHECK_TEST(!s->r.var().assigned(), "Control variable assigned");
01025 }
01026 delete s;
01027 }
01028 {
01029 START_TEST("Prune reified, <=, disable");
01030 TestSpace* s = new TestSpace(arity,dom,this,RM_PMI);
01031 TestSpace* c = static_cast<TestSpace*>(s->clone());
01032 s->post(); c->post();
01033 while (!s->failed() &&
01034 (!s->assigned() || (sol && !s->r.var().assigned())))
01035 if (!s->disabled(a,*c,testfix)) {
01036 problem = "No fixpoint";
01037 delete s;
01038 delete c;
01039 goto failed;
01040 }
01041 CHECK_TEST(!c->failed(), "Failed");
01042 CHECK_TEST(c->propagators()==0, "No subsumption");
01043 if (sol) {
01044 CHECK_TEST(c->r.var().assigned(), "Control variable unassigned");
01045 CHECK_TEST(c->r.var().val()==1, "Zero on solution");
01046 } else {
01047 CHECK_TEST(!c->r.var().assigned(), "Control variable assigned");
01048 }
01049 delete s;
01050 delete c;
01051 }
01052 }
01053 }
01054
01055 if (testsearch) {
01056 if (sol) {
01057 START_TEST("Search");
01058 TestSpace* s = e_s.next();
01059 CHECK_TEST(s != NULL, "Solutions exhausted");
01060 CHECK_TEST(s->propagators()==0, "No subsumption");
01061 for (int i=a.size(); i--; ) {
01062 CHECK_TEST(s->x[i].assigned(), "Unassigned variable");
01063 CHECK_TEST(a[i] == s->x[i].val(), "Wrong value in solution");
01064 }
01065 delete s;
01066 }
01067 }
01068
01069 ++a;
01070 }
01071
01072 if (testsearch) {
01073 test = "Search";
01074 if (e_s.next() != NULL) {
01075 problem = "Excess solutions";
01076 goto failed;
01077 }
01078 }
01079
01080 switch (contest) {
01081 case CTL_NONE: break;
01082 case CTL_DOMAIN: {
01083 START_TEST("Full domain consistency");
01084 TestSpace* s = new TestSpace(arity,dom,this);
01085 s->post();
01086 if (!s->failed()) {
01087 while (!s->failed() && !s->assigned())
01088 s->prune();
01089 CHECK_TEST(!s->failed(), "Failed");
01090 CHECK_TEST(s->propagators()==0, "No subsumption");
01091 }
01092 delete s;
01093
01094 }
01095 case CTL_BOUNDS_D: {
01096 START_TEST("Bounds(D)-consistency");
01097 TestSpace* s = new TestSpace(arity,dom,this);
01098 s->post();
01099 for (int i = s->x.size(); i--; )
01100 s->prune(i, false);
01101 if (!s->failed()) {
01102 while (!s->failed() && !s->assigned())
01103 s->bound();
01104 CHECK_TEST(!s->failed(), "Failed");
01105 CHECK_TEST(s->propagators()==0, "No subsumption");
01106 }
01107 delete s;
01108
01109 }
01110 case CTL_BOUNDS_Z: {
01111 START_TEST("Bounds(Z)-consistency");
01112 TestSpace* s = new TestSpace(arity,dom,this);
01113 s->post();
01114 for (int i = s->x.size(); i--; )
01115 s->prune(i, true);
01116 if (!s->failed()) {
01117 while (!s->failed() && !s->assigned())
01118 s->bound();
01119 CHECK_TEST(!s->failed(), "Failed");
01120 CHECK_TEST(s->propagators()==0, "No subsumption");
01121 }
01122 delete s;
01123 break;
01124 }
01125 }
01126
01127 delete ap;
01128 return true;
01129
01130 failed:
01131 if (opt.log)
01132 olog << "FAILURE" << std::endl
01133 << ind(1) << "Test: " << test << std::endl
01134 << ind(1) << "Problem: " << problem << std::endl;
01135 if (a() && opt.log)
01136 olog << ind(1) << "Assignment: " << a << std::endl;
01137 delete ap;
01138
01139 return false;
01140 }
01141
01142 }}
01143
01144 #undef START_TEST
01145 #undef CHECK_TEST
01146
01147