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 #include <gecode/support/timer.hh>
00045
00046
00047
00048
00049
00050 #if !defined(GECODE_STATIC_LIBS) && \
00051 (defined(__CYGWIN__) || defined(__MINGW32__) || defined(_MSC_VER))
00052
00053 #ifdef GECODE_BUILD_SEARCH
00054 #define GECODE_SEARCH_EXPORT __declspec( dllexport )
00055 #else
00056 #define GECODE_SEARCH_EXPORT __declspec( dllimport )
00057 #endif
00058
00059 #else
00060
00061 #ifdef GECODE_GCC_HAS_CLASS_VISIBILITY
00062 #define GECODE_SEARCH_EXPORT __attribute__ ((visibility("default")))
00063 #else
00064 #define GECODE_SEARCH_EXPORT
00065 #endif
00066
00067 #endif
00068
00069
00070 #ifndef GECODE_BUILD_SEARCH
00071 #define GECODE_LIBRARY_NAME "Search"
00072 #include <gecode/support/auto-link.hpp>
00073 #endif
00074
00075
00076 namespace Gecode {
00077
00079 namespace Search {
00080
00086 namespace Config {
00088 const bool clone = true;
00090 const double threads = 1.0;
00092 const unsigned int c_d = 8;
00094 const unsigned int a_d = 2;
00096 const unsigned int d = 5;
00097
00099 const unsigned int steal_limit = 3;
00101 const unsigned int initial_delay = 5;
00102 }
00103
00108 class Statistics : public StatusStatistics {
00109 public:
00111 unsigned long int fail;
00113 unsigned long int node;
00115 unsigned long int depth;
00117 size_t memory;
00119 Statistics(void);
00121 void reset(void);
00123 Statistics operator +(const Statistics& s);
00125 Statistics& operator +=(const Statistics& s);
00126 };
00127
00128 class Stop;
00129
00167 class Options {
00168 public:
00170 bool clone;
00172 double threads;
00174 unsigned int c_d;
00176 unsigned int a_d;
00178 unsigned int d;
00180 Stop* stop;
00182 GECODE_SEARCH_EXPORT static const Options def;
00184 Options(void);
00186 GECODE_SEARCH_EXPORT Options
00187 expand(void) const;
00188 };
00189
00204 class GECODE_SEARCH_EXPORT Stop {
00205 public:
00207 Stop(void);
00209 virtual bool stop(const Statistics& s, const Options& o) = 0;
00211 virtual ~Stop(void);
00212 };
00213
00219 class GECODE_SEARCH_EXPORT MemoryStop : public Stop {
00220 protected:
00222 size_t l;
00223 public:
00225 MemoryStop(size_t l);
00227 size_t limit(void) const;
00229 void limit(size_t l);
00231 virtual bool stop(const Statistics& s, const Options& o);
00232 };
00233
00242 class GECODE_SEARCH_EXPORT NodeStop : public Stop {
00243 protected:
00245 unsigned long int l;
00246 public:
00248 NodeStop(unsigned long int l);
00250 unsigned long int limit(void) const;
00252 void limit(unsigned long int l);
00254 virtual bool stop(const Statistics& s, const Options& o);
00255 };
00256
00265 class GECODE_SEARCH_EXPORT FailStop : public Stop {
00266 protected:
00268 unsigned long int l;
00269 public:
00271 FailStop(unsigned long int l);
00273 unsigned long int limit(void) const;
00275 void limit(unsigned long int l);
00277 virtual bool stop(const Statistics& s, const Options& o);
00278 };
00279
00284 class GECODE_SEARCH_EXPORT TimeStop : public Stop {
00285 protected:
00287 Support::Timer t;
00289 unsigned long int l;
00290 public:
00292 TimeStop(unsigned long int l);
00294 unsigned long int limit(void) const;
00296 void limit(unsigned long int l);
00298 void reset(void);
00300 virtual bool stop(const Statistics& s, const Options& o);
00301 };
00302
00303
00307 class Engine {
00308 public:
00310 virtual Space* next(void) = 0;
00312 virtual Search::Statistics statistics(void) const = 0;
00314 virtual bool stopped(void) const = 0;
00316 virtual ~Engine(void) {}
00317 };
00318
00320 namespace Sequential {}
00321
00323 namespace Parallel {}
00324
00325 }
00326
00327 }
00328
00329 #include <gecode/search/statistics.hpp>
00330 #include <gecode/search/stop.hpp>
00331 #include <gecode/search/options.hpp>
00332
00333 namespace Gecode {
00334
00342 template <class T>
00343 class DFS {
00344 private:
00346 Search::Engine* e;
00347 public:
00349 DFS(T* s, const Search::Options& o=Search::Options::def);
00351 T* next(void);
00353 Search::Statistics statistics(void) const;
00355 bool stopped(void) const;
00357 ~DFS(void);
00358 };
00359
00361 template <class T>
00362 T* dfs(T* s, const Search::Options& o=Search::Options::def);
00363
00364
00365
00377 template <class T>
00378 class BAB {
00379 private:
00381 Search::Engine* e;
00382 public:
00384 BAB(T* s, const Search::Options& o=Search::Options::def);
00386 T* next(void);
00388 Search::Statistics statistics(void) const;
00390 bool stopped(void) const;
00392 ~BAB(void);
00393 };
00394
00407 template <class T>
00408 T* bab(T* s, const Search::Options& o=Search::Options::def);
00409
00410
00411
00423 template <class T>
00424 class Restart {
00425 private:
00427 Search::Engine* e;
00428 public:
00430 Restart(T* s, const Search::Options& o=Search::Options::def);
00432 T* next(void);
00434 Search::Statistics statistics(void) const;
00436 bool stopped(void) const;
00438 ~Restart(void);
00439 };
00440
00452 template <class T>
00453 T* restart(T* s, const Search::Options& o=Search::Options::def);
00454
00455
00456
00461 template <class T>
00462 class LDS {
00463 private:
00465 Search::Engine* e;
00466 public:
00468 LDS(T* s, const Search::Options& o=Search::Options::def);
00470 T* next(void);
00472 Search::Statistics statistics(void) const;
00474 bool stopped(void) const;
00476 ~LDS(void);
00477 };
00478
00483 template <class T>
00484 T* lds(T* s, const Search::Options& o=Search::Options::def);
00485
00486 }
00487
00488 #include <gecode/search/dfs.hpp>
00489 #include <gecode/search/bab.hpp>
00490 #include <gecode/search/restart.hpp>
00491 #include <gecode/search/lds.hpp>
00492
00493 #endif
00494
00495