Generated on for Gecode by doxygen 1.17.0
int.cpp
Go to the documentation of this file.
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2/*
3 * Main authors:
4 * Christian Schulte <schulte@gecode.dev>
5 * Mikael Zayenz Lagerkvist <lagerkvist@gecode.dev>
6 *
7 * Copyright:
8 * Christian Schulte, 2005
9 * Mikael Zayenz Lagerkvist, 2005, 2026
10 *
11 * This file is part of Gecode, the generic constraint
12 * development environment:
13 * http://www.gecode.dev
14 *
15 * Permission is hereby granted, free of charge, to any person obtaining
16 * a copy of this software and associated documentation files (the
17 * "Software"), to deal in the Software without restriction, including
18 * without limitation the rights to use, copy, modify, merge, publish,
19 * distribute, sublicense, and/or sell copies of the Software, and to
20 * permit persons to whom the Software is furnished to do so, subject to
21 * the following conditions:
22 *
23 * The above copyright notice and this permission notice shall be
24 * included in all copies or substantial portions of the Software.
25 *
26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
30 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
31 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
32 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 *
34 */
35
36#include "test/int.hh"
37
38#include <algorithm>
39#include <memory>
40
41namespace Test { namespace Int {
42
43
44 /*
45 * Complete assignments
46 *
47 */
48 void
50 int i = n-1;
51 while (true) {
52 ++dsv[i];
53 if (dsv[i]() || (i == 0))
54 return;
55 dsv[i--].init(d);
56 }
57 }
58
59 /*
60 * Random assignments
61 *
62 */
64 for (int i = this->n; i--; )
65 this->vals[i]= this->randval(rand);
66 this->a--;
67 }
68
69 void
71 for (int i=n-_n1; i--; )
72 vals[i] = randval(d, rand);
73 for (int i=_n1; i--; )
74 vals[n-_n1+i] = randval(_d1, rand);
75 a--;
76 }
77
78}}
79
80std::ostream&
81operator<<(std::ostream& os, const Test::Int::Assignment& a) {
82 int n = a.size();
83 os << "{";
84 for (int i=0; i<n; i++)
85 os << a[i] << ((i!=n-1) ? "," : "}");
86 return os;
87}
88
89namespace Test { namespace Int {
90
92 : d(d0), x(*this,n,Gecode::Int::Limits::min,Gecode::Int::Limits::max),
93 test(t), reified(false) {
94 Gecode::IntVarArgs _x(*this,n,d);
95 if (x.size() == 1)
96 Gecode::dom(*this,x[0],_x[0]);
97 else
98 Gecode::dom(*this,x,_x);
99 Gecode::BoolVar b(*this,0,1);
101 if (opt.log)
102 olog << ind(2) << "Initial: x[]=" << x
103 << std::endl;
104 }
105
108 : d(d0), x(*this,n,Gecode::Int::Limits::min,Gecode::Int::Limits::max),
109 test(t), reified(true) {
110 Gecode::IntVarArgs _x(*this,n,d);
111 if (x.size() == 1)
112 Gecode::dom(*this,x[0],_x[0]);
113 else
114 Gecode::dom(*this,x,_x);
115 Gecode::BoolVar b(*this,0,1);
116 r = Gecode::Reify(b,rm);
117 if (opt.log)
118 olog << ind(2) << "Initial: x[]=" << x
119 << " b=" << r.var() << std::endl;
120 }
121
123 : Gecode::Space(s), d(s.d), test(s.test), reified(s.reified) {
124 x.update(*this, s.x);
126 Gecode::BoolVar sr(s.r.var());
127 b.update(*this, sr);
128 r.var(b); r.mode(s.r.mode());
129 }
130
133 return new TestSpace(*this);
134 }
135
136 bool
138 for (int i=x.size(); i--; )
139 if (!x[i].assigned())
140 return false;
141 return true;
142 }
143
144 void
146 if (reified){
147 test->post(*this,x,r);
148 if (opt.log)
149 olog << ind(3) << "Posting reified propagator" << std::endl;
150 } else {
151 test->post(*this,x);
152 if (opt.log)
153 olog << ind(3) << "Posting propagator" << std::endl;
154 }
155 }
156
157 bool
159 if (opt.log) {
160 olog << ind(3) << "Fixpoint: " << x;
161 bool f=(status() == Gecode::SS_FAILED);
162 olog << std::endl << ind(3) << " --> " << x << std::endl;
163 return f;
164 } else {
165 return status() == Gecode::SS_FAILED;
166 }
167 }
168
169 int
171 assert(!assigned());
172 // Select variable to be pruned
173 int i = static_cast<int>(rand(static_cast<unsigned int>(x.size())));
174 while (x[i].assigned()) {
175 i = (i+1) % x.size();
176 }
177 return i;
178 }
179
180 void
181 TestSpace::rndrel(const Assignment& a, int i, Gecode::IntRelType& irt, int& v,
183 using namespace Gecode;
184 // Select mode for pruning
185 irt = IRT_EQ; // Means do nothing!
186 switch (rand(3)) {
187 case 0:
188 if (a[i] < x[i].max()) {
189 unsigned int n =
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()));
194 irt = IRT_LE;
195 }
196 break;
197 case 1:
198 if (a[i] > x[i].min()) {
199 unsigned int n =
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()));
204 irt = IRT_GR;
205 }
206 break;
207 default:
208 {
210 unsigned int skip = rand(static_cast<unsigned int>(x[i].size()-1));
211 while (true) {
212 if (it.width() > skip) {
213 v = static_cast<int>(static_cast<long long>(it.min()) + skip);
214 if (v == a[i]) {
215 if (it.width() == 1) {
216 ++it; v = it.min();
217 } else if (v < it.max()) {
218 ++v;
219 } else {
220 --v;
221 }
222 }
223 break;
224 }
225 skip -= it.width(); ++it;
226 }
227 irt = IRT_NQ;
228 break;
229 }
230 }
231 }
232
233 void
235 if (opt.log) {
236 olog << ind(4) << "x[" << i << "] ";
237 switch (irt) {
238 case Gecode::IRT_EQ: olog << "="; break;
239 case Gecode::IRT_NQ: olog << "!="; break;
240 case Gecode::IRT_LQ: olog << "<="; break;
241 case Gecode::IRT_LE: olog << "<"; break;
242 case Gecode::IRT_GQ: olog << ">="; break;
243 case Gecode::IRT_GR: olog << ">"; break;
244 }
245 olog << " " << n << std::endl;
246 }
247 Gecode::rel(*this, x[i], irt, n);
248 }
249
250 void
251 TestSpace::rel(bool sol) {
252 int n = sol ? 1 : 0;
253 assert(reified);
254 if (opt.log)
255 olog << ind(4) << "b = " << n << std::endl;
256 Gecode::rel(*this, r.var(), Gecode::IRT_EQ, n);
257 }
258
259 void
261 using namespace Gecode;
262 int i = skip ?
263 static_cast<int>(rand(static_cast<unsigned int>(a.size()))) : -1;
264 for (int j=a.size(); j--; )
265 if (i != j) {
266 rel(j, IRT_EQ, a[j]);
267 if (Base::fixpoint(rand) && failed())
268 return;
269 }
270 }
271
272 void
274 using namespace Gecode;
275 int i = rndvar(rand);
276 bool min = rand(2);
277 rel(i, IRT_EQ, min ? x[i].min() : x[i].max());
278 }
279
280 void
281 TestSpace::prune(int i, bool bounds_only, Gecode::Support::RandomGenerator& rand) {
282 using namespace Gecode;
283 // Prune values
284 if (bounds_only) {
285 if (rand(2) && !x[i].assigned()) {
286 unsigned int n =
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()) +
291 1LL + offset);
292 assert((v > x[i].min()) && (v <= x[i].max()));
293 rel(i, Gecode::IRT_LE, v);
294 }
295 if (rand(2) && !x[i].assigned()) {
296 unsigned int n =
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()));
302 rel(i, Gecode::IRT_GR, v);
303 }
304 } else {
305 for (int vals =
306 static_cast<int>(rand(static_cast<unsigned int>(x[i].size()-1))+1); vals--; ) {
307 int v;
309 unsigned int skip = rand(x[i].size()-1);
310 while (true) {
311 if (it.width() > skip) {
312 v = static_cast<int>(static_cast<long long>(it.min()) + skip);
313 break;
314 }
315 skip -= it.width(); ++it;
316 }
317 rel(i, IRT_NQ, v);
318 }
319 }
320 }
321
322 void
324 prune(rndvar(rand), false, rand);
325 }
326
327 bool
329 using namespace Gecode;
330 // Select variable to be pruned
331 int i = rndvar(rand);
332 // Select mode for pruning
333 IntRelType irt;
334 int v;
335 rndrel(a, i, irt, v, rand);
336 if (irt != IRT_EQ)
337 rel(i, irt, v);
338 if (Base::fixpoint(rand)) {
339 if (failed() || !testfix)
340 return true;
341 TestSpace* c = static_cast<TestSpace*>(clone());
342 if (opt.log)
343 olog << ind(3) << "Testing fixpoint on copy" << std::endl;
344 c->post();
345 if (c->failed()) {
346 if (opt.log)
347 olog << ind(4) << "Copy failed after posting" << std::endl;
348 delete c; return false;
349 }
350 for (int j=x.size(); j--; )
351 if (x[j].size() != c->x[j].size()) {
352 if (opt.log)
353 olog << ind(4) << "Different domain size" << std::endl;
354 delete c; return false;
355 }
356 if (reified && (r.var().size() != c->r.var().size())) {
357 if (opt.log)
358 olog << ind(4) << "Different control variable" << std::endl;
359 delete c; return false;
360 }
361 if (opt.log)
362 olog << ind(3) << "Finished testing fixpoint on copy" << std::endl;
363 delete c;
364 }
365 return true;
366 }
367
368 void
370 Gecode::PropagatorGroup::all.enable(*this);
371 }
372
373 void
375 Gecode::PropagatorGroup::all.disable(*this);
376 (void) status();
377 }
378
379 bool
381 using namespace Gecode;
382 // Disable propagators
383 c.disable();
384 // Select variable to be pruned
385 int i = rndvar(rand);
386 // Select mode for pruning
387 IntRelType irt;
388 int v;
389 rndrel(a, i, irt, v, rand);
390 if (irt != IRT_EQ) {
391 rel(i, irt, v);
392 c.rel(i, irt, v);
393 }
394 // Enable propagators
395 c.enable();
396 if (!testfix)
397 return true;
398 if (failed()) {
399 if (!c.failed()) {
400 if (opt.log)
401 olog << ind(3) << "No failure on disabled copy" << std::endl;
402 return false;
403 }
404 return true;
405 }
406 if (c.failed()) {
407 if (opt.log)
408 olog << ind(3) << "Failure on disabled copy" << std::endl;
409 return false;
410 }
411 for (int j=x.size(); j--; ) {
412 if (x[j].size() != c.x[j].size()) {
413 if (opt.log)
414 olog << ind(4) << "Different domain size" << std::endl;
415 return false;
416 }
417 if (reified && (r.var().size() != c.r.var().size())) {
418 if (opt.log)
419 olog << ind(4) << "Different control variable" << std::endl;
420 return false;
421 }
422 }
423 return true;
424 }
425
426 unsigned int
428 return Gecode::PropagatorGroup::all.size(*this);
429 }
430
431 const Gecode::IntPropLevel IntPropLevels::ipls[] =
433
434 const Gecode::IntPropLevel IntPropBasicAdvanced::ipls[] =
436
437 const Gecode::IntRelType IntRelTypes::irts[] =
440
441 const Gecode::BoolOpType BoolOpTypes::bots[] =
444
446 Test::assignment(void) const {
447 return new CpltAssignment(arity,dom);
448 }
449
450
452#define CHECK_TEST(T,M) \
453do { \
454if (opt.log) \
455 olog << ind(3) << "Check: " << (M) << std::endl; \
456if (!(T)) { \
457 problem = (M); delete s; goto failed; \
458} \
459} while (false)
460
462#define START_TEST(T) \
463do { \
464 if (opt.log) { \
465 olog.str(""); \
466 olog << ind(2) << "Testing: " << (T) << std::endl; \
467 } \
468 test = (T); \
469} while (false)
470
471 bool
472 Test::ignore(const Assignment&) const {
473 return false;
474 }
475
476 void
479
480 bool
481 Test::run(void) {
482 using namespace Gecode;
483 const char* test = "NONE";
484 const char* problem = "NONE";
485
486 // Set up assignments
487 Assignment* ap = assignment();
488 Assignment& a = *ap;
489
490 // Set up space for all solution search
491 TestSpace* search_s = new TestSpace(arity,dom,this);
492 post(*search_s,search_s->x);
493 branch(*search_s,search_s->x,INT_VAR_NONE(),INT_VAL_MIN());
494 Search::Options search_o;
495 search_o.threads = 1;
496 DFS<TestSpace> e_s(search_s,search_o);
497 delete search_s;
498
499 while (a.has_more()) {
500 bool sol = solution(a);
501 if (opt.log) {
502 olog << ind(1) << "Assignment: " << a
503 << (sol ? " (solution)" : " (no solution)")
504 << std::endl;
505 }
506
507 START_TEST("Assignment (after posting)");
508 {
509 TestSpace* s = new TestSpace(arity,dom,this);
510 TestSpace* sc = nullptr;
511 s->post();
512 switch (_rand(2)) {
513 case 0:
514 if (opt.log)
515 olog << ind(3) << "No copy" << std::endl;
516 sc = s;
517 s = nullptr;
518 break;
519 case 1:
520 if (opt.log)
521 olog << ind(3) << "Copy" << std::endl;
522 if (s->status() != SS_FAILED) {
523 sc = static_cast<TestSpace*>(s->clone());
524 } else {
525 sc = s; s = nullptr;
526 }
527 break;
528 default: assert(false);
529 }
530 sc->assign(a, false, _rand);
531 if (sol) {
532 CHECK_TEST(!sc->failed(), "Failed on solution");
533 CHECK_TEST(sc->propagators()==0, "No subsumption");
534 } else {
535 CHECK_TEST(sc->failed(), "Solved on non-solution");
536 }
537 delete s; delete sc;
538 }
539 START_TEST("Partial assignment (after posting)");
540 {
541 TestSpace* s = new TestSpace(arity,dom,this);
542 s->post();
543 s->assign(a, true, _rand);
544 (void) s->failed();
545 s->assign(a, false, _rand);
546 if (sol) {
547 CHECK_TEST(!s->failed(), "Failed on solution");
548 CHECK_TEST(s->propagators()==0, "No subsumption");
549 } else {
550 CHECK_TEST(s->failed(), "Solved on non-solution");
551 }
552 delete s;
553 }
554 START_TEST("Assignment (after posting, disable)");
555 {
556 TestSpace* s = new TestSpace(arity,dom,this);
557 s->post();
558 s->disable();
559 s->assign(a, false, _rand);
560 s->enable();
561 if (sol) {
562 CHECK_TEST(!s->failed(), "Failed on solution");
563 CHECK_TEST(s->propagators()==0, "No subsumption");
564 } else {
565 CHECK_TEST(s->failed(), "Solved on non-solution");
566 }
567 delete s;
568 }
569 START_TEST("Partial assignment (after posting, disable)");
570 {
571 TestSpace* s = new TestSpace(arity,dom,this);
572 s->post();
573 s->assign(a, true, _rand);
574 s->disable();
575 (void) s->failed();
576 s->assign(a, false, _rand);
577 s->enable();
578 if (sol) {
579 CHECK_TEST(!s->failed(), "Failed on solution");
580 CHECK_TEST(s->propagators()==0, "No subsumption");
581 } else {
582 CHECK_TEST(s->failed(), "Solved on non-solution");
583 }
584 delete s;
585 }
586 START_TEST("Assignment (before posting)");
587 {
588 TestSpace* s = new TestSpace(arity,dom,this);
589 s->assign(a, false, _rand);
590 s->post();
591 if (sol) {
592 CHECK_TEST(!s->failed(), "Failed on solution");
593 CHECK_TEST(s->propagators()==0, "No subsumption");
594 } else {
595 CHECK_TEST(s->failed(), "Solved on non-solution");
596 }
597 delete s;
598 }
599 START_TEST("Partial assignment (before posting)");
600 {
601 TestSpace* s = new TestSpace(arity,dom,this);
602 s->assign(a, true, _rand);
603 s->post();
604 (void) s->failed();
605 s->assign(a, false, _rand);
606 if (sol) {
607 CHECK_TEST(!s->failed(), "Failed on solution");
608 CHECK_TEST(s->propagators()==0, "No subsumption");
609 } else {
610 CHECK_TEST(s->failed(), "Solved on non-solution");
611 }
612 delete s;
613 }
614 START_TEST("Prune");
615 {
616 TestSpace* s = new TestSpace(arity,dom,this);
617 s->post();
618 while (!s->failed() && !s->assigned())
619 if (!s->prune(a, testfix, _rand)) {
620 problem = "No fixpoint";
621 delete s;
622 goto failed;
623 }
624 s->assign(a, false, _rand);
625 if (sol) {
626 CHECK_TEST(!s->failed(), "Failed on solution");
627 CHECK_TEST(s->propagators()==0, "No subsumption");
628 } else {
629 CHECK_TEST(s->failed(), "Solved on non-solution");
630 }
631 delete s;
632 }
633 START_TEST("Prune (disable)");
634 {
635 TestSpace* s = new TestSpace(arity,dom,this);
636 TestSpace* c = static_cast<TestSpace*>(s->clone());
637 s->post(); c->post();
638 while (!s->failed() && !s->assigned())
639 if (!s->disabled(a, *c, testfix, _rand)) {
640 problem = "Different result after re-enable";
641 delete s; delete c;
642 goto failed;
643 }
644 if (testfix && (s->failed() != c->failed())) {
645 problem = "Different failure after re-enable";
646 delete s; delete c;
647 goto failed;
648 }
649 delete s; delete c;
650 }
651 if (!ignore(a)) {
652 if (eqv()) {
653 {
654 START_TEST("Assignment reified (rewrite after post, <=>)");
655 TestSpace* s = new TestSpace(arity,dom,this,RM_EQV);
656 s->post();
657 s->rel(sol);
658 s->assign(a, false, _rand);
659 CHECK_TEST(!s->failed(), "Failed");
660 CHECK_TEST(s->propagators()==0, "No subsumption");
661 delete s;
662 }
663 {
664 START_TEST("Assignment reified (rewrite failure, <=>)");
665 TestSpace* s = new TestSpace(arity,dom,this,RM_EQV);
666 s->post();
667 s->rel(!sol);
668 s->assign(a, false, _rand);
669 CHECK_TEST(s->failed(), "Not failed");
670 delete s;
671 }
672 {
673 START_TEST("Assignment reified (immediate rewrite, <=>)");
674 TestSpace* s = new TestSpace(arity,dom,this,RM_EQV);
675 s->rel(sol);
676 s->post();
677 s->assign(a, false, _rand);
678 CHECK_TEST(!s->failed(), "Failed");
679 CHECK_TEST(s->propagators()==0, "No subsumption");
680 delete s;
681 }
682 {
683 START_TEST("Assignment reified (immediate failure, <=>)");
684 TestSpace* s = new TestSpace(arity,dom,this,RM_EQV);
685 s->rel(!sol);
686 s->post();
687 s->assign(a, false, _rand);
688 CHECK_TEST(s->failed(), "Not failed");
689 delete s;
690 }
691 {
692 START_TEST("Assignment reified (before posting, <=>)");
693 TestSpace* s = new TestSpace(arity,dom,this,RM_EQV);
694 s->assign(a, false, _rand);
695 s->post();
696 CHECK_TEST(!s->failed(), "Failed");
697 CHECK_TEST(s->propagators()==0, "No subsumption");
698 CHECK_TEST(s->r.var().assigned(), "Control variable unassigned");
699 if (sol) {
700 CHECK_TEST(s->r.var().val()==1, "Zero on solution");
701 } else {
702 CHECK_TEST(s->r.var().val()==0, "One on non-solution");
703 }
704 delete s;
705 }
706 {
707 START_TEST("Assignment reified (after posting, <=>)");
708 TestSpace* s = new TestSpace(arity,dom,this,RM_EQV);
709 s->post();
710 s->assign(a, false, _rand);
711 CHECK_TEST(!s->failed(), "Failed");
712 CHECK_TEST(s->propagators()==0, "No subsumption");
713 CHECK_TEST(s->r.var().assigned(), "Control variable unassigned");
714 if (sol) {
715 CHECK_TEST(s->r.var().val()==1, "Zero on solution");
716 } else {
717 CHECK_TEST(s->r.var().val()==0, "One on non-solution");
718 }
719 delete s;
720 }
721 {
722 START_TEST("Assignment reified (after posting, <=>, disable)");
723 TestSpace* s = new TestSpace(arity,dom,this,RM_EQV);
724 s->post();
725 s->disable();
726 s->assign(a, false, _rand);
727 s->enable();
728 CHECK_TEST(!s->failed(), "Failed");
729 CHECK_TEST(s->propagators()==0, "No subsumption");
730 CHECK_TEST(s->r.var().assigned(), "Control variable unassigned");
731 if (sol) {
732 CHECK_TEST(s->r.var().val()==1, "Zero on solution");
733 } else {
734 CHECK_TEST(s->r.var().val()==0, "One on non-solution");
735 }
736 delete s;
737 }
738 {
739 START_TEST("Prune reified, <=>");
740 TestSpace* s = new TestSpace(arity,dom,this,RM_EQV);
741 s->post();
742 while (!s->failed() &&
743 (!s->assigned() || !s->r.var().assigned()))
744 if (!s->prune(a, testfix, _rand)) {
745 problem = "No fixpoint";
746 delete s;
747 goto failed;
748 }
749 CHECK_TEST(!s->failed(), "Failed");
750 CHECK_TEST(s->propagators()==0, "No subsumption");
751 CHECK_TEST(s->r.var().assigned(), "Control variable unassigned");
752 if (sol) {
753 CHECK_TEST(s->r.var().val()==1, "Zero on solution");
754 } else {
755 CHECK_TEST(s->r.var().val()==0, "One on non-solution");
756 }
757 delete s;
758 }
759 {
760 START_TEST("Prune reified, <=>, disable");
761 TestSpace* s = new TestSpace(arity,dom,this,RM_EQV);
762 TestSpace* c = static_cast<TestSpace*>(s->clone());
763 s->post(); c->post();
764 while (!s->failed() &&
765 (!s->assigned() || !s->r.var().assigned()))
766 if (!s->disabled(a, *c, testfix, _rand)) {
767 problem = "No fixpoint";
768 delete s;
769 delete c;
770 goto failed;
771 }
772 CHECK_TEST(!c->failed(), "Failed");
773 CHECK_TEST(c->propagators()==0, "No subsumption");
774 CHECK_TEST(c->r.var().assigned(), "Control variable unassigned");
775 if (sol) {
776 CHECK_TEST(c->r.var().val()==1, "Zero on solution");
777 } else {
778 CHECK_TEST(c->r.var().val()==0, "One on non-solution");
779 }
780 delete s;
781 delete c;
782 }
783 }
784
785 if (imp()) {
786 {
787 START_TEST("Assignment reified (rewrite after post, =>)");
788 TestSpace* s = new TestSpace(arity,dom,this,RM_IMP);
789 s->post();
790 s->rel(sol);
791 s->assign(a, false, _rand);
792 CHECK_TEST(!s->failed(), "Failed");
793 CHECK_TEST(s->propagators()==0, "No subsumption");
794 delete s;
795 }
796 {
797 START_TEST("Assignment reified (rewrite failure, =>)");
798 TestSpace* s = new TestSpace(arity,dom,this,RM_IMP);
799 s->post();
800 s->rel(!sol);
801 s->assign(a, false, _rand);
802 if (sol) {
803 CHECK_TEST(!s->failed(), "Failed");
804 CHECK_TEST(s->propagators()==0, "No subsumption");
805 } else {
806 CHECK_TEST(s->failed(), "Not failed");
807 }
808 delete s;
809 }
810 {
811 START_TEST("Assignment reified (immediate rewrite, =>)");
812 TestSpace* s = new TestSpace(arity,dom,this,RM_IMP);
813 s->rel(sol);
814 s->post();
815 s->assign(a, false, _rand);
816 CHECK_TEST(!s->failed(), "Failed");
817 CHECK_TEST(s->propagators()==0, "No subsumption");
818 delete s;
819 }
820 {
821 START_TEST("Assignment reified (immediate failure, =>)");
822 TestSpace* s = new TestSpace(arity,dom,this,RM_IMP);
823 s->rel(!sol);
824 s->post();
825 s->assign(a, false, _rand);
826 if (sol) {
827 CHECK_TEST(!s->failed(), "Failed");
828 CHECK_TEST(s->propagators()==0, "No subsumption");
829 } else {
830 CHECK_TEST(s->failed(), "Not failed");
831 }
832 delete s;
833 }
834 {
835 START_TEST("Assignment reified (before posting, =>)");
836 TestSpace* s = new TestSpace(arity,dom,this,RM_IMP);
837 s->assign(a, false, _rand);
838 s->post();
839 CHECK_TEST(!s->failed(), "Failed");
840 CHECK_TEST(s->propagators()==0, "No subsumption");
841 if (sol) {
842 CHECK_TEST(!s->r.var().assigned(), "Control variable assigned");
843 } else {
844 CHECK_TEST(s->r.var().assigned(), "Control variable unassigned");
845 CHECK_TEST(s->r.var().val()==0, "One on non-solution");
846 }
847 delete s;
848 }
849 {
850 START_TEST("Assignment reified (after posting, =>)");
851 TestSpace* s = new TestSpace(arity,dom,this,RM_IMP);
852 s->post();
853 s->assign(a, false, _rand);
854 CHECK_TEST(!s->failed(), "Failed");
855 CHECK_TEST(s->propagators()==0, "No subsumption");
856 if (sol) {
857 CHECK_TEST(!s->r.var().assigned(), "Control variable assigned");
858 } else {
859 CHECK_TEST(s->r.var().assigned(), "Control variable unassigned");
860 CHECK_TEST(s->r.var().val()==0, "One on non-solution");
861 }
862 delete s;
863 }
864 {
865 START_TEST("Assignment reified (after posting, =>, disable)");
866 TestSpace* s = new TestSpace(arity,dom,this,RM_IMP);
867 s->post();
868 s->disable();
869 s->assign(a, false, _rand);
870 s->enable();
871 CHECK_TEST(!s->failed(), "Failed");
872 CHECK_TEST(s->propagators()==0, "No subsumption");
873 if (sol) {
874 CHECK_TEST(!s->r.var().assigned(), "Control variable assigned");
875 } else {
876 CHECK_TEST(s->r.var().assigned(), "Control variable unassigned");
877 CHECK_TEST(s->r.var().val()==0, "One on non-solution");
878 }
879 delete s;
880 }
881 {
882 START_TEST("Prune reified, =>");
883 TestSpace* s = new TestSpace(arity,dom,this,RM_IMP);
884 s->post();
885 while (!s->failed() &&
886 (!s->assigned() || (!sol && !s->r.var().assigned())))
887 if (!s->prune(a, testfix, _rand)) {
888 problem = "No fixpoint";
889 delete s;
890 goto failed;
891 }
892 CHECK_TEST(!s->failed(), "Failed");
893 CHECK_TEST(s->propagators()==0, "No subsumption");
894 if (sol) {
895 CHECK_TEST(!s->r.var().assigned(), "Control variable assigned");
896 } else {
897 CHECK_TEST(s->r.var().assigned(), "Control variable unassigned");
898 CHECK_TEST(s->r.var().val()==0, "One on non-solution");
899 }
900 delete s;
901 }
902 {
903 START_TEST("Prune reified, =>, disable");
904 TestSpace* s = new TestSpace(arity,dom,this,RM_IMP);
905 TestSpace* c = static_cast<TestSpace*>(s->clone());
906 s->post(); c->post();
907 while (!s->failed() &&
908 (!s->assigned() || (!sol && !s->r.var().assigned())))
909 if (!s->disabled(a, *c, testfix, _rand)) {
910 problem = "No fixpoint";
911 delete s;
912 delete c;
913 goto failed;
914 }
915 CHECK_TEST(!c->failed(), "Failed");
916 CHECK_TEST(c->propagators()==0, "No subsumption");
917 if (sol) {
918 CHECK_TEST(!c->r.var().assigned(), "Control variable assigned");
919 } else {
920 CHECK_TEST(c->r.var().assigned(), "Control variable unassigned");
921 CHECK_TEST(c->r.var().val()==0, "One on non-solution");
922 }
923 delete s;
924 delete c;
925 }
926 }
927
928 if (pmi()) {
929 {
930 START_TEST("Assignment reified (rewrite after post, <=)");
931 TestSpace* s = new TestSpace(arity,dom,this,RM_PMI);
932 s->post();
933 s->rel(sol);
934 s->assign(a, false, _rand);
935 CHECK_TEST(!s->failed(), "Failed");
936 CHECK_TEST(s->propagators()==0, "No subsumption");
937 delete s;
938 }
939 {
940 START_TEST("Assignment reified (rewrite failure, <=)");
941 TestSpace* s = new TestSpace(arity,dom,this,RM_PMI);
942 s->post();
943 s->rel(!sol);
944 s->assign(a, false, _rand);
945 if (sol) {
946 CHECK_TEST(s->failed(), "Not failed");
947 } else {
948 CHECK_TEST(!s->failed(), "Failed");
949 CHECK_TEST(s->propagators()==0, "No subsumption");
950 }
951 delete s;
952 }
953 {
954 START_TEST("Assignment reified (immediate rewrite, <=)");
955 TestSpace* s = new TestSpace(arity,dom,this,RM_PMI);
956 s->rel(sol);
957 s->post();
958 s->assign(a, false, _rand);
959 CHECK_TEST(!s->failed(), "Failed");
960 CHECK_TEST(s->propagators()==0, "No subsumption");
961 delete s;
962 }
963 {
964 START_TEST("Assignment reified (immediate failure, <=)");
965 TestSpace* s = new TestSpace(arity,dom,this,RM_PMI);
966 s->rel(!sol);
967 s->post();
968 s->assign(a, false, _rand);
969 if (sol) {
970 CHECK_TEST(s->failed(), "Not failed");
971 } else {
972 CHECK_TEST(!s->failed(), "Failed");
973 CHECK_TEST(s->propagators()==0, "No subsumption");
974 }
975 delete s;
976 }
977 {
978 START_TEST("Assignment reified (before posting, <=)");
979 TestSpace* s = new TestSpace(arity,dom,this,RM_PMI);
980 s->assign(a, false, _rand);
981 s->post();
982 CHECK_TEST(!s->failed(), "Failed");
983 CHECK_TEST(s->propagators()==0, "No subsumption");
984 if (sol) {
985 CHECK_TEST(s->r.var().assigned(), "Control variable unassigned");
986 CHECK_TEST(s->r.var().val()==1, "Zero on solution");
987 } else {
988 CHECK_TEST(!s->r.var().assigned(), "Control variable assigned");
989 }
990 delete s;
991 }
992 {
993 START_TEST("Assignment reified (after posting, <=)");
994 TestSpace* s = new TestSpace(arity,dom,this,RM_PMI);
995 s->post();
996 s->assign(a, false, _rand);
997 CHECK_TEST(!s->failed(), "Failed");
998 CHECK_TEST(s->propagators()==0, "No subsumption");
999 if (sol) {
1000 CHECK_TEST(s->r.var().assigned(), "Control variable unassigned");
1001 CHECK_TEST(s->r.var().val()==1, "Zero on solution");
1002 } else {
1003 CHECK_TEST(!s->r.var().assigned(), "Control variable assigned");
1004 }
1005 delete s;
1006 }
1007 {
1008 START_TEST("Assignment reified (after posting, <=, disable)");
1009 TestSpace* s = new TestSpace(arity,dom,this,RM_PMI);
1010 s->post();
1011 s->disable();
1012 s->assign(a, false, _rand);
1013 s->enable();
1014 CHECK_TEST(!s->failed(), "Failed");
1015 CHECK_TEST(s->propagators()==0, "No subsumption");
1016 if (sol) {
1017 CHECK_TEST(s->r.var().assigned(), "Control variable unassigned");
1018 CHECK_TEST(s->r.var().val()==1, "Zero on solution");
1019 } else {
1020 CHECK_TEST(!s->r.var().assigned(), "Control variable assigned");
1021 }
1022 delete s;
1023 }
1024 {
1025 START_TEST("Prune reified, <=");
1026 TestSpace* s = new TestSpace(arity,dom,this,RM_PMI);
1027 s->post();
1028 while (!s->failed() &&
1029 (!s->assigned() || (sol && !s->r.var().assigned())))
1030 if (!s->prune(a, testfix, _rand)) {
1031 problem = "No fixpoint";
1032 delete s;
1033 goto failed;
1034 }
1035 CHECK_TEST(!s->failed(), "Failed");
1036 CHECK_TEST(s->propagators()==0, "No subsumption");
1037 if (sol) {
1038 CHECK_TEST(s->r.var().assigned(), "Control variable unassigned");
1039 CHECK_TEST(s->r.var().val()==1, "Zero on solution");
1040 } else {
1041 CHECK_TEST(!s->r.var().assigned(), "Control variable assigned");
1042 }
1043 delete s;
1044 }
1045 {
1046 START_TEST("Prune reified, <=, disable");
1047 TestSpace* s = new TestSpace(arity,dom,this,RM_PMI);
1048 TestSpace* c = static_cast<TestSpace*>(s->clone());
1049 s->post(); c->post();
1050 while (!s->failed() &&
1051 (!s->assigned() || (sol && !s->r.var().assigned())))
1052 if (!s->disabled(a, *c, testfix, _rand)) {
1053 problem = "No fixpoint";
1054 delete s;
1055 delete c;
1056 goto failed;
1057 }
1058 CHECK_TEST(!c->failed(), "Failed");
1059 CHECK_TEST(c->propagators()==0, "No subsumption");
1060 if (sol) {
1061 CHECK_TEST(c->r.var().assigned(), "Control variable unassigned");
1062 CHECK_TEST(c->r.var().val()==1, "Zero on solution");
1063 } else {
1064 CHECK_TEST(!c->r.var().assigned(), "Control variable assigned");
1065 }
1066 delete s;
1067 delete c;
1068 }
1069 }
1070 }
1071
1072 if (testsearch) {
1073 if (sol) {
1074 START_TEST("Search");
1075 TestSpace* s = e_s.next();
1076 CHECK_TEST(s != nullptr, "Solutions exhausted");
1077 CHECK_TEST(s->propagators()==0, "No subsumption");
1078 for (int i=a.size(); i--; ) {
1079 CHECK_TEST(s->x[i].assigned(), "Unassigned variable");
1080 CHECK_TEST(a[i] == s->x[i].val(), "Wrong value in solution");
1081 }
1082 delete s;
1083 }
1084 }
1085
1086 a.next(_rand);
1087 }
1088
1089 if (testsearch) {
1090 test = "Search";
1091 if (e_s.next() != nullptr) {
1092 problem = "Excess solutions";
1093 goto failed;
1094 }
1095 }
1096
1097 switch (contest) {
1098 case CTL_NONE: break;
1099 case CTL_DOMAIN: {
1100 START_TEST("Full domain consistency");
1101 TestSpace* s = new TestSpace(arity,dom,this);
1102 s->post();
1103 if (!s->failed()) {
1104 while (!s->failed() && !s->assigned())
1105 s->prune(_rand);
1106 CHECK_TEST(!s->failed(), "Failed");
1107 CHECK_TEST(s->propagators()==0, "No subsumption");
1108 }
1109 delete s;
1110 // Fall-through -- domain implies bounds(d) and bounds(z)
1111 }
1112 case CTL_BOUNDS_D: {
1113 START_TEST("Bounds(D)-consistency");
1114 TestSpace* s = new TestSpace(arity,dom,this);
1115 s->post();
1116 for (int i = s->x.size(); i--; )
1117 s->prune(i, false, _rand);
1118 if (!s->failed()) {
1119 while (!s->failed() && !s->assigned())
1120 s->bound(_rand);
1121 CHECK_TEST(!s->failed(), "Failed");
1122 CHECK_TEST(s->propagators()==0, "No subsumption");
1123 }
1124 delete s;
1125 // Fall-through -- bounds(d) implies bounds(z)
1126 }
1127 case CTL_BOUNDS_Z: {
1128 START_TEST("Bounds(Z)-consistency");
1129 TestSpace* s = new TestSpace(arity,dom,this);
1130 s->post();
1131 for (int i = s->x.size(); i--; )
1132 s->prune(i, true, _rand);
1133 if (!s->failed()) {
1134 while (!s->failed() && !s->assigned())
1135 s->bound(_rand);
1136 CHECK_TEST(!s->failed(), "Failed");
1137 CHECK_TEST(s->propagators()==0, "No subsumption");
1138 }
1139 delete s;
1140 break;
1141 }
1142 }
1143
1144 delete ap;
1145 return true;
1146
1147 failed:
1148 if (opt.log)
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;
1154 delete ap;
1155
1156 return false;
1157 }
1158
1159 OpenTest::OpenTest(const std::string& name, int items0, int extra,
1160 const Gecode::IntSet& domain, Gecode::IntPropLevel level)
1161 : Test(name,items0+extra,domain,false,level), items(items0) {}
1162
1163 void
1165 Gecode::OpenIntVarList list(home,dom,items);
1166 post(home,list,x);
1167 for (int i=0; i<items; i++)
1168 list.append(home,x[i]);
1169 list.close(home);
1170 }
1171
1173 class OpenTestSpace : public TestSpace {
1174 public:
1177
1178 OpenTestSpace(int arity, Gecode::IntSet& domain, OpenTest* test, int items0)
1179 : TestSpace(arity,domain,test), items(items0),
1181 [](Gecode::Space& home, int i) {
1182 OpenTestSpace& s = static_cast<OpenTestSpace&>(home);
1183 return (i < s.items) ? s.x[i] : Gecode::IntVar(home,s.d);
1184 },items+1)) {}
1185
1187 : TestSpace(s), items(s.items) {
1188 list.update(*this,s.list);
1189 }
1190
1191 Gecode::Space* copy(void) override {
1192 return new OpenTestSpace(*this);
1193 }
1194
1195 void post_open(void) {
1196 if (opt.log)
1197 olog << ind(3) << "Posting with " << list.known_length()
1198 << " open-list items" << std::endl;
1199 static_cast<OpenTest*>(test)->post(*this,list,x);
1200 }
1201
1203 bool retains(const Assignment& a) {
1204 if (failed() || !list.length().in(items))
1205 return false;
1206 for (int i=0; i<x.size(); i++)
1207 if (!x[i].in(a[i]))
1208 return false;
1209 return true;
1210 }
1211 };
1212
1213 bool
1215 using namespace Gecode;
1216 if (!Test::run())
1217 return false;
1218
1219 // Limit the randomized histories to 16 solutions and 16 non-solutions.
1220 int solutions = 0;
1221 int nonsolutions = 0;
1222 std::unique_ptr<Assignment> assignments(assignment());
1223 Assignment& a = *assignments;
1224 for (; a.has_more() && ((solutions < 16) || (nonsolutions < 16));
1225 a.next(_rand)) {
1226 const bool sol = solution(a);
1227 int& checked = sol ? solutions : nonsolutions;
1228 if (checked == 16)
1229 continue;
1230 checked++;
1231 if (opt.log) {
1232 olog.str("");
1233 olog << ind(1) << "Open-list assignment: " << a
1234 << (sol ? " (solution)" : " (no solution)") << std::endl;
1235 }
1236
1237 const auto complete = [&](OpenTestSpace& s) {
1238 s.list.materialize(s,items);
1239 if (_rand(2) == 0)
1240 s.list.close(s);
1241 s.assign(a,false,_rand);
1242 s.list.close(s);
1243 Gecode::rel(s,s.list.length(),IRT_EQ,items);
1244 return s.failed() == !sol;
1245 };
1246
1247 const auto history = [&]() {
1248 OpenTestSpace s(arity,dom,this,items);
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++) {
1254 if (n == post_at)
1255 s.post_open();
1256 if (!s.retains(a))
1257 return complete(s);
1258
1259 // Restrict an old item or an auxiliary variable, keeping the target.
1260 const int known = std::min(items,s.list.known_length());
1261 const int available = known+arity-items;
1262 if (available > 0) {
1263 int i = static_cast<int>
1264 (_rand(static_cast<unsigned int>(available)));
1265 if (i >= known)
1266 i += items-known;
1267 if (!s.x[i].assigned()) {
1268 if (_rand(4) == 0) {
1269 s.rel(i,IRT_EQ,a[i]);
1270 } else {
1271 IntRelType relation;
1272 int value;
1273 s.rndrel(a,i,relation,value,_rand);
1274 if (relation != IRT_EQ)
1275 s.rel(i,relation,value);
1276 }
1277 }
1278 }
1279 if (!s.retains(a))
1280 return complete(s);
1281
1282 if (n == clone_at) {
1283 if (opt.log)
1284 olog << ind(3) << "Cloning open list" << std::endl;
1285 const int before = s.list.known_length();
1286 const int length_min = s.list.length().min();
1287 const int length_max = s.list.length().max();
1288 IntArgs sizes(arity);
1289 for (int i=0; i<arity; i++)
1290 sizes[i] = static_cast<int>(s.x[i].size());
1291 std::unique_ptr<OpenTestSpace> c
1292 (static_cast<OpenTestSpace*>(s.clone()));
1293 if (!complete(*c))
1294 return false;
1295 if ((s.list.known_length() != before) ||
1296 (s.list.length().min() != length_min) ||
1297 (s.list.length().max() != length_max))
1298 return false;
1299 for (int i=0; i<arity; i++)
1300 if (s.x[i].size() != static_cast<unsigned int>(sizes[i]))
1301 return false;
1302 }
1303
1304 if ((n < items) && (s.list.known_length() <= n)) {
1305 const int end = std::min(items,n+1+static_cast<int>(_rand(2)));
1306 if (_rand(2) == 0) {
1307 if (opt.log)
1308 olog << ind(3) << "Appending through item " << end-1
1309 << std::endl;
1310 for (int i=s.list.known_length(); i<end; i++)
1311 s.list.append(s,s.x[i]);
1312 } else {
1313 if (opt.log)
1314 olog << ind(3) << "Requiring " << end << " items"
1315 << std::endl;
1316 Gecode::rel(s,s.list.length(),IRT_GQ,end);
1317 }
1318 }
1319 }
1320 return complete(s);
1321 };
1322
1323 if (!history()) {
1324 if (opt.log)
1325 olog << "FAILURE in incremental open-list history" << std::endl;
1326 return false;
1327 }
1328 }
1329 return true;
1330 }
1331
1332}}
1333
1334#undef START_TEST
1335#undef CHECK_TEST
1336
1337// STATISTICS: test-int
Boolean integer variables.
Definition int.hh:534
int val(void) const
Return assigned value.
Definition bool.hpp:57
Depth-first search engine.
Definition search.hh:1211
FloatNum size(void) const
Return size of float value (distance between maximum and minimum).
Definition val.hpp:78
Passing integer arguments.
Definition int.hh:653
Integer sets.
Definition int.hh:179
Passing integer variables.
Definition int.hh:681
Integer variable array.
Definition int.hh:792
Integer variables.
Definition int.hh:390
int min(void) const
Return minimum of domain.
Definition int.hpp:62
int max(void) const
Return maximum of domain.
Definition int.hpp:70
Range iterator for integer views.
Definition view.hpp:54
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.
Definition int.hh:1076
Space-local list of variables with an open length.
Definition int.hh:923
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.
Options for scripts
Definition driver.hh:447
void threads(double n)
Set number of parallel threads.
Definition options.hpp:330
static PropagatorGroup all
Group of all propagators.
Definition core.hpp:796
Reification specification.
Definition int.hh:1176
BoolVar var(void) const
Return Boolean control variable.
Definition reify.hpp:48
ReifyMode mode(void) const
Return reification mode.
Definition reify.hpp:56
virtual T * next(void)
Return next solution (nullptr, if none exists or search has been stopped).
Definition base.hpp:46
Computation spaces.
Definition core.hpp:1787
struct Gecode::Space::@055132133326276162005044145100211202071356247106::@155123175027073262103111264343315000271204104107 c
Data available only during copying.
SpaceStatus status(void)
Query space status without collecting statistics.
Definition core.hpp:3378
bool assigned(void) const
Test if all variables are assigned.
Definition array.hpp:1045
int size(void) const
Return size of array (number of elements).
Definition array.hpp:945
bool assigned(void) const
Test whether view is assigned.
Definition var.hpp:111
Gecode::Support::RandomGenerator _rand
Random number generator.
Definition test.hh:238
bool fixpoint(void)
Throw a coin whether to compute a fixpoint.
Definition test.hpp:111
const std::string & name(void) const
Return name of test.
Definition test.hpp:91
Base class for assignments
Definition int.hh:73
Gecode::IntSet d
Domain for each variable.
Definition int.hh:76
int n
Number of variables.
Definition int.hh:75
Generate all assignments.
Definition int.hh:93
virtual void next(Gecode::Support::RandomGenerator &rand)
Move to next assignment.
Definition int.cpp:49
Gecode::IntSetValues * dsv
Iterator for each variable.
Definition int.hh:95
The item factory uses variables from the space being materialized.
Definition int.cpp:1173
Gecode::OpenIntVarList list
Definition int.cpp:1176
Gecode::Space * copy(void) override
Copy space during cloning.
Definition int.cpp:1191
OpenTestSpace(int arity, Gecode::IntSet &domain, OpenTest *test, int items0)
Definition int.cpp:1178
OpenTestSpace(OpenTestSpace &s)
Definition int.cpp:1186
bool retains(const Assignment &a)
Whether the target assignment and length are possible after propagation.
Definition int.cpp:1203
Integer constraint tests with incremental open-list histories.
Definition int.hh:410
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.
Definition int.cpp:1159
int items
Number of items in the completed list.
Definition int.hh:413
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.
Definition int.cpp:1214
int a
How many assignments still to be generated Generate new value according to domain.
Definition int.hh:113
int * vals
The current values for the variables.
Definition int.hh:112
int randval(Gecode::Support::RandomGenerator &rand)
Definition int.hpp:76
virtual void next(Gecode::Support::RandomGenerator &rand)
Move to next assignment.
Definition int.cpp:63
int _n1
How many variables in the second set.
Definition int.hh:134
int randval(const Gecode::IntSet &d, Gecode::Support::RandomGenerator &rand)
Definition int.hpp:109
Gecode::IntSet _d1
Domain for second set of variables Generate new value according to domain d.
Definition int.hh:135
virtual void next(Gecode::Support::RandomGenerator &rand)
Move to next assignment.
Definition int.cpp:70
int a
How many assignments still to be generated.
Definition int.hh:133
int * vals
The current values for the variables.
Definition int.hh:132
Space for executing tests.
Definition int.hh:163
int rndvar(Gecode::Support::RandomGenerator &rand)
Randomly select an unassigned variable.
Definition int.cpp:170
Gecode::Reify r
Reification information.
Definition int.hh:170
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.
Definition int.cpp:260
TestSpace(int n, Gecode::IntSet &d, Test *t)
Create test space without reification.
Definition int.cpp:91
Gecode::IntSet d
Initial domain.
Definition int.hh:166
void rndrel(const Assignment &a, int i, Gecode::IntRelType &irt, int &v, Gecode::Support::RandomGenerator &rand)
Randomly select a pruning rel for variable i.
Definition int.cpp:181
Test * test
The test currently run.
Definition int.hh:172
virtual Gecode::Space * copy(void)
Copy space during cloning.
Definition int.cpp:132
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.
Definition int.cpp:380
void post(void)
Post propagator.
Definition int.cpp:145
bool assigned(void) const
Test whether all variables are assigned.
Definition int.cpp:137
void prune(int i, bool bounds_only, Gecode::Support::RandomGenerator &rand)
Prune some random values from variable i.
Definition int.cpp:281
bool failed(void)
Compute a fixpoint and check for failure.
Definition int.cpp:158
bool reified
Whether the test is for a reified propagator.
Definition int.hh:174
void disable(void)
Disable propagators in space and compute fixpoint (make all idle).
Definition int.cpp:374
Gecode::IntVarArray x
Variables to be tested.
Definition int.hh:168
void bound(Gecode::Support::RandomGenerator &rand)
Assign a random variable to a random bound.
Definition int.cpp:273
void enable(void)
Enable propagators in space.
Definition int.cpp:369
void rel(int i, Gecode::IntRelType irt, int n)
Perform integer tell operation on x[i].
Definition int.cpp:234
unsigned int propagators(void)
Return the number of propagators.
Definition int.cpp:427
bool pmi(void) const
Test whether reverse implication as reification mode is supported.
Definition int.hpp:160
virtual bool run(void)
Perform test.
Definition int.cpp:481
virtual bool ignore(const Assignment &) const
Whether to ignore assignment for reification.
Definition int.cpp:472
bool testsearch
Whether to perform search test.
Definition int.hh:285
bool testfix
Whether to perform fixpoint test.
Definition int.hh:287
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)=0
Post constraint.
bool eqv(void) const
Test whether equivalence as reification mode is supported.
Definition int.hpp:152
int arity
Number of variables.
Definition int.hh:273
virtual bool solution(const Assignment &) const =0
Check for solution.
virtual Assignment * assignment(void) const
Create the assignment generator (complete by default).
Definition int.cpp:446
Gecode::IntSet dom
Domain of variables.
Definition int.hh:275
bool imp(void) const
Test whether implication as reification mode is supported.
Definition int.hpp:156
ConTestLevel contest
Whether to test for certain consistency.
Definition int.hh:283
Simple class for describing indentation.
Definition test.hh:82
LinearCongruentialGenerator< 2147483647, 48271, 44488, 3399 > RandomGenerator
Default values for linear congruential generator.
Definition random.hpp:183
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.
Definition branch.cpp:39
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVar x1)
Post propagator for .
Definition rel.cpp:68
IntRelType
Relation types for integers.
Definition int.hh:1225
ReifyMode
Mode for reification.
Definition int.hh:1148
BoolOpType
Operation types for Booleans.
Definition int.hh:1250
IntPropLevel
Propagation levels for integer propagators.
Definition int.hh:1274
@ IRT_EQ
Equality ( ).
Definition int.hh:1226
@ IRT_NQ
Disequality ( ).
Definition int.hh:1227
@ IRT_GQ
Greater or equal ( ).
Definition int.hh:1230
@ IRT_LE
Less ( ).
Definition int.hh:1229
@ IRT_GR
Greater ( ).
Definition int.hh:1231
@ IRT_LQ
Less or equal ( ).
Definition int.hh:1228
@ RM_IMP
Implication for reification.
Definition int.hh:1162
@ RM_PMI
Inverse implication for reification.
Definition int.hh:1169
@ RM_EQV
Equivalence for reification (default).
Definition int.hh:1155
@ BOT_OR
Disjunction.
Definition int.hh:1252
@ BOT_EQV
Equivalence.
Definition int.hh:1254
@ BOT_IMP
Implication.
Definition int.hh:1253
@ BOT_XOR
Exclusive or.
Definition int.hh:1255
@ BOT_AND
Conjunction.
Definition int.hh:1251
@ IPL_BASIC
Use basic propagation algorithm.
Definition int.hh:1281
@ IPL_BASIC_ADVANCED
Use both.
Definition int.hh:1283
@ IPL_DOM
Domain propagation Options: basic versus advanced propagation.
Definition int.hh:1279
@ IPL_VAL
Value propagation.
Definition int.hh:1277
@ IPL_ADVANCED
Use advanced propagation algorithm.
Definition int.hh:1282
@ IPL_BND
Bounds propagation.
Definition int.hh:1278
Space(void)
Default constructor.
Definition core.cpp:121
Space * clone(void) const
Clone space.
Definition core.hpp:3384
SpaceStatus status(StatusStatistics &stat)
Query space status.
Definition core.cpp:281
@ SS_FAILED
Space is failed
Definition core.hpp:1727
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.
Definition var.hpp:96
void dom(Home home, FloatVar x, FloatVal n)
Propagates .
Definition dom.cpp:40
IntValBranch INT_VAL_MIN(void)
Select smallest value.
Definition val.hpp:55
void max(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Testing finite domain integers.
Definition int.cpp:41
@ CTL_BOUNDS_Z
Test for bounds(z)-consistency.
Definition int.hh:157
@ CTL_BOUNDS_D
Test for bounds(d)-consistency.
Definition int.hh:156
@ CTL_NONE
No consistency-test.
Definition int.hh:154
@ CTL_DOMAIN
Test for domain-consistency.
Definition int.hh:155
General test support.
Definition afc.cpp:41
std::ostringstream olog
Stream used for logging.
Definition test.cpp:54
Options opt
The options.
Definition test.cpp:163
#define START_TEST(T)
Start new test.
Definition array.cpp:52
#define CHECK_TEST(T, M)
Check the test result and handle failed test.
Definition array.cpp:42
std::ostream & operator<<(std::ostream &os, const Test::Int::Assignment &a)
Definition int.cpp:81