pbs.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 #ifndef __GECODE_SEARCH_PAR_PBS_HH__
00035 #define __GECODE_SEARCH_PAR_PBS_HH__
00036
00037 #include <gecode/search.hh>
00038
00039 namespace Gecode { namespace Search { namespace Par {
00040
00042 class GECODE_SEARCH_EXPORT PortfolioStop : public Stop {
00043 private:
00045 Stop* so;
00047 volatile bool* tostop;
00048 public:
00050 PortfolioStop(Stop* so);
00052 void share(volatile bool* ts);
00054 virtual bool stop(const Statistics& s, const Options& o);
00056 void stop(bool s);
00058 bool stop(void) const;
00059 };
00060
00061
00062 template<class Collect>
00063 class PBS;
00064
00066 template<class Collect>
00067 class GECODE_SEARCH_EXPORT Slave : public Support::Runnable {
00068 protected:
00070 PBS<Collect>* master;
00072 Engine* slave;
00074 Stop* stop;
00075 public:
00077 Slave(PBS<Collect>* m, Engine* s, Stop* so);
00079 Statistics statistics(void) const;
00081 bool stopped(void) const;
00083 void constrain(const Space& b);
00085 virtual void run(void);
00087 virtual ~Slave(void);
00088 };
00089
00091 class CollectAll {
00092 protected:
00094 Support::DynamicQueue<Space*,Heap> solutions;
00095 public:
00097 static const bool best = false;
00099 CollectAll(void);
00101 bool add(Space* s, Slave<CollectAll>* r);
00103 bool constrain(const Space& b);
00105 bool empty(void) const;
00107 Space* get(Slave<CollectAll>*& r);
00109 ~CollectAll(void);
00110 };
00111
00113 class CollectBest {
00114 protected:
00116 Space* b;
00118 Slave<CollectBest>* reporter;
00119 public:
00121 static const bool best = true;
00123 CollectBest(void);
00125 bool add(Space* s, Slave<CollectBest>* r);
00127 bool constrain(const Space& b);
00129 bool empty(void) const;
00131 Space* get(Slave<CollectBest>*& r);
00133 ~CollectBest(void);
00134 };
00135
00137 template<class Collect>
00138 class GECODE_SEARCH_EXPORT PBS : public Engine {
00139 friend class Slave<Collect>;
00140 protected:
00142 Statistics stat;
00144 Slave<Collect>** slaves;
00146 unsigned int n_slaves;
00148 unsigned int n_active;
00150 bool slave_stop;
00152 volatile bool tostop;
00154 Collect solutions;
00156 Support::Mutex m;
00158 unsigned int n_busy;
00160 Support::Event idle;
00162 bool report(Slave<Collect>* slave, Space* s);
00171 public:
00173 PBS(Engine** s, Stop** so, unsigned int n, const Statistics& stat);
00175 virtual Space* next(void);
00177 virtual Statistics statistics(void) const;
00179 virtual bool stopped(void) const;
00181 virtual void constrain(const Space& b);
00183 virtual ~PBS(void);
00184 };
00185
00186 }}}
00187
00188 #include <gecode/search/par/pbs.hpp>
00189
00190 #endif
00191
00192