Generated on for Gecode by doxygen 1.17.0
search.hh
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 * Guido Tack <tack@gecode.dev>
6 *
7 * Contributing authors:
8 * Kevin Leo <kevin.leo@monash.edu>
9 * Mikael Zayenz Lagerkvist <lagerkvist@gecode.dev>
10 * Maxim Shishmarev <maxim.shishmarev@monash.edu>
11 *
12 * Copyright:
13 * Kevin Leo, 2017
14 * Christian Schulte, 2002
15 * Mikael Zayenz Lagerkvist, 2026
16 * Maxim Shishmarev, 2017
17 * Guido Tack, 2004
18 *
19 * This file is part of Gecode, the generic constraint
20 * development environment:
21 * http://www.gecode.dev
22 *
23 * Permission is hereby granted, free of charge, to any person obtaining
24 * a copy of this software and associated documentation files (the
25 * "Software"), to deal in the Software without restriction, including
26 * without limitation the rights to use, copy, modify, merge, publish,
27 * distribute, sublicense, and/or sell copies of the Software, and to
28 * permit persons to whom the Software is furnished to do so, subject to
29 * the following conditions:
30 *
31 * The above copyright notice and this permission notice shall be
32 * included in all copies or substantial portions of the Software.
33 *
34 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
35 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
36 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
37 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
38 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
39 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
40 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
41 *
42 */
43
44#ifndef GECODE_SEARCH_HH
45#define GECODE_SEARCH_HH
46
47#include <chrono>
48#include <initializer_list>
49#include <atomic>
50
51#include <gecode/kernel.hh>
52
53/*
54 * Configure linking
55 *
56 */
57#if !defined(GECODE_STATIC_LIBS) && \
58 (defined(__CYGWIN__) || defined(__MINGW32__) || defined(_MSC_VER))
59
60#ifdef GECODE_BUILD_SEARCH
61#define GECODE_SEARCH_EXPORT __declspec( dllexport )
62#else
63#define GECODE_SEARCH_EXPORT __declspec( dllimport )
64#endif
65
66#else
67
68#ifdef GECODE_GCC_HAS_CLASS_VISIBILITY
69#define GECODE_SEARCH_EXPORT __attribute__ ((visibility("default")))
70#else
71#define GECODE_SEARCH_EXPORT
72#endif
73
74#endif
75
76// Configure auto-linking
77#ifndef GECODE_BUILD_SEARCH
78#define GECODE_LIBRARY_NAME "Search"
80#endif
81
82
83namespace Gecode { namespace Search {
84
86 namespace Sequential {}
87
89 namespace Parallel {}
90
92 namespace Meta {}
93
94 namespace Meta {
95
97 namespace Sequential {}
98
100 namespace Parallel {}
101
102 }
103
104
110 namespace Config {
112 const bool clone = true;
114 const double threads = 1.0;
115
117 const unsigned int c_d = 8;
119 const unsigned int a_d = 2;
120
122 const unsigned int steal_limit = 3;
124 const unsigned int initial_delay = 5;
125
127 const unsigned int d_l = 5;
128
130 const double base = 1.5;
132 const unsigned int slice = 250;
133
135 const unsigned int nogoods_limit = 128;
136
138 const unsigned int cpprofiler_port = 6565U;
139 }
140
141}}
142
144
145namespace Gecode { namespace Search {
146
152 public:
154 unsigned long long int fail;
156 unsigned long long int node;
158 unsigned long int depth;
160 unsigned long int restart;
162 unsigned long int nogood;
164 Statistics(void);
166 void reset(void);
171 };
172
173}}
174
176
177namespace Gecode { namespace Search {
178
179 class WrapTraceRecorder;
180 class TraceRecorder;
181 class EdgeTraceRecorder;
182
183}}
184
185#include <string>
186#include <sstream>
187
188namespace Gecode {
189
195 public:
198 DFS = 0,
199 BAB = 1,
200 LDS = 2,
201 RBS = 3,
202 PBS = 4,
203 AOE = 5
204 };
205
207 protected:
211 unsigned int _fst;
213 unsigned int _lst;
214 public:
216 EngineInfo(void);
218 EngineInfo(EngineType et, unsigned int fst, unsigned int lst);
220
221
222 EngineType type(void) const;
224 bool meta(void) const;
226
228
229 unsigned int wfst(void) const;
231 unsigned int wlst(void) const;
233 unsigned int workers(void) const;
235
237
238 unsigned int efst(void) const;
240 unsigned int elst(void) const;
242 unsigned int engines(void) const;
244 };
245
246 class EdgeInfo {
247 protected:
249 unsigned int _wid;
251 unsigned int _nid;
253 unsigned int _a;
255 std::string _s;
256 public:
258 void init(unsigned int wid, unsigned int nid, unsigned int a);
260 void init(unsigned int wid, unsigned int nid, unsigned int a,
261 const Space& s, const Choice & c);
263 void invalidate(void);
265 EdgeInfo(void);
267 EdgeInfo(unsigned int wid, unsigned int nid, unsigned int a);
269 operator bool(void) const;
271 unsigned int wid(void) const;
273 unsigned int nid(void) const;
275 unsigned int alternative(void) const;
277 std::string string(void) const;
278 };
279
280 enum NodeType {
281 SOLVED = 0,
282 FAILED = 1,
284 };
285
286 class NodeInfo {
287 protected:
291 unsigned int _wid;
293 unsigned int _nid;
295 const Space& _s;
297 const Choice* _c;
298 public:
301 unsigned int wid, unsigned int nid,
302 const Space& s, const Choice* c = nullptr);
304 NodeType type(void) const;
306 unsigned int wid(void) const;
308 unsigned int nid(void) const;
310 const Space& space(void) const;
312 const Choice& choice(void) const;
313 };
314 private:
318 unsigned int pending;
320 unsigned int n_e;
322 unsigned int n_w;
324 unsigned int n_active;
330 void engine(EngineType t, unsigned int n);
332 void worker(unsigned int& wid, unsigned int& eid);
334 void worker(void);
336 //{@
338 void _round(unsigned int eid);
340 void _skip(const EdgeInfo& ei);
342 void _node(const EdgeInfo& ei, const NodeInfo& ni);
344 public:
346 SearchTracer(void);
348
349
350 unsigned int workers(void) const;
352 unsigned int engines(void) const;
354 const EngineInfo& engine(unsigned int eid) const;
356 unsigned int eid(unsigned int wid) const;
358
360
361 virtual void init(void) = 0;
363 virtual void round(unsigned int eid) = 0;
365 virtual void skip(const EdgeInfo& ei) = 0;
367 virtual void node(const EdgeInfo& ei, const NodeInfo& ni) = 0;
369 virtual void done(void) = 0;
371
372 virtual ~SearchTracer(void);
373 };
374
376 protected:
378 std::ostream& os;
380 static const char* t2s[EngineType::AOE + 1];
381 public:
383 StdSearchTracer(std::ostream& os = std::cerr);
385 virtual void init(void);
387 virtual void round(unsigned int eid);
389 virtual void skip(const EdgeInfo& ei);
391 virtual void node(const EdgeInfo& ei, const NodeInfo& ni);
393 virtual void done(void);
395 virtual ~StdSearchTracer(void);
398 };
399
400}
401
404
405#ifdef GECODE_HAS_CPPROFILER
406
407namespace Gecode {
408
410 namespace CPProfiler {}
411
412}
413
414namespace Gecode { namespace CPProfiler {
415
417 class Connector;
418
419}}
420
421namespace Gecode {
422
425 public:
428 public:
430 GetInfo(void);
432 virtual std::string getInfo(const Space& home) const = 0;
434 virtual ~GetInfo(void);
435 };
436 private:
438 CPProfiler::Connector* connector;
440 int execution_id;
442 std::string name;
444 int restart;
446 const GetInfo* pgi;
447 public:
449 CPProfilerSearchTracer(int eid, std::string name,
450 unsigned int port = Search::Config::cpprofiler_port,
451 const GetInfo* pgi = nullptr);
453 virtual void init(void);
455 virtual void round(unsigned int eid);
457 virtual void skip(const EdgeInfo& ei);
459 virtual void node(const EdgeInfo& ei, const NodeInfo& ni);
461 virtual void done(void);
464 };
465
466}
467
468#endif
469
470namespace Gecode { namespace Search {
471
477 public:
479
480
481 Cutoff(void);
483 virtual unsigned long long int operator ()(void) const = 0;
485 virtual unsigned long long int operator ++(void) = 0;
487 virtual ~Cutoff(void);
489
491
492 static Cutoff*
493 constant(unsigned long long int scale=Config::slice);
495 static Cutoff*
496 linear(unsigned long long int scale=Config::slice);
500 static Cutoff*
501 geometric(unsigned long long int scale=Config::slice,
502 double base=Config::base);
504 static Cutoff*
505 luby(unsigned long long int scale=Config::slice);
510 static Cutoff*
511 rnd(unsigned int seed,
512 unsigned long long int min, unsigned long long int max,
513 unsigned long long int n);
515 static Cutoff*
516 append(Cutoff* c1, unsigned long long int n, Cutoff* c2);
518 static Cutoff*
519 merge(Cutoff* c1, Cutoff* c2);
521 static Cutoff*
522 repeat(Cutoff* c, unsigned long long int n);
524 };
525
531 protected:
533 unsigned long long int c;
534 public:
536 CutoffConstant(unsigned long long int c);
538 virtual unsigned long long int operator ()(void) const;
540 virtual unsigned long long int operator ++(void);
541 };
542
548 protected:
550 unsigned long long int scale;
552 unsigned long long int n;
553 public:
555 CutoffLinear(unsigned long long int scale);
557 virtual unsigned long long int operator ()(void) const;
559 virtual unsigned long long int operator ++(void);
560 };
561
567 protected:
569 unsigned long long int i;
571 unsigned long long int scale;
573 static const unsigned long long int n_start = 63U;
575 static unsigned long int start[n_start];
577 static unsigned long long int log(unsigned long long int i);
579 static unsigned long long int luby(unsigned long long int i);
580 public:
582 CutoffLuby(unsigned long long int scale);
584 virtual unsigned long long int operator ()(void) const;
586 virtual unsigned long long int operator ++(void);
587 };
588
594 protected:
596 double n;
598 double scale;
600 double base;
601 public:
603 CutoffGeometric(unsigned long long int scale, double base);
605 virtual unsigned long long int operator ()(void) const;
607 virtual unsigned long long int operator ++(void);
608 };
609
615 protected:
619 unsigned long long int min;
621 unsigned long long int n;
623 unsigned long long int step;
625 unsigned long long int cur;
626 public:
628 CutoffRandom(unsigned int seed,
629 unsigned long long int min, unsigned long long int max,
630 unsigned long long int n);
632 virtual unsigned long long int operator ()(void) const;
634 virtual unsigned long long int operator ++(void);
635 };
636
642 protected:
648 unsigned long long int n;
649 public:
651 CutoffAppend(Cutoff* c1, unsigned long long int n, Cutoff* c2);
653 virtual unsigned long long int operator ()(void) const;
655 virtual unsigned long long int operator ++(void);
657 virtual ~CutoffAppend(void);
658 };
659
665 protected:
670 public:
674 virtual unsigned long long int operator ()(void) const;
676 virtual unsigned long long int operator ++(void);
678 virtual ~CutoffMerge(void);
679 };
680
686 protected:
689 // Current cutoff
690 unsigned long long int cutoff;
691 // Iteration
692 unsigned long long int i;
693 // Number of repetitions
694 unsigned long long int n;
695 public:
697 CutoffRepeat(Cutoff* c, unsigned long long int n);
699 virtual unsigned long long int operator ()(void) const;
701 virtual unsigned long long int operator ++(void);
703 virtual ~CutoffRepeat(void);
704 };
705
706}}
707
709
710namespace Gecode { namespace Search {
711
712 class Stop;
713
751 class Options {
752 public:
754 bool clone;
756 double threads;
758 unsigned int c_d;
760 unsigned int a_d;
762 unsigned int d_l;
764 unsigned int assets;
766 unsigned int slice;
768 unsigned int nogoods_limit;
778 Options(void);
781 expand(void) const;
782 };
783
784}}
785
787
788namespace Gecode { namespace Search {
789
799
805 public:
807
808
809 Stop(void);
811 virtual bool stop(const Statistics& s, const Options& o) = 0;
813 virtual ~Stop(void);
815
817
818 static Stop* node(unsigned long long int l);
820 static Stop* fail(unsigned long long int l);
822 static Stop* time(double l);
824 static Stop* restart(unsigned long long int l);
826 };
827
837 protected:
839 std::atomic<unsigned long long int> l;
840 public:
842 NodeStop(unsigned long long int l);
844 NodeStop(const NodeStop& s);
846 NodeStop& operator =(const NodeStop& s);
848 unsigned long long int limit(void) const;
850 void limit(unsigned long long int l);
852 virtual bool stop(const Statistics& s, const Options& o);
853 };
854
864 protected:
866 std::atomic<unsigned long long int> l;
867 public:
869 FailStop(unsigned long long int l);
871 FailStop(const FailStop& s);
873 FailStop& operator =(const FailStop& s);
875 unsigned long long int limit(void) const;
877 void limit(unsigned long long int l);
879 virtual bool stop(const Statistics& s, const Options& o);
880 };
881
887 protected:
888 using clock = std::chrono::steady_clock;
889 using clock_rep = clock::time_point::rep;
891 std::atomic<clock_rep> t0;
893 std::atomic<double> l;
894 public:
896 TimeStop(double l);
898 TimeStop(const TimeStop& s);
900 TimeStop& operator =(const TimeStop& s);
902 double limit(void) const;
904 void limit(double l);
906 void reset(void);
908 virtual bool stop(const Statistics& s, const Options& o);
909 };
910
916 protected:
918 std::atomic<unsigned long long int> l;
919 public:
921 RestartStop(unsigned long long int l);
923 RestartStop(const RestartStop& s);
925 RestartStop& operator =(const RestartStop& s);
927 unsigned long long int limit(void) const;
929 void limit(unsigned long long int l);
931 virtual bool stop(const Statistics& s, const Options& o);
932 };
933
934}}
935
936#include <gecode/search/stop.hpp>
937
938namespace Gecode { namespace Search {
939
944 public:
946 virtual Space* next(void) = 0;
948 virtual Statistics statistics(void) const = 0;
950 virtual bool stopped(void) const = 0;
952 virtual void constrain(const Space& b);
954 virtual void reset(Space* s);
956 virtual NoGoods& nogoods(void);
958 virtual ~Engine(void);
959 };
960
961}}
962
964
965namespace Gecode { namespace Search {
966
968 template<class T>
969 class Base : public HeapAllocated {
970 template<class, class>
971 friend Engine* build(Space*, const Options&);
972 template<class, template<class> class>
973 friend Engine* build(Space*, const Options&);
974 protected:
978 Base(Engine* e = nullptr);
979 public:
981 virtual T* next(void);
983 virtual Statistics statistics(void) const;
985 virtual bool stopped(void) const;
987 virtual ~Base(void);
988 private:
990 Base(const Base&);
992 Base& operator =(const Base&);
993 };
994
995}}
996
997#include <gecode/search/base.hpp>
998
999namespace Gecode { namespace Search {
1000
1002 template<class T, class E>
1003 Engine* build(Space* s, const Options& opt);
1005 template<class T, template<class> class E>
1006 Engine* build(Space* s, const Options& opt);
1007
1010 protected:
1014 const bool b;
1015 public:
1017 Builder(const Options& opt, bool best);
1019 Options& options(void);
1021 const Options& options(void) const;
1023 bool best(void) const;
1025 virtual Engine* operator() (Space* s) const = 0;
1027 virtual ~Builder(void);
1028 };
1029
1030}}
1031
1032#include <gecode/search/build.hpp>
1033
1034namespace Gecode {
1035
1038
1039}
1040
1041#include <gecode/search/traits.hpp>
1042
1043namespace Gecode {
1044
1046 class SEBs : public ArgArray<SEB> {
1047 public:
1049
1050
1051 SEBs(void);
1053 explicit SEBs(int n);
1055 SEBs(const std::vector<SEB>& x);
1057 SEBs(std::initializer_list<SEB> x);
1059 template<class InputIterator>
1060 SEBs(InputIterator first, InputIterator last);
1062 SEBs(const ArgArray<SEB>& a);
1064 };
1065
1066}
1067
1068#include <gecode/search/sebs.hpp>
1069
1070namespace Gecode {
1071
1079 template<class T>
1080 class DFS : public Search::Base<T> {
1081 public:
1085 static const bool best = false;
1086 };
1087
1089 template<class T>
1090 T* dfs(T* s, const Search::Options& o=Search::Options::def);
1091
1093 template<class T>
1095
1096}
1097
1098#include <gecode/search/dfs.hpp>
1099
1100namespace Gecode {
1101
1113 template<class T>
1114 class BAB : public Search::Base<T> {
1115 public:
1119 static const bool best = true;
1120 };
1121
1134 template<class T>
1135 T* bab(T* s, const Search::Options& o=Search::Options::def);
1136
1138 template<class T>
1140
1141}
1142
1143#include <gecode/search/bab.hpp>
1144
1145namespace Gecode {
1146
1151 template<class T>
1152 class LDS : public Search::Base<T> {
1153 public:
1157 static const bool best = false;
1158 };
1159
1164 template<class T>
1165 T* lds(T* s, const Search::Options& o=Search::Options::def);
1166
1168 template<class T>
1170
1171}
1172
1173#include <gecode/search/lds.hpp>
1174
1175namespace Gecode {
1176
1195 template<class T, template<class> class E = DFS>
1196 class RBS : public Search::Base<T> {
1197 using Search::Base<T>::e;
1198 public:
1200 RBS(T* s, const Search::Options& o);
1202 static const bool best = E<T>::best;
1203 };
1204
1223 template<class T, template<class> class E>
1224 T* rbs(T* s, const Search::Options& o);
1225
1227 template<class T, template<class> class E>
1228 SEB rbs(const Search::Options& o);
1229
1230}
1231
1232#include <gecode/search/rbs.hpp>
1233
1234namespace Gecode { namespace Search { namespace Meta {
1235
1237 template<class T, template<class> class E>
1238 Engine* sequential(T* master, const Search::Statistics& stat, Options& opt);
1239
1241 template<class T, template<class> class E>
1242 Engine* sequential(T* master, SEBs& sebs,
1243 const Search::Statistics& stat, Options& opt, bool best);
1244
1245#ifdef GECODE_HAS_THREADS
1246
1248 template<class T, template<class> class E>
1249 Engine* parallel(T* master, const Search::Statistics& stat, Options& opt);
1250
1252 template<class T, template<class> class E>
1253 Engine* parallel(T* master, SEBs& sebs,
1254 const Search::Statistics& stat, Options& opt, bool best);
1255
1256#endif
1257
1258}}}
1259
1260namespace Gecode {
1261
1279 template<class T, template<class> class E = DFS>
1280 class PBS : public Search::Base<T> {
1281 using Search::Base<T>::e;
1282 protected:
1284 void build(T* s, SEBs& sebs, const Search::Options& o);
1285 public:
1289 PBS(T* s, SEBs& sebs, const Search::Options& o=Search::Options::def);
1291 static const bool best = E<T>::best;
1292 };
1293
1311 template<class T, template<class> class E>
1312 T* pbs(T* s, const Search::Options& o=Search::Options::def);
1313
1315 template<class T>
1317
1318}
1319
1320#include <gecode/search/pbs.hpp>
1321
1322#endif
1323
1324// STATISTICS: search-other
BAB(T *s, const Search::Options &o=Search::Options::def)
Initialize engine for space s and options o.
Definition bab.hpp:72
static const bool best
Whether engine does best solution search.
Definition search.hh:1119
Class to send solution information to CPProfiler.
Definition search.hh:427
virtual std::string getInfo(const Space &home) const =0
Return info for a space.
virtual void done(void)
All workers are done.
virtual ~CPProfilerSearchTracer(void)
Delete.
virtual void round(unsigned int eid)
The engine with id eid goes to a next round (restart or next iteration in LDS).
virtual void skip(const EdgeInfo &ei)
The engine skips an edge.
virtual void node(const EdgeInfo &ei, const NodeInfo &ni)
The engine creates a new node with information ei and ni.
virtual void init(void)
The search engine initializes.
CPProfilerSearchTracer(int eid, std::string name, unsigned int port=Search::Config::cpprofiler_port, const GetInfo *pgi=nullptr)
Initialize.
Choice for performing commit
Definition core.hpp:1423
DFS(T *s, const Search::Options &o=Search::Options::def)
Initialize search engine for space s with options o.
Definition dfs.hpp:68
static const bool best
Whether engine does best solution search.
Definition search.hh:1085
Base class for heap allocated objects.
Definition heap.hpp:344
static const bool best
Whether engine does best solution search.
Definition search.hh:1157
LDS(T *s, const Search::Options &o=Search::Options::def)
Initialize engine for space s and options o.
Definition lds.hpp:69
No-goods recorded from restarts.
Definition core.hpp:1599
void build(T *s, SEBs &sebs, const Search::Options &o)
The actual build function.
Definition pbs.hpp:266
PBS(T *s, const Search::Options &o=Search::Options::def)
Initialize with engines running copies of s with options o.
Definition pbs.hpp:225
static const bool best
Whether engine does best solution search.
Definition search.hh:1291
static const bool best
Whether engine does best solution search.
Definition search.hh:1202
RBS(T *s, const Search::Options &o)
Initialize engine for space s and options o.
Definition rbs.hpp:83
Passing search engine builder arguments.
Definition search.hh:1046
SEBs(void)
Allocate empty array.
Definition sebs.hpp:37
void invalidate(void)
Invalidate edge information (for stealing).
Definition tracer.hpp:102
unsigned int alternative(void) const
Return number of alternative.
Definition tracer.hpp:148
unsigned int _a
Number of alternative.
Definition search.hh:253
unsigned int _nid
The parent node id.
Definition search.hh:251
unsigned int wid(void) const
Return parent worker id.
Definition tracer.hpp:136
std::string string(void) const
Return string for alternative.
Definition tracer.hpp:154
unsigned int nid(void) const
Return parent node id.
Definition tracer.hpp:142
EdgeInfo(void)
Initialize as non existing.
Definition tracer.hpp:127
unsigned int _wid
The parent worker id (edge does not exist if UINT_MAX).
Definition search.hh:249
std::string _s
String corresponding to alternative.
Definition search.hh:255
Information about an engine.
Definition search.hh:206
bool meta(void) const
Return whether engine is a meta engine.
Definition tracer.hpp:56
unsigned int wfst(void) const
Return id of first worker.
Definition tracer.hpp:61
unsigned int _lst
Last worker or engine.
Definition search.hh:213
EngineInfo(void)
Do not initialize.
Definition tracer.hpp:43
unsigned int workers(void) const
Return number of workers.
Definition tracer.hpp:75
EngineType _type
The engine type.
Definition search.hh:209
EngineType type(void) const
Return engine type.
Definition tracer.hpp:51
unsigned int efst(void) const
Return id of first engine.
Definition tracer.hpp:80
unsigned int engines(void) const
Return number of engines.
Definition tracer.hpp:92
unsigned int _fst
First worker or engine.
Definition search.hh:211
unsigned int elst(void) const
Return id of last engine.
Definition tracer.hpp:86
unsigned int wlst(void) const
Return id of last worker plus one.
Definition tracer.hpp:68
unsigned int _wid
The worker id.
Definition search.hh:291
const Choice * _c
The corresponding choice (nullptr if type is not BRANCH).
Definition search.hh:297
NodeType _nt
The node type.
Definition search.hh:289
NodeType type(void) const
Return node type.
Definition tracer.hpp:171
const Choice & choice(void) const
Return corresponding choice.
Definition tracer.hpp:191
unsigned int nid(void) const
Return node id.
Definition tracer.hpp:181
unsigned int wid(void) const
Return worker id.
Definition tracer.hpp:176
const Space & space(void) const
Return corresponding space.
Definition tracer.hpp:186
unsigned int _nid
The node id.
Definition search.hh:293
const Space & _s
The corresponding space.
Definition search.hh:295
NodeInfo(NodeType nt, unsigned int wid, unsigned int nid, const Space &s, const Choice *c=nullptr)
Initialize node info.
Definition tracer.hpp:165
Support for tracing search.
Definition search.hh:191
unsigned int eid(unsigned int wid) const
Return the engine id of a worker with id wid.
Definition tracer.hpp:278
NodeType
Node type.
Definition search.hh:280
@ FAILED
A solution node.
Definition search.hh:282
@ BRANCH
A failed node.
Definition search.hh:283
virtual void init(void)=0
The search engine initializes.
EngineType
Which type of engine.
Definition search.hh:197
@ BAB
Engine is a BAB engine.
Definition search.hh:199
@ DFS
Engine is a DFS engine.
Definition search.hh:198
@ AOE
Unspecified engine (any other engine).
Definition search.hh:203
@ PBS
Engine is a PBS engine.
Definition search.hh:202
@ RBS
Engine is a RBS engine.
Definition search.hh:201
@ LDS
Engine is a LDS engine.
Definition search.hh:200
unsigned int engines(void) const
Return number of engines.
Definition tracer.hpp:266
virtual ~SearchTracer(void)
Delete.
Definition tracer.hpp:284
virtual void node(const EdgeInfo &ei, const NodeInfo &ni)=0
The engine creates a new node with information ei and ni.
virtual void round(unsigned int eid)=0
The engine with id eid goes to a next round (restart or next iteration in LDS).
unsigned int workers(void) const
Return number of workers.
Definition tracer.hpp:261
virtual void skip(const EdgeInfo &ei)=0
The engine skips an edge.
SearchTracer(void)
Initialize.
Definition tracer.hpp:220
virtual void done(void)=0
All workers are done.
Base-class for search engines.
Definition search.hh:969
virtual bool stopped(void) const
Check whether engine has been stopped.
Definition base.hpp:56
virtual T * next(void)
Return next solution (nullptr, if none exists or search has been stopped).
Definition base.hpp:46
virtual Statistics statistics(void) const
Return statistics.
Definition base.hpp:51
virtual ~Base(void)
Destructor.
Definition base.hpp:61
friend Engine * build(Space *, const Options &)
Build an engine of type E for a script T.
Definition build.hpp:58
Base(Engine *e=nullptr)
Constructor.
Definition base.hpp:42
Engine * e
The actual search engine.
Definition search.hh:976
A class for building search engines.
Definition search.hh:1009
const bool b
Whether engine to be built is a best solution search engine.
Definition search.hh:1014
Options opt
Stored and already expanded options.
Definition search.hh:1012
Builder(const Options &opt, bool best)
Initialize with options opt and best solution search support.
Definition build.hpp:37
bool best(void) const
Whether engine is a best solution search engine.
Definition build.hpp:48
Options & options(void)
Provide access to options.
Definition build.hpp:40
unsigned long long int n
How many number to take from the first.
Definition search.hh:648
CutoffAppend(Cutoff *c1, unsigned long long int n, Cutoff *c2)
Constructor.
Definition cutoff.hpp:100
Cutoff * c1
First cutoff generators.
Definition search.hh:644
Cutoff * c2
Second cutoff generators.
Definition search.hh:646
CutoffConstant(unsigned long long int c)
Constructor.
Definition cutoff.hpp:47
unsigned long long int c
Constant.
Definition search.hh:533
double n
Current cutoff value.
Definition search.hh:596
CutoffGeometric(unsigned long long int scale, double base)
Constructor.
Definition cutoff.hpp:83
double scale
Scale factor.
Definition search.hh:598
unsigned long long int n
Next number in sequence.
Definition search.hh:552
CutoffLinear(unsigned long long int scale)
Constructor.
Definition cutoff.hpp:52
unsigned long long int scale
Scale factor.
Definition search.hh:550
static const unsigned long long int n_start
Number of pre-computed luby values.
Definition search.hh:573
unsigned long long int i
Iteration number.
Definition search.hh:569
static unsigned long long int log(unsigned long long int i)
Compute binary logarithm of i.
Definition cutoff.hpp:60
CutoffLuby(unsigned long long int scale)
Constructor.
Definition cutoff.hpp:57
static unsigned long int start[n_start]
Precomputed luby-values.
Definition search.hh:575
unsigned long long int scale
Scale factor.
Definition search.hh:571
static unsigned long long int luby(unsigned long long int i)
Compute Luby number for step i.
Definition cutoff.hpp:68
Cutoff * c1
First cutoff generator.
Definition search.hh:667
Cutoff * c2
Second cutoff generator.
Definition search.hh:669
CutoffMerge(Cutoff *c1, Cutoff *c2)
Constructor.
Definition cutoff.hpp:109
CutoffRandom(unsigned int seed, unsigned long long int min, unsigned long long int max, unsigned long long int n)
Constructor.
Definition cutoff.hpp:88
unsigned long long int n
Random values.
Definition search.hh:621
unsigned long long int step
Step size.
Definition search.hh:623
unsigned long long int cur
Current value.
Definition search.hh:625
unsigned long long int min
Minimum cutoff value.
Definition search.hh:619
Support::RandomGenerator rnd
Random number generator.
Definition search.hh:617
Cutoff * c
Actual cutoff generator.
Definition search.hh:688
unsigned long long int n
Definition search.hh:694
unsigned long long int cutoff
Definition search.hh:690
CutoffRepeat(Cutoff *c, unsigned long long int n)
Constructor.
Definition cutoff.hpp:118
unsigned long long int i
Definition search.hh:692
Base class for cutoff generators for restart-based meta engine.
Definition search.hh:476
static Cutoff * linear(unsigned long long int scale=Config::slice)
Create generator for linear sequence scaled by scale.
static Cutoff * append(Cutoff *c1, unsigned long long int n, Cutoff *c2)
Append cutoff values from c2 after n values from c1.
static Cutoff * rnd(unsigned int seed, unsigned long long int min, unsigned long long int max, unsigned long long int n)
Cutoff(void)
Default constructor.
Definition cutoff.hpp:41
static Cutoff * repeat(Cutoff *c, unsigned long long int n)
Create generator that repeats n times each cutoff value from c.
static Cutoff * merge(Cutoff *c1, Cutoff *c2)
Merge cutoff values from c1 with values from c2.
static Cutoff * constant(unsigned long long int scale=Config::slice)
Create generator for constant sequence with constant s.
static Cutoff * luby(unsigned long long int scale=Config::slice)
Create generator for luby sequence with scale-factor scale.
static Cutoff * geometric(unsigned long long int scale=Config::slice, double base=Config::base)
Recorder for a search tracer with edge information.
Search engine implementation interface
Definition search.hh:943
virtual void constrain(const Space &b)
Constrain future solutions to be better than b (raises exception).
virtual Statistics statistics(void) const =0
Return statistics.
virtual Space * next(void)=0
Return next solution (nullptr, if none exists or search has been stopped).
virtual void reset(Space *s)
Reset engine to restart at space s (does nothing).
virtual bool stopped(void) const =0
Check whether engine has been stopped.
virtual NoGoods & nogoods(void)
Return no-goods (the no-goods are empty).
std::atomic< unsigned long long int > l
Failure limit.
Definition search.hh:866
virtual bool stop(const Statistics &s, const Options &o)
Return true if failure limit is exceeded.
FailStop(unsigned long long int l)
Stop if failure limit l is exceeded.
Definition stop.hpp:83
unsigned long long int limit(void) const
Return current limit.
Definition stop.hpp:94
NodeStop(unsigned long long int l)
Stop if node limit l is exceeded.
Definition stop.hpp:56
unsigned long long int limit(void) const
Return current limit.
Definition stop.hpp:67
virtual bool stop(const Statistics &s, const Options &o)
Return true if node limit is exceeded.
std::atomic< unsigned long long int > l
Node limit.
Definition search.hh:839
Search engine options
Definition search.hh:751
static const Options def
Default options.
Definition search.hh:776
unsigned int c_d
Create a clone after every c_d commits (commit distance).
Definition search.hh:758
bool clone
Whether engines create a clone when being initialized.
Definition search.hh:754
Options(void)
Initialize with default values.
Definition options.hpp:37
unsigned int d_l
Discrepancy limit (for LDS).
Definition search.hh:762
Cutoff * cutoff
Cutoff for restart-based search.
Definition search.hh:772
Options expand(void) const
Expand with real number of threads.
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
SearchTracer * tracer
Tracer object for tracing search.
Definition search.hh:774
unsigned int assets
Number of assets (engines) in a portfolio.
Definition search.hh:764
unsigned int slice
Size of a slice in a portfolio (in number of failures).
Definition search.hh:766
unsigned int nogoods_limit
Depth limit for extraction of no-goods.
Definition search.hh:768
double threads
Number of threads to use.
Definition search.hh:756
std::atomic< unsigned long long int > l
Restart limit.
Definition search.hh:918
virtual bool stop(const Statistics &s, const Options &o)
Return true if failure limit is exceeded.
RestartStop(unsigned long long int l)
Stop if restart limit l is exceeded.
Definition stop.hpp:149
unsigned long long int limit(void) const
Return current limit.
Definition stop.hpp:160
Search engine statistics
Definition search.hh:151
Statistics(void)
Initialize.
unsigned long int restart
Number of restarts.
Definition search.hh:160
Statistics & operator+=(const Statistics &s)
Increment by statistics s.
unsigned long int depth
Maximum depth of search stack.
Definition search.hh:158
unsigned long long int fail
Number of failed nodes in search tree.
Definition search.hh:154
unsigned long long int node
Number of nodes expanded.
Definition search.hh:156
Statistics operator+(const Statistics &s)
Return sum with s.
unsigned long int nogood
Number of no-goods posted.
Definition search.hh:162
Base-class for Stop-object.
Definition search.hh:804
static Stop * node(unsigned long long int l)
Stop if node limit l has been exceeded.
Stop(void)
Default constructor.
Definition stop.hpp:45
virtual bool stop(const Statistics &s, const Options &o)=0
Stop search, if returns true.
static Stop * time(double l)
Stop if time limit l (in milliseconds) has been exceeded.
static Stop * fail(unsigned long long int l)
Stop if failure limit l has been exceeded.
static Stop * restart(unsigned long long int l)
Stop if restart limit l has been exceeded.
clock::time_point::rep clock_rep
Definition search.hh:889
virtual bool stop(const Statistics &s, const Options &o)
Return true if time limit is exceeded.
std::chrono::steady_clock clock
Definition search.hh:888
TimeStop(double l)
Stop if search exceeds l milliseconds (from creation of this object).
Definition stop.hpp:110
double limit(void) const
Return current limit in milliseconds.
Definition stop.hpp:128
std::atomic< double > l
Current limit in milliseconds.
Definition search.hh:893
std::atomic< clock_rep > t0
Clock representation at the start of timing.
Definition search.hh:891
void reset(void)
Reset time to zero.
Definition stop.hpp:138
Simple recorder for a search tracer.
Recorder for engine events (for access control).
Computation spaces.
Definition core.hpp:1775
StatusStatistics(void)
Initialize.
Definition core.hpp:4870
virtual void init(void)
The search engine initializes.
StdSearchTracer(std::ostream &os=std::cerr)
Initialize with output stream os.
virtual ~StdSearchTracer(void)
Delete.
virtual void round(unsigned int eid)
The engine with id eid goes to a next round (restart or next iteration in LDS).
virtual void done(void)
All workers are done.
static StdSearchTracer def
Default tracer (printing to std::cerr).
Definition search.hh:397
static const char * t2s[EngineType::AOE+1]
Map engine type to string.
Definition search.hh:380
virtual void node(const EdgeInfo &ei, const NodeInfo &ni)
The engine creates a new node with information ei and ni.
virtual void skip(const EdgeInfo &ei)
The engine skips an edge.
std::ostream & os
Output stream to use.
Definition search.hh:378
Array with arbitrary number of elements.
A mutex for mutual exclausion among several threads.
Definition thread.hpp:78
LinearCongruentialGenerator< 2147483647, 48271, 44488, 3399 > RandomGenerator
Default values for linear congruential generator.
Definition random.hpp:183
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
Code that is specific to the CPProfiler.
Definition search.hh:410
Search configuration
Definition search.hh:110
const unsigned int initial_delay
Initial delay in milliseconds for all but first worker thread.
Definition search.hh:124
const unsigned int d_l
Default discrepancy limit for LDS.
Definition search.hh:127
const unsigned int a_d
Create a clone during recomputation if distance is greater than a_d (adaptive distance).
Definition search.hh:119
const double base
Base for geometric restart sequence.
Definition search.hh:130
const unsigned int c_d
Create a clone after every c_d commits (commit distance).
Definition search.hh:117
const unsigned int slice
Size of a slice in a portfolio and scale factor for restarts(in number of failures).
Definition search.hh:132
const unsigned int cpprofiler_port
Default port for CPProfiler.
Definition search.hh:138
const unsigned int nogoods_limit
Depth limit for no-good generation during search.
Definition search.hh:135
const unsigned int steal_limit
Minimal number of open nodes for stealing.
Definition search.hh:122
const double threads
Number of threads to use.
Definition search.hh:114
const bool clone
Whether engines create a clone when being initialized.
Definition search.hh:112
Parallel meta search engine implementations
Definition search.hh:100
Sequential meta search engine implementations
Definition search.hh:97
Meta search engine implementations
Definition search.hh:92
Engine * sequential(T *master, const Search::Statistics &stat, Options &opt)
Build a sequential engine.
Engine * parallel(T *master, const Search::Statistics &stat, Options &opt)
Build a parallel engine.
Parallel search engine implementations
Definition search.hh:89
Sequential search engine implementations
Definition search.hh:86
Engine * build(Space *s, const Options &opt)
Build an engine of type E for a script T.
Definition build.hpp:58
Gecode toplevel namespace
Search::Builder * SEB
Type for a search engine builder.
Definition search.hh:1037
void min(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
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
void max(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
#define GECODE_SEARCH_EXPORT
Definition search.hh:71