36namespace Gecode {
namespace Search {
namespace Par {
69 :
b(NULL), reporter(NULL) {}
118 : so(so0), tostop(NULL) {}
126 template<
class Collect>
129 : Support::Runnable(false), master(m), slave(s), stop(so) {}
130 template<
class Collect>
133 return slave->statistics();
135 template<
class Collect>
138 return slave->stopped();
140 template<
class Collect>
145 template<
class Collect>
153 template<
class Collect>
157 : stat(stat0), slaves(
heap.alloc<
Slave<Collect>*>(
n)),
158 n_slaves(
n), n_active(
n),
159 slave_stop(false), tostop(false), n_busy(0) {
161 for (
unsigned int i=0U; i<
n_slaves; i++) {
168 template<
class Collect>
175 b = solutions.add(s,slave);
184 while (slaves[i] != slave)
186 assert(i < n_active);
187 assert(n_active > 0);
188 std::swap(slaves[i],slaves[--n_active]);
199 template<
class Collect>
205 }
while (!master->report(
this,s));
208 template<
class Collect>
212 if (solutions.empty()) {
224 for (
unsigned int i=0U; i<n_active; i++)
239 if (solutions.empty()) {
243 s = solutions.get(
r);
245 for (
unsigned int i=0U; i<n_active; i++)
247 slaves[i]->constrain(*s);
254 template<
class Collect>
260 template<
class Collect>
265 for (
unsigned int i=0U; i<n_slaves; i++)
266 s += slaves[i]->statistics();
270 template<
class Collect>
275 throw NoBest(
"PBS::constrain");
276 if (solutions.constrain(
b)) {
278 for (
unsigned int i=0U; i<n_active; i++)
279 slaves[i]->constrain(
b);
283 template<
class Collect>
struct Gecode::@603::NNF::@65::@66 b
For binary nodes (and, or, eqv)
int n
Number of negative literals for node type.
void free(T *b, long unsigned int n)
Delete n objects starting at b.
Exception: Best solution search is not supported
Space * get(Slave< CollectAll > *&r)
Return solution reported by r.
bool empty(void) const
Check whether there is any solution left.
Support::DynamicQueue< Space *, Heap > solutions
Queue of solutions.
bool add(Space *s, Slave< CollectAll > *r)
Add a solution a reported by r and always return true.
CollectAll(void)
Initialize.
~CollectAll(void)
Destructor.
bool constrain(const Space &b)
Dummy function.
CollectBest(void)
Initialize.
bool constrain(const Space &b)
Check whether b better and update accordingly.
bool empty(void) const
Check whether there is any solution left.
bool add(Space *s, Slave< CollectBest > *r)
Add a solution s by r and return whether is was better.
Space * get(Slave< CollectBest > *&r)
Return solution reported by r (only if a better one was found)
Slave< CollectBest > * reporter
Who has reported the best solution (NULL if solution has already been reported)
~CollectBest(void)
Destructor.
Space * b
Currently best solution.
Parallel depth-first search engine
Parallel portfolio engine implementation.
virtual bool stopped(void) const
Check whether engine has been stopped.
virtual ~PBS(void)
Destructor.
bool report(Slave< Collect > *slave, Space *s)
Process report from slave, return false if solution was ignored.
friend class Slave< Collect >
Slave< Collect > ** slaves
Slave engines.
volatile bool tostop
Shared stop flag.
unsigned int n_slaves
Number of slave engines.
PBS(Engine **s, Stop **so, unsigned int n, const Statistics &stat)
Initialize.
virtual void constrain(const Space &b)
Constrain future solutions to be better than b.
virtual Space * next(void)
Return next solution (NULL, if none exists or search has been stopped)
virtual Statistics statistics(void) const
Return statistics.
Stop object used for controling slaves in a portfolio.
void share(volatile bool *ts)
Set pointer to shared tostop variable.
PortfolioStop(Stop *so)
Initialize.
Runnable slave of a portfolio master.
virtual void run(void)
Perform one run.
bool stopped(void) const
Check whether slave has been stopped.
virtual ~Slave(void)
Delete slave.
Statistics statistics(void) const
Return statistics of slave.
Slave(PBS< Collect > *m, Engine *s, Stop *so)
Initialize with master m, slave s, and its stop object so.
void constrain(const Space &b)
Constrain with better solution b.
Base-class for Stop-object.
static void run(Runnable *r)
Construct a new thread and run r.
Heap heap
The single global heap.
virtual void constrain(const Space &best)
Constrain function for best solution search.
SpaceStatus status(StatusStatistics &stat=unused_status)
Query space status.
Space * clone(CloneStatistics &stat=unused_clone) const
Clone space.
@ SS_FAILED
Space is failed
Gecode toplevel namespace
Post propagator for SetVar SetOpType SetVar SetRelType r