search.hh
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #ifndef __GECODE_SEARCH_HH__
00041 #define __GECODE_SEARCH_HH__
00042
00043 #include <gecode/kernel.hh>
00044
00045
00046
00047
00048
00049 #if !defined(GECODE_STATIC_LIBS) && \
00050 (defined(__CYGWIN__) || defined(__MINGW32__) || defined(_MSC_VER))
00051
00052 #ifdef GECODE_BUILD_SEARCH
00053 #define GECODE_SEARCH_EXPORT __declspec( dllexport )
00054 #else
00055 #define GECODE_SEARCH_EXPORT __declspec( dllimport )
00056 #endif
00057
00058 #else
00059
00060 #ifdef GECODE_GCC_HAS_CLASS_VISIBILITY
00061 #define GECODE_SEARCH_EXPORT __attribute__ ((visibility("default")))
00062 #else
00063 #define GECODE_SEARCH_EXPORT
00064 #endif
00065
00066 #endif
00067
00068
00069 #ifndef GECODE_BUILD_SEARCH
00070 #define GECODE_LIBRARY_NAME "Search"
00071 #include <gecode/support/auto-link.hpp>
00072 #endif
00073
00074
00075 namespace Gecode { namespace Search {
00076
00078 namespace Sequential {}
00079
00081 namespace Parallel {}
00082
00084 namespace Meta {}
00085
00091 namespace Config {
00093 const bool clone = true;
00095 const double threads = 1.0;
00097 const unsigned int c_d = 8;
00099 const unsigned int a_d = 2;
00100
00102 const unsigned int steal_limit = 3;
00104 const unsigned int initial_delay = 5;
00105
00107 const unsigned int nogoods_limit = 128;
00108 }
00109
00110 }}
00111
00112 namespace Gecode { namespace Search {
00113
00119
00120 class GECODE_VTABLE_EXPORT UninitializedCutoff : public Exception {
00121 public:
00123 UninitializedCutoff(const char* l);
00124 };
00126 }}
00127
00128 #include <gecode/search/exception.hpp>
00129
00130 namespace Gecode { namespace Search {
00131
00136 class Statistics : public StatusStatistics {
00137 public:
00139 unsigned long int fail;
00141 unsigned long int node;
00143 unsigned long int depth;
00145 unsigned long int restart;
00147 unsigned long int nogood;
00149 Statistics(void);
00151 void reset(void);
00153 Statistics operator +(const Statistics& s);
00155 Statistics& operator +=(const Statistics& s);
00156 };
00157
00158 }}
00159
00160 #include <gecode/search/statistics.hpp>
00161
00162 namespace Gecode { namespace Search {
00163
00168 class GECODE_SEARCH_EXPORT Cutoff {
00169 public:
00171
00172
00173 Cutoff(void);
00175 virtual unsigned long int operator ()(void) const = 0;
00177 virtual unsigned long int operator ++(void) = 0;
00179 virtual ~Cutoff(void);
00181
00182
00183
00184 static void* operator new(size_t s);
00186 static void operator delete(void* p);
00188
00189
00190
00191 static Cutoff*
00192 constant(unsigned long int scale=1U);
00194 static Cutoff*
00195 linear(unsigned long int scale=1U);
00199 static Cutoff*
00200 geometric(unsigned long int scale=1U, double base=1.5);
00202 static Cutoff*
00203 luby(unsigned long int scale=1U);
00208 static Cutoff*
00209 rnd(unsigned int seed,
00210 unsigned long int min, unsigned long int max,
00211 unsigned long int n);
00213 static Cutoff*
00214 append(Cutoff* c1, unsigned long int n, Cutoff* c2);
00216 static Cutoff*
00217 merge(Cutoff* c1, Cutoff* c2);
00219 static Cutoff*
00220 repeat(Cutoff* c, unsigned long int n);
00222 };
00223
00228 class GECODE_SEARCH_EXPORT CutoffConstant : public Cutoff {
00229 protected:
00231 unsigned long int c;
00232 public:
00234 CutoffConstant(unsigned long int c);
00236 virtual unsigned long int operator ()(void) const;
00238 virtual unsigned long int operator ++(void);
00239 };
00240
00245 class GECODE_SEARCH_EXPORT CutoffLinear : public Cutoff {
00246 protected:
00248 unsigned long int scale;
00250 unsigned long int n;
00251 public:
00253 CutoffLinear(unsigned long int scale);
00255 virtual unsigned long int operator ()(void) const;
00257 virtual unsigned long int operator ++(void);
00258 };
00259
00264 class GECODE_SEARCH_EXPORT CutoffLuby : public Cutoff {
00265 protected:
00267 unsigned long int i;
00269 unsigned long int scale;
00271 static const unsigned long int n_start = 63U;
00273 static unsigned long int start[n_start];
00275 static unsigned long int log(unsigned long int i);
00277 static unsigned long int luby(unsigned long int i);
00278 public:
00280 CutoffLuby(unsigned long int scale);
00282 virtual unsigned long int operator ()(void) const;
00284 virtual unsigned long int operator ++(void);
00285 };
00286
00291 class GECODE_SEARCH_EXPORT CutoffGeometric : public Cutoff {
00292 protected:
00294 double n;
00296 double scale;
00298 double base;
00299 public:
00301 CutoffGeometric(unsigned long int scale, double base);
00303 virtual unsigned long int operator ()(void) const;
00305 virtual unsigned long int operator ++(void);
00306 };
00307
00312 class GECODE_SEARCH_EXPORT CutoffRandom : public Cutoff {
00313 protected:
00315 Support::RandomGenerator rnd;
00317 unsigned long int min;
00319 unsigned long int n;
00321 unsigned long int step;
00323 unsigned long int cur;
00324 public:
00326 CutoffRandom(unsigned int seed,
00327 unsigned long int min, unsigned long int max,
00328 unsigned long int n);
00330 virtual unsigned long int operator ()(void) const;
00332 virtual unsigned long int operator ++(void);
00333 };
00334
00339 class GECODE_SEARCH_EXPORT CutoffAppend : public Cutoff {
00340 protected:
00342 Cutoff* c1;
00344 Cutoff* c2;
00346 unsigned long int n;
00347 public:
00349 CutoffAppend(Cutoff* c1, unsigned long int n, Cutoff* c2);
00351 virtual unsigned long int operator ()(void) const;
00353 virtual unsigned long int operator ++(void);
00355 virtual ~CutoffAppend(void);
00356 };
00357
00362 class GECODE_SEARCH_EXPORT CutoffMerge : public Cutoff {
00363 protected:
00365 Cutoff* c1;
00367 Cutoff* c2;
00368 public:
00370 CutoffMerge(Cutoff* c1, Cutoff* c2);
00372 virtual unsigned long int operator ()(void) const;
00374 virtual unsigned long int operator ++(void);
00376 virtual ~CutoffMerge(void);
00377 };
00378
00383 class GECODE_SEARCH_EXPORT CutoffRepeat : public Cutoff {
00384 protected:
00386 Cutoff* c;
00387
00388 unsigned int cutoff;
00389
00390 unsigned long int i;
00391
00392 unsigned long int n;
00393 public:
00395 CutoffRepeat(Cutoff* c, unsigned long int n);
00397 virtual unsigned long int operator ()(void) const;
00399 virtual unsigned long int operator ++(void);
00401 virtual ~CutoffRepeat(void);
00402 };
00403
00404 }}
00405
00406 #include <gecode/search/cutoff.hpp>
00407
00408 namespace Gecode { namespace Search {
00409
00410 class Stop;
00411
00449 class Options {
00450 public:
00452 bool clone;
00454 double threads;
00456 unsigned int c_d;
00458 unsigned int a_d;
00460 unsigned int nogoods_limit;
00462 Stop* stop;
00464 Cutoff* cutoff;
00466 GECODE_SEARCH_EXPORT static const Options def;
00468 Options(void);
00470 GECODE_SEARCH_EXPORT Options
00471 expand(void) const;
00472 };
00473
00474 }}
00475
00476 #include <gecode/search/options.hpp>
00477
00478 namespace Gecode { namespace Search {
00479
00494 class GECODE_SEARCH_EXPORT Stop {
00495 public:
00497
00498
00499 Stop(void);
00501 virtual bool stop(const Statistics& s, const Options& o) = 0;
00503 virtual ~Stop(void);
00505
00506
00507
00508 static void* operator new(size_t s);
00510 static void operator delete(void* p);
00512
00513
00514
00515 static Stop* node(unsigned long int l);
00517 static Stop* fail(unsigned long int l);
00519 static Stop* time(unsigned long int l);
00521 };
00522
00531 class GECODE_SEARCH_EXPORT NodeStop : public Stop {
00532 protected:
00534 unsigned long int l;
00535 public:
00537 NodeStop(unsigned long int l);
00539 unsigned long int limit(void) const;
00541 void limit(unsigned long int l);
00543 virtual bool stop(const Statistics& s, const Options& o);
00544 };
00545
00554 class GECODE_SEARCH_EXPORT FailStop : public Stop {
00555 protected:
00557 unsigned long int l;
00558 public:
00560 FailStop(unsigned long int l);
00562 unsigned long int limit(void) const;
00564 void limit(unsigned long int l);
00566 virtual bool stop(const Statistics& s, const Options& o);
00567 };
00568
00573 class GECODE_SEARCH_EXPORT TimeStop : public Stop {
00574 protected:
00576 Support::Timer t;
00578 unsigned long int l;
00579 public:
00581 TimeStop(unsigned long int l);
00583 unsigned long int limit(void) const;
00585 void limit(unsigned long int l);
00587 void reset(void);
00589 virtual bool stop(const Statistics& s, const Options& o);
00590 };
00591
00592 }}
00593
00594 #include <gecode/search/stop.hpp>
00595
00596 namespace Gecode { namespace Search {
00597
00601 class GECODE_SEARCH_EXPORT Engine {
00602 public:
00604 virtual Space* next(void) = 0;
00606 virtual Statistics statistics(void) const = 0;
00608 virtual bool stopped(void) const = 0;
00610 virtual void reset(Space* s);
00612 virtual NoGoods& nogoods(void);
00614 virtual ~Engine(void);
00616
00617
00618 static void* operator new(size_t s);
00620 static void operator delete(void* p);
00622 };
00623
00624 }}
00625
00626 #include <gecode/search/engine.hpp>
00627
00628 namespace Gecode {
00629
00630 template<template<class> class E, class T>
00631 class RBS;
00632
00633 }
00634
00635 namespace Gecode { namespace Search {
00636
00638 template<class T>
00639 class EngineBase {
00640 template<template<class>class,class> friend class ::Gecode::RBS;
00641 protected:
00643 Engine* e;
00645 EngineBase(Engine* e = NULL);
00646 public:
00648 virtual T* next(void);
00650 virtual Statistics statistics(void) const;
00652 virtual bool stopped(void) const;
00654 virtual NoGoods& nogoods(void);
00656 virtual ~EngineBase(void);
00658
00659
00660 static void* operator new(size_t s);
00662 static void operator delete(void* p);
00664 };
00665
00666 }}
00667
00668 #include <gecode/search/engine-base.hpp>
00669
00670 namespace Gecode {
00671
00672
00680 template<class T>
00681 class DFS : public Search::EngineBase<T> {
00682 public:
00684 DFS(T* s, const Search::Options& o=Search::Options::def);
00685 };
00686
00688 template<class T>
00689 T* dfs(T* s, const Search::Options& o=Search::Options::def);
00690
00691 }
00692
00693 #include <gecode/search/dfs.hpp>
00694
00695 namespace Gecode {
00696
00708 template<class T>
00709 class BAB : public Search::EngineBase<T> {
00710 public:
00712 BAB(T* s, const Search::Options& o=Search::Options::def);
00713 };
00714
00727 template<class T>
00728 T* bab(T* s, const Search::Options& o=Search::Options::def);
00729
00730 }
00731
00732 #include <gecode/search/bab.hpp>
00733
00734 namespace Gecode {
00735
00754 template<template<class> class E, class T>
00755 class RBS : public Search::EngineBase<T> {
00756 using Search::EngineBase<T>::e;
00757 public:
00759 RBS(T* s, const Search::Options& o);
00760 };
00761
00780 template<template<class> class E, class T>
00781 T* rbs(T* s, const Search::Options& o);
00782
00783 }
00784
00785 #include <gecode/search/rbs.hpp>
00786
00787 #endif
00788
00789