Generated on for Gecode by doxygen 1.15.0
search.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 *
6 * Contributing authors:
7 * Mikael Zayenz Lagerkvist <lagerkvist@gecode.dev>
8 *
9 * Copyright:
10 * Christian Schulte, 2008
11 * Mikael Zayenz Lagerkvist, 2026
12 *
13 * This file is part of Gecode, the generic constraint
14 * development environment:
15 * http://www.gecode.dev
16 *
17 * Permission is hereby granted, free of charge, to any person obtaining
18 * a copy of this software and associated documentation files (the
19 * "Software"), to deal in the Software without restriction, including
20 * without limitation the rights to use, copy, modify, merge, publish,
21 * distribute, sublicense, and/or sell copies of the Software, and to
22 * permit persons to whom the Software is furnished to do so, subject to
23 * the following conditions:
24 *
25 * The above copyright notice and this permission notice shall be
26 * included in all copies or substantial portions of the Software.
27 *
28 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 *
36 */
37
38#include <gecode/minimodel.hh>
39#include <gecode/search.hh>
40
41#include "test/test.hh"
42
43#include <type_traits>
44
45static_assert(std::is_copy_constructible<Gecode::NoGoods>::value,
46 "NoGoods must remain copy constructible");
47static_assert(std::is_copy_assignable<Gecode::NoGoods>::value,
48 "NoGoods must remain copy assignable");
49static_assert(std::is_copy_constructible<Gecode::Search::NodeStop>::value,
50 "NodeStop must remain copy constructible");
51static_assert(std::is_copy_assignable<Gecode::Search::NodeStop>::value,
52 "NodeStop must remain copy assignable");
53static_assert(std::is_copy_constructible<Gecode::Search::FailStop>::value,
54 "FailStop must remain copy constructible");
55static_assert(std::is_copy_assignable<Gecode::Search::FailStop>::value,
56 "FailStop must remain copy assignable");
57static_assert(std::is_copy_constructible<Gecode::Search::TimeStop>::value,
58 "TimeStop must remain copy constructible");
59static_assert(std::is_copy_assignable<Gecode::Search::TimeStop>::value,
60 "TimeStop must remain copy assignable");
61static_assert(std::is_copy_constructible<Gecode::Search::RestartStop>::value,
62 "RestartStop must remain copy constructible");
63static_assert(std::is_copy_assignable<Gecode::Search::RestartStop>::value,
64 "RestartStop must remain copy assignable");
65
66namespace Test {
67
69 namespace Search {
70
71 using namespace Gecode;
72 using namespace Gecode::Int;
73
81
90
97
99 class TestSpace : public Space {
100 public:
102 TestSpace(void) {}
106 virtual int solutions(void) const = 0;
108 virtual bool best(void) const = 0;
110 virtual bool master(const MetaInfo& mi) {
111 if (mi.type() == MetaInfo::RESTART) {
112 if (mi.last() != nullptr)
113 constrain(*mi.last());
114 return false;
115 } else {
116 return false;
117 }
118 }
119 };
120
122 class FailImmediate : public TestSpace {
123 public:
129 : x(*this,1,0,0) {
130 rel(*this, x[0], IRT_EQ, 1);
131 }
132
134 x.update(*this, s.x);
135 }
136
137 virtual Space* copy(void) {
138 return new FailImmediate(*this);
139 }
140
141 virtual void constrain(const Space&) {
142 }
143
144 virtual int solutions(void) const {
145 return 0;
146 }
147
148 virtual bool best(void) const {
149 return false;
150 }
151
152 static std::string name(void) {
153 return "Fail";
154 }
155 };
156
158 class SolveImmediate : public TestSpace {
159 public:
166
168 x.update(*this, s.x);
169 }
170
171 virtual Space* copy(void) {
172 return new SolveImmediate(*this);
173 }
174
175 virtual void constrain(const Space&) {
176 fail();
177 }
178
179 virtual int solutions(void) const {
180 return 1;
181 }
182
183 virtual bool best(void) const {
184 return true;
185 }
186
187 static std::string name(void) {
188 return "Solve";
189 }
190 };
191
193 class HasSolutions : public TestSpace {
194 public:
202 void branch(const IntVarArgs& x, HowToBranch htb) {
203 switch (htb) {
204 case HTB_NONE:
205 break;
206 case HTB_UNARY:
207 assign(*this, x, INT_ASSIGN_MIN());
208 break;
209 case HTB_BINARY:
211 break;
212 case HTB_NARY:
214 break;
215 }
216 }
217
220 : x(*this,6,0,5), htb1(_htb1), htb2(_htb2), htb3(_htb3), htc(_htc) {
221 distinct(*this, x);
222 rel(*this, x[2], IRT_LQ, 3); rel(*this, x[3], IRT_LQ, 3);
223 rel(*this, x[4], IRT_LQ, 1); rel(*this, x[5], IRT_LQ, 1);
224 IntVarArgs x1(2); x1[0]=x[0]; x1[1]=x[1]; branch(x1, htb1);
225 IntVarArgs x2(2); x2[0]=x[2]; x2[1]=x[3]; branch(x2, htb2);
226 IntVarArgs x3(2); x3[0]=x[4]; x3[1]=x[5]; branch(x3, htb3);
227 }
228
230 : TestSpace(s),
231 htb1(s.htb1), htb2(s.htb2), htb3(s.htb3), htc(s.htc) {
232 x.update(*this, s.x);
233 }
234
235 virtual Space* copy(void) {
236 return new HasSolutions(*this);
237 }
238
239 virtual void constrain(const Space& _s) {
240 const HasSolutions& s = static_cast<const HasSolutions&>(_s);
241 switch (htc) {
242 case HTC_NONE:
243 break;
244 case HTC_LEX_LE:
245 case HTC_LEX_GR:
246 {
247 IntVarArgs y(6);
248 for (int i=0; i<6; i++)
249 y[i] = IntVar(*this, s.x[i].val(), s.x[i].val());
250 lex(*this, x, (htc == HTC_LEX_LE) ? IRT_LE : IRT_GR, y);
251 break;
252 }
253 case HTC_BAL_LE:
254 case HTC_BAL_GR:
255 {
256 IntVarArgs y(6);
257 for (int i=0; i<6; i++)
258 y[i] = IntVar(*this, s.x[i].val(), s.x[i].val());
259 IntVar xs(*this, -18, 18);
260 IntVar ys(*this, -18, 18);
261 rel(*this, x[0]+x[1]+x[2]-x[3]-x[4]-x[5] == xs);
262 rel(*this, y[0]+y[1]+y[2]-y[3]-y[4]-y[5] == ys);
263 rel(*this,
264 expr(*this,abs(xs)),
265 (htc == HTC_BAL_LE) ? IRT_LE : IRT_GR,
266 expr(*this,abs(ys)));
267 break;
268 }
269 }
270 }
271
272 virtual int solutions(void) const {
273 if (htb1 == HTB_NONE) {
274 assert((htb2 == HTB_NONE) && (htb3 == HTB_NONE));
275 return 1;
276 }
277 if ((htb1 == HTB_UNARY) || (htb2 == HTB_UNARY))
278 return 0;
279 if (htb3 == HTB_UNARY)
280 return 4;
281 return 8;
282 }
283
284 virtual bool best(void) const {
285 if ((htb1 == HTB_NONE) || (htb2 == HTB_NONE) || (htb3 == HTB_NONE) ||
286 (htb1 == HTB_UNARY) || (htb2 == HTB_UNARY) || (htb3 == HTB_UNARY))
287 return true;
288 switch (htc) {
289 case HTC_NONE:
290 return true;
291 case HTC_LEX_LE:
292 return ((x[0].val()==4) && (x[1].val()==5) &&
293 (x[2].val()==2) && (x[3].val()==3) &&
294 (x[4].val()==0) && (x[5].val()==1));
295 case HTC_LEX_GR:
296 return ((x[0].val()==5) && (x[1].val()==4) &&
297 (x[2].val()==3) && (x[3].val()==2) &&
298 (x[4].val()==1) && (x[5].val()==0));
299 case HTC_BAL_LE:
300 return ((x[0].val()==4) && (x[1].val()==5) &&
301 (x[2].val()==2) && (x[3].val()==3) &&
302 (x[4].val()==0) && (x[5].val()==1));
303 case HTC_BAL_GR:
304 return ((x[0].val()==4) && (x[1].val()==5) &&
305 (x[2].val()==3) && (x[3].val()==2) &&
306 (x[4].val()==0) && (x[5].val()==1));
307 default: GECODE_NEVER;
308 }
309 return false;
310 }
311
312 static std::string name(void) {
313 return "Sol";
314 }
315
316 virtual bool master(const MetaInfo& mi) {
317 switch (mi.type()) {
319 if (mi.last() != nullptr) {
320 const HasSolutions* s
321 = static_cast<const HasSolutions*>(mi.last());
322 BoolVarArgs b;
323 for (int i=0; i<x.size(); i++)
324 b << expr(*this, x[i] == s->x[i]);
325 rel(*this, BOT_AND, b, 0);
326 }
327 break;
329 // Do not kill the brancher!
330 break;
331 default:
332 break;
333 }
334 return false;
335 }
336 };
337
339 class Test : public Base {
340 public:
346 static std::string str(unsigned int i) {
347 std::stringstream s;
348 s << i;
349 return s.str();
350 }
351
352 static std::string str(HowToBranch htb) {
353 switch (htb) {
354 case HTB_NONE: return "None";
355 case HTB_UNARY: return "Unary";
356 case HTB_BINARY: return "Binary";
357 case HTB_NARY: return "Nary";
358 default: GECODE_NEVER;
359 }
361 return "";
362 }
363
364 static std::string str(HowToConstrain htc) {
365 switch (htc) {
366 case HTC_NONE: return "None";
367 case HTC_LEX_LE: return "LexLe";
368 case HTC_LEX_GR: return "LexGr";
369 case HTC_BAL_LE: return "BalLe";
370 case HTC_BAL_GR: return "BalGr";
371 default: GECODE_NEVER;
372 }
374 return "";
375 }
376
377 Test(const std::string& s,
378 HowToBranch _htb1, HowToBranch _htb2, HowToBranch _htb3,
380 : Base("Search::"+s),
381 htb1(_htb1), htb2(_htb2), htb3(_htb3), htc(_htc) {}
382 };
383
385 template<class Model>
386 class DFS : public Test {
387 private:
389 unsigned int c_d;
391 unsigned int a_d;
393 unsigned int t;
394 public:
397 unsigned int c_d0, unsigned int a_d0, unsigned int t0)
398 : Test("DFS::"+Model::name()+"::"+
399 str(htb1)+"::"+str(htb2)+"::"+str(htb3)+"::"+
400 str(c_d0)+"::"+str(a_d0)+"::"+str(t0),
401 htb1,htb2,htb3), c_d(c_d0), a_d(a_d0), t(t0) {}
402
403 virtual bool run(void) {
404 Model* m = new Model(htb1,htb2,htb3);
407 o.c_d = c_d;
408 o.a_d = a_d;
409 o.threads = t;
410 o.stop = &f;
412 int n = m->solutions();
413 delete m;
414 while (true) {
415 Model* s = dfs.next();
416 if (s != nullptr) {
417 n--; delete s;
418 }
419 if ((s == nullptr) && !dfs.stopped())
420 break;
421 f.limit(f.limit()+2);
422 }
423 return n == 0;
424 }
425 };
426
428 template<class Model>
429 class LDS : public Test {
430 private:
432 unsigned int t;
433 public:
436 unsigned int t0)
437 : Test("LDS::"+Model::name()+"::"+
438 str(htb1)+"::"+str(htb2)+"::"+str(htb3)+"::"+str(t0),
439 htb1,htb2,htb3), t(t0) {}
440
441 virtual bool run(void) {
442 Model* m = new Model(htb1,htb2,htb3);
445 o.threads = t;
446 o.d_l = 50;
447 o.stop = &f;
449 int n = m->solutions();
450 delete m;
451 while (true) {
452 Model* s = lds.next();
453 if (s != nullptr) {
454 n--; delete s;
455 }
456 if ((s == nullptr) && !lds.stopped())
457 break;
458 f.limit(f.limit()+2);
459 }
460 return n == 0;
461 }
462 };
463
465 template<class Model>
466 class BAB : public Test {
467 private:
469 unsigned int c_d;
471 unsigned int a_d;
473 unsigned int t;
474 public:
478 unsigned int c_d0, unsigned int a_d0, unsigned int t0)
479 : Test("BAB::"+Model::name()+"::"+str(htc)+"::"+
480 str(htb1)+"::"+str(htb2)+"::"+str(htb3)+"::"+
481 str(c_d0)+"::"+str(a_d0)+"::"+str(t0),
482 htb1,htb2,htb3,htc), c_d(c_d0), a_d(a_d0), t(t0) {}
483
484 virtual bool run(void) {
485 Model* m = new Model(htb1,htb2,htb3,htc);
488 o.c_d = c_d;
489 o.a_d = a_d;
490 o.threads = t;
491 o.stop = &f;
493 delete m;
494 Model* b = nullptr;
495 while (true) {
496 Model* s = bab.next();
497 if (s != nullptr) {
498 delete b; b=s;
499 }
500 if ((s == nullptr) && !bab.stopped())
501 break;
502 f.limit(f.limit()+2);
503 }
504 bool ok = (b == nullptr) || b->best();
505 delete b;
506 return ok;
507 }
508 };
509
511 template<class Model, template<class> class Engine>
512 class RBS : public Test {
513 private:
515 unsigned int t;
516 public:
518 RBS(const std::string& e, unsigned int t0)
519 : Test("RBS::"+e+"::"+Model::name()+"::"+str(t0),
521
522 virtual bool run(void) {
523 Model* m = new Model(htb1,htb2,htb3);
526 o.threads = t;
527 o.stop = &f;
528 o.d_l = 100;
531 int n = m->solutions();
532 delete m;
533 while (true) {
534 Model* s = rbs.next();
535 if (s != nullptr) {
536 n--; delete s;
537 }
538 if ((s == nullptr) && !rbs.stopped())
539 break;
540 f.limit(f.limit()+2);
541 }
542 return n == 0;
543 }
544 };
545
547 template<class Model, template<class> class Engine>
548 class PBS : public Test {
549 private:
551 bool best;
553 unsigned int a;
555 unsigned int t;
556 public:
558 PBS(const std::string& e, bool b, unsigned int a0, unsigned int t0)
559 : Test("PBS::"+e+"::"+Model::name()+"::"+str(a0)+"::"+str(t0),
560 HTB_BINARY,HTB_BINARY,HTB_BINARY), best(b), a(a0), t(t0) {}
561
562 virtual bool run(void) {
563 Model* m = new Model(htb1,htb2,htb3);
566 o.assets = a;
567 o.threads = t;
568 o.d_l = 100;
569 o.stop = &f;
571 if (best) {
572 Model* b = nullptr;
573 while (true) {
574 Model* s = pbs.next();
575 if (s != nullptr) {
576 delete b; b=s;
577 }
578 if ((s == nullptr) && !pbs.stopped())
579 break;
580 f.limit(f.limit()+2);
581 }
582 bool ok = (b == nullptr) || b->best();
583 delete b;
584 return ok;
585 } else {
586 int n = ((t > 1) ? std::min(a,t) : a) * m->solutions();
587 delete m;
588 while (true) {
589 Model* s = pbs.next();
590 if (s != nullptr) {
591 n--; delete s;
592 }
593 if ((s == nullptr) && !pbs.stopped())
594 break;
595 f.limit(f.limit()+2);
596 }
597 return n >= 0;
598 }
599 }
600 };
601
603 template<class Model>
604 class SEBPBS : public Test {
605 private:
607 bool best;
609 unsigned int mt;
611 unsigned int st;
612 public:
614 SEBPBS(const std::string& e, bool b, unsigned int mt0, unsigned int st0)
615 : Test("PBS::SEB::"+e+"::"+Model::name()+"::"+str(mt0)+"::"+str(st0),
616 HTB_BINARY,HTB_BINARY,HTB_BINARY), best(b), mt(mt0), st(st0) {}
617
618 virtual bool run(void) {
619 using namespace Gecode;
620 Model* m = new Model(htb1,htb2,htb3);
622
624 mo.threads = mt;
625 mo.d_l = 100;
626 mo.stop = &f;
627
629 so.threads = st;
630 so.d_l = 100;
632 if (best) {
633 SEBs sebs(3);
634 sebs[0] = bab<Model>(so);
635 sebs[1] = bab<Model>(so);
636 sebs[2] = rbs<Model,Gecode::BAB>(so);
638 delete m;
639
640 Model* b = nullptr;
641 while (true) {
642 Model* s = pbs.next();
643 if (s != nullptr) {
644 delete b; b=s;
645 }
646 if ((s == nullptr) && !pbs.stopped())
647 break;
648 f.limit(f.limit()+2);
649 }
650 bool ok = (b == nullptr) || b->best();
651 delete b;
652 return ok;
653 } else {
654 SEBs sebs(3);
655 sebs[0] = dfs<Model>(so);
656 sebs[1] = lds<Model>(so);
657 sebs[2] = rbs<Model,Gecode::DFS>(so);
659
660 int n = 3 * m->solutions();
661 delete m;
662
663 while (true) {
664 Model* s = pbs.next();
665 if (s != nullptr) {
666 n--; delete s;
667 }
668 if ((s == nullptr) && !pbs.stopped())
669 break;
670 f.limit(f.limit()+2);
671 }
672 return n >= 0;
673 }
674 }
675 };
676
679 private:
681 static const HowToBranch htbs[3];
683 int i;
684 public:
686 BranchTypes(void) : i(0) {}
688 bool operator()(void) const {
689 return i<3;
690 }
691
692 void operator++(void) {
693 i++;
694 }
695
696 HowToBranch htb(void) const {
697 return htbs[i];
698 }
699 };
700
701 const HowToBranch BranchTypes::htbs[3] = {HTB_UNARY, HTB_BINARY, HTB_NARY};
702
705 private:
707 static const HowToConstrain htcs[4];
709 int i;
710 public:
712 ConstrainTypes(void) : i(0) {}
714 bool operator()(void) const {
715 return i<4;
716 }
717
718 void operator++(void) {
719 i++;
720 }
721
722 HowToConstrain htc(void) const {
723 return htcs[i];
724 }
725 };
726
727 const HowToConstrain ConstrainTypes::htcs[4] =
728 {HTC_LEX_LE, HTC_LEX_GR, HTC_BAL_LE, HTC_BAL_GR};
729
730
732 class Create {
733 public:
735 Create(void) {
736 // Depth-first search
737 for (unsigned int t = 1; t<=4; t++)
738 for (unsigned int c_d = 1; c_d<10; c_d++)
739 for (unsigned int a_d = 1; a_d<=c_d; a_d++) {
740 for (BranchTypes htb1; htb1(); ++htb1)
741 for (BranchTypes htb2; htb2(); ++htb2)
742 for (BranchTypes htb3; htb3(); ++htb3)
743 (void) new DFS<HasSolutions>
744 (htb1.htb(),htb2.htb(),htb3.htb(),c_d, a_d, t);
746 c_d, a_d, t);
748 c_d, a_d, t);
750 c_d, a_d, t);
751 }
752
753 // Limited discrepancy search
754 for (unsigned int t = 1; t<=4; t++) {
755 for (BranchTypes htb1; htb1(); ++htb1)
756 for (BranchTypes htb2; htb2(); ++htb2)
757 for (BranchTypes htb3; htb3(); ++htb3)
758 (void) new LDS<HasSolutions>(htb1.htb(),htb2.htb(),htb3.htb()
759 ,t);
762 }
763
764 // Best solution search
765 for (unsigned int t = 1; t<=4; t++)
766 for (unsigned int c_d = 1; c_d<10; c_d++)
767 for (unsigned int a_d = 1; a_d<=c_d; a_d++) {
768 for (ConstrainTypes htc; htc(); ++htc)
769 for (BranchTypes htb1; htb1(); ++htb1)
770 for (BranchTypes htb2; htb2(); ++htb2)
771 for (BranchTypes htb3; htb3(); ++htb3) {
772 (void) new BAB<HasSolutions>
773 (htc.htc(),htb1.htb(),htb2.htb(),htb3.htb(),
774 c_d,a_d,t);
775 }
776 (void) new BAB<FailImmediate>
778 (void) new BAB<SolveImmediate>
780 (void) new BAB<HasSolutions>
782 }
783 // Restart-based search
784 for (unsigned int t=1; t<=4; t++) {
785 (void) new RBS<HasSolutions,Gecode::DFS>("DFS",t);
786 (void) new RBS<HasSolutions,Gecode::LDS>("LDS",t);
787 (void) new RBS<HasSolutions,Gecode::BAB>("BAB",t);
788 (void) new RBS<FailImmediate,Gecode::DFS>("DFS",t);
789 (void) new RBS<FailImmediate,Gecode::LDS>("LDS",t);
790 (void) new RBS<FailImmediate,Gecode::BAB>("BAB",t);
791 (void) new RBS<SolveImmediate,Gecode::DFS>("DFS",t);
792 (void) new RBS<SolveImmediate,Gecode::LDS>("LDS",t);
793 (void) new RBS<SolveImmediate,Gecode::BAB>("BAB",t);
794 }
795 // Portfolio-based search
796 for (unsigned int a=1; a<=4; a++)
797 for (unsigned int t=1; t<=2*a; t++) {
798 (void) new PBS<HasSolutions,Gecode::DFS>("DFS",false,a,t);
799 (void) new PBS<HasSolutions,Gecode::LDS>("LDS",false,a,t);
800 (void) new PBS<HasSolutions,Gecode::BAB>("BAB",true,a,t);
801 (void) new PBS<FailImmediate,Gecode::DFS>("DFS",false,a,t);
802 (void) new PBS<FailImmediate,Gecode::LDS>("LDS",false,a,t);
803 (void) new PBS<FailImmediate,Gecode::BAB>("BAB",true,a,t);
804 (void) new PBS<SolveImmediate,Gecode::DFS>("DFS",false,a,t);
805 (void) new PBS<SolveImmediate,Gecode::LDS>("LDS",false,a,t);
806 (void) new PBS<SolveImmediate,Gecode::BAB>("BAB",true,a,t);
807 }
808 // Portfolio-based search using SEBs
809 for (unsigned int mt=1; mt<=3; mt += 2)
810 for (unsigned int st=1; st<=8; st++) {
811 (void) new SEBPBS<HasSolutions>("BAB",true,mt,st);
812 (void) new SEBPBS<FailImmediate>("BAB",true,mt,st);
813 (void) new SEBPBS<SolveImmediate>("BAB",true,mt,st);
814 (void) new SEBPBS<HasSolutions>("DFS+LDS",false,mt,st);
815 (void) new SEBPBS<FailImmediate>("DFS+LDS",false,mt,st);
816 (void) new SEBPBS<SolveImmediate>("DFS+LDS",false,mt,st);
817 }
818 }
819 };
820
822 }
823
824}
825
826// STATISTICS: test-search
Depth-first branch-and-bound search engine.
Definition search.hh:1114
Passing Boolean variables.
Definition int.hh:738
Depth-first search engine.
Definition search.hh:1080
Passing integer variables.
Definition int.hh:680
Integer variable array.
Definition int.hh:791
Integer variables.
Definition int.hh:389
Limited discrepancy search engine.
Definition search.hh:1152
Information passed by meta search engines.
Definition core.hpp:1628
@ PORTFOLIO
Information is provided by a portfolio-based engine.
Definition core.hpp:1635
@ RESTART
Information is provided by a restart-based engine.
Definition core.hpp:1633
const Space * last(void) const
Return last solution found (possibly nullptr).
Definition core.hpp:3183
Type type(void) const
Return type of information.
Definition core.hpp:3160
Meta engine using a portfolio of search engines.
Definition search.hh:1280
Meta-engine performing restart-based search.
Definition search.hh:1196
Passing search engine builder arguments.
Definition search.hh:1046
static Cutoff * constant(unsigned long long int scale=Config::slice)
Create generator for constant sequence with constant s.
Definition cutoff.cpp:148
static Cutoff * geometric(unsigned long long int scale=Config::slice, double base=Config::base)
Definition cutoff.cpp:160
Stop-object based on number of failures
Definition search.hh:863
Search engine options
Definition search.hh:751
unsigned int c_d
Create a clone after every c_d commits (commit distance).
Definition search.hh:758
unsigned int d_l
Discrepancy limit (for LDS).
Definition search.hh:762
Cutoff * cutoff
Cutoff for restart-based search.
Definition search.hh:772
unsigned int a_d
Create a clone during recomputation if distance is greater than a_d (adaptive distance).
Definition search.hh:760
Stop * stop
Stop object for stopping search.
Definition search.hh:770
unsigned int assets
Number of assets (engines) in a portfolio.
Definition search.hh:764
double threads
Number of threads to use.
Definition search.hh:756
Computation spaces.
Definition core.hpp:1775
Base(std::string s)
Create and register test with name s.
Definition test.cpp:60
const std::string & name(void) const
Return name of test.
Definition test.hpp:51
BAB(HowToConstrain htc, HowToBranch htb1, HowToBranch htb2, HowToBranch htb3, unsigned int c_d0, unsigned int a_d0, unsigned int t0)
Initialize test.
Definition search.cpp:476
virtual bool run(void)
Run test.
Definition search.cpp:484
Iterator for branching types.
Definition search.cpp:678
HowToBranch htb(void) const
Return current branching type.
Definition search.cpp:696
BranchTypes(void)
Initialize iterator.
Definition search.cpp:686
void operator++(void)
Increment to next branching type.
Definition search.cpp:692
bool operator()(void) const
Test whether iterator is done.
Definition search.cpp:688
Iterator for constrain types.
Definition search.cpp:704
HowToConstrain htc(void) const
Return current constrain type.
Definition search.cpp:722
void operator++(void)
Increment to next constrain type.
Definition search.cpp:718
bool operator()(void) const
Test whether iterator is done.
Definition search.cpp:714
ConstrainTypes(void)
Initialize iterator.
Definition search.cpp:712
Help class to create and register tests.
Definition search.cpp:732
Create(void)
Perform creation and registration.
Definition search.cpp:735
virtual bool run(void)
Run test.
Definition search.cpp:403
DFS(HowToBranch htb1, HowToBranch htb2, HowToBranch htb3, unsigned int c_d0, unsigned int a_d0, unsigned int t0)
Initialize test.
Definition search.cpp:396
virtual bool best(void) const
Verify that this is best solution.
Definition search.cpp:148
IntVarArray x
Variables used.
Definition search.cpp:125
FailImmediate(HowToBranch, HowToBranch, HowToBranch, HowToConstrain=HTC_NONE)
Constructor for space creation.
Definition search.cpp:127
FailImmediate(FailImmediate &s)
Constructor for cloning s.
Definition search.cpp:133
virtual Space * copy(void)
Copy during cloning.
Definition search.cpp:137
static std::string name(void)
Return name.
Definition search.cpp:152
virtual int solutions(void) const
Return number of solutions.
Definition search.cpp:144
virtual void constrain(const Space &)
Add constraint for next better solution.
Definition search.cpp:141
virtual int solutions(void) const
Return number of solutions.
Definition search.cpp:272
virtual Space * copy(void)
Copy during cloning.
Definition search.cpp:235
static std::string name(void)
Return name.
Definition search.cpp:312
virtual bool best(void) const
Verify that this is best solution.
Definition search.cpp:284
virtual void constrain(const Space &_s)
Add constraint for next better solution.
Definition search.cpp:239
virtual bool master(const MetaInfo &mi)
Rule out that solution is found more than once during restarts.
Definition search.cpp:316
HowToConstrain htc
How to constrain.
Definition search.cpp:200
HasSolutions(HasSolutions &s)
Constructor for cloning s.
Definition search.cpp:229
IntVarArray x
Variables used.
Definition search.cpp:196
HowToBranch htb1
How to branch.
Definition search.cpp:198
HasSolutions(HowToBranch _htb1, HowToBranch _htb2, HowToBranch _htb3, HowToConstrain _htc=HTC_NONE)
Constructor for space creation.
Definition search.cpp:218
void branch(const IntVarArgs &x, HowToBranch htb)
Branch on x according to htb.
Definition search.cpp:202
virtual bool run(void)
Run test.
Definition search.cpp:441
LDS(HowToBranch htb1, HowToBranch htb2, HowToBranch htb3, unsigned int t0)
Initialize test.
Definition search.cpp:435
PBS(const std::string &e, bool b, unsigned int a0, unsigned int t0)
Initialize test.
Definition search.cpp:558
virtual bool run(void)
Run test.
Definition search.cpp:562
RBS(const std::string &e, unsigned int t0)
Initialize test.
Definition search.cpp:518
virtual bool run(void)
Run test.
Definition search.cpp:522
Test for portfolio-based search using SEBs
Definition search.cpp:604
SEBPBS(const std::string &e, bool b, unsigned int mt0, unsigned int st0)
Initialize test.
Definition search.cpp:614
virtual bool run(void)
Run test.
Definition search.cpp:618
virtual int solutions(void) const
Return number of solutions.
Definition search.cpp:179
IntVarArray x
Variables used.
Definition search.cpp:161
virtual bool best(void) const
Verify that this is best solution.
Definition search.cpp:183
virtual Space * copy(void)
Copy during cloning.
Definition search.cpp:171
static std::string name(void)
Return name.
Definition search.cpp:187
SolveImmediate(SolveImmediate &s)
Constructor for cloning s.
Definition search.cpp:167
SolveImmediate(HowToBranch, HowToBranch, HowToBranch, HowToConstrain=HTC_NONE)
Constructor for space creation.
Definition search.cpp:163
virtual void constrain(const Space &)
Add constraint for next better solution.
Definition search.cpp:175
virtual int solutions(void) const =0
Return number of solutions.
virtual bool master(const MetaInfo &mi)
Master configuration function that does not restart.
Definition search.cpp:110
TestSpace(void)
Constructor for space creation.
Definition search.cpp:102
TestSpace(TestSpace &s)
Constructor for cloning s.
Definition search.cpp:104
virtual bool best(void) const =0
Verify that this is best solution.
static std::string str(unsigned int i)
Map unsigned integer to string.
Definition search.cpp:346
Test(const std::string &s, HowToBranch _htb1, HowToBranch _htb2, HowToBranch _htb3, HowToConstrain _htc=HTC_NONE)
Initialize test.
Definition search.cpp:377
HowToConstrain htc
How to constrain.
Definition search.cpp:344
static std::string str(HowToBranch htb)
Map branching to string.
Definition search.cpp:352
HowToBranch htb1
How to branch.
Definition search.cpp:342
static std::string str(HowToConstrain htc)
Map constrain to string.
Definition search.cpp:364
HowToBranch htb3
Definition search.cpp:342
HowToBranch htb2
Definition search.cpp:342
void fail(void)
Fail space.
Definition core.hpp:4167
void assign(Home home, const FloatVarArgs &x, FloatVarBranch vars, FloatAssign vals, FloatBranchFilter bf=nullptr, FloatVarValPrint vvp=nullptr)
Assign all x with variable selection vars and value selection vals.
Definition branch.cpp:111
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
@ IRT_EQ
Equality ( ).
Definition int.hh:960
@ IRT_LE
Less ( ).
Definition int.hh:963
@ IRT_GR
Greater ( ).
Definition int.hh:965
@ IRT_LQ
Less or equal ( ).
Definition int.hh:962
@ BOT_AND
Conjunction.
Definition int.hh:985
Space(void)
Default constructor.
Definition core.cpp:121
virtual void constrain(const Space &best)
Constrain function for best solution search.
Definition core.cpp:896
T * pbs(T *s, const Search::Options &o=Search::Options::def)
Run a portfolio of search engines.
Definition pbs.hpp:313
T * bab(T *s, const Search::Options &o=Search::Options::def)
Perform depth-first branch-and-bound search for subclass T of space s and options o.
Definition bab.hpp:77
T * lds(T *s, const Search::Options &o=Search::Options::def)
Invoke limited-discrepancy search for s as root node and optionso.
Definition lds.hpp:74
T * rbs(T *s, const Search::Options &o)
Perform restart-based search.
Definition rbs.hpp:111
Finite domain integers.
Definition lastval.hh:52
Search engines
Gecode toplevel namespace
void lex(Home home, const IntVarArgs &x, IntRelType r, const IntVarArgs &y, IntPropLevel ipl=IPL_DEF)
Post lexical order between x and y.
Definition aliases.hpp:132
IntVar expr(Home home, const LinIntExpr &e, const IntPropLevels &ipls=IntPropLevels::def)
Post linear expression and return its value.
Definition int-expr.cpp:988
void distinct(Home home, const IntVarArgs &x, IntPropLevel ipl=IPL_DEF)
Post propagator for for all .
Definition distinct.cpp:46
IntVarBranch INT_VAR_NONE(void)
Select first unassigned variable.
Definition var.hpp:96
void abs(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
IntValBranch INT_VALUES_MIN(void)
Try all values starting from smallest.
Definition val.hpp:100
IntValBranch INT_VAL_MIN(void)
Select smallest value.
Definition val.hpp:55
T * dfs(T *s, const Search::Options &o=Search::Options::def)
Invoke depth-first search engine for subclass T of space s with options o.
Definition dfs.hpp:73
IntAssign INT_ASSIGN_MIN(void)
Select smallest value.
Definition assign.hpp:55
HowToBranch
Values for selecting branchers.
Definition search.cpp:75
@ HTB_BINARY
Branch with two alternatives.
Definition search.cpp:78
@ HTB_NONE
Do not branch.
Definition search.cpp:76
@ HTB_UNARY
Branch with single alternative.
Definition search.cpp:77
@ HTB_NARY
Branch with many alternatives.
Definition search.cpp:79
HowToConstrain
Values for selecting how to constrain.
Definition search.cpp:83
@ HTC_BAL_GR
Constrain for largest balance.
Definition search.cpp:88
@ HTC_LEX_LE
Constrain for lexically smallest.
Definition search.cpp:85
@ HTC_LEX_GR
Constrain for lexically biggest.
Definition search.cpp:86
@ HTC_BAL_LE
Constrain for smallest balance.
Definition search.cpp:87
@ HTC_NONE
Do not constrain.
Definition search.cpp:84
WhichModel
Values for selecting models.
Definition search.cpp:92
@ WM_FAIL_SEARCH
Model without solutions.
Definition search.cpp:94
@ WM_SOLUTIONS
Model with solutions.
Definition search.cpp:95
@ WM_FAIL_IMMEDIATE
Model that fails immediately.
Definition search.cpp:93
General test support.
Definition afc.cpp:39
#define GECODE_NEVER
Assert that this command is never executed.
Definition macros.hpp:56