42 template<
class Collect>
51 template<
class Collect>
57 template<
class Collect>
143 : so(so0), worker_control(control), tostop(nullptr) {}
151 template<
class Collect>
155 template<
class Collect>
158 return slave->statistics();
160 template<
class Collect>
163 return slave->stopped();
165 template<
class Collect>
168#ifdef GECODE_HAS_EXPERIMENTAL
169 return slave->limited();
174 template<
class Collect>
179 template<
class Collect>
184 template<
class Collect>
189 template<
class Collect>
194 template<
class Collect>
202 template<
class Collect>
210 for (
unsigned int i=0U; i<
n_slaves; i++) {
217 template<
class Collect>
227 tostop.store(
true, std::memory_order_release);
231 if (!
tostop.load(std::memory_order_acquire)) {
232 slave_stop.store(
true, std::memory_order_release);
233 tostop.store(
true, std::memory_order_release);
242 while (
slaves[i] != slave)
247 tostop.store(
true, std::memory_order_release);
251 for (
unsigned int i=0U; i<
n_active; i++)
261 template<
class Collect>
267 }
while (!
master->report(
this,s));
270 template<
class Collect>
275 slave_stop.store(
false, std::memory_order_release);
277 !
slave_stop.load(std::memory_order_acquire)) {
279 tostop.store(
false, std::memory_order_release);
283 assert(!
tostop.load(std::memory_order_acquire));
287 for (
unsigned int i=0U; i<
n_active; i++) {
303 slave_stop.store(
true, std::memory_order_release);
314 for (
unsigned int i=0U; i<
n_active; i++)
323 template<
class Collect>
326 return slave_stop.load(std::memory_order_acquire);
329 template<
class Collect>
334 for (
unsigned int i=0U; i<
n_slaves; i++)
339 template<
class Collect>
344 throw NoBest(
"PBS::constrain");
347 for (
unsigned int i=0U; i<
n_active; i++)
352 template<
class Collect>
357 for (
unsigned int i=0U; i<
n_slaves; i++)
360 for (
unsigned int i=0U; i<
n_slaves; i++)
void free(T *b, long unsigned int n)
Delete n objects starting at b.
NoBest(const char *l)
Initialize with location l.
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 (nullptr if solution has already been reported).
~CollectBest(void)
Destructor.
Space * b
Currently best solution.
Parallel depth-first search engine
void wait(void)
Ensure that worker waits.
Engine(const Options &o)
Initialize with options o.
Parallel portfolio engine implementation.
virtual bool stopped(void) const
Check whether engine has been stopped.
virtual ~PBS(void)
Destructor.
Support::Event idle
Signal that number of busy slaves becomes zero.
bool report(Slave< Collect > *slave, Space *s)
Process report from slave, return false if solution was ignored.
Collect solutions
Collect solutions in this.
Support::Mutex m
Mutex for synchronization.
Slave< Gecode::Search::Par::CollectBest > ** slaves
std::atomic< bool > tostop
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.
std::atomic< bool > slave_stop
virtual Space * next(void)
Return next solution (nullptr, if none exists or search has been stopped).
virtual Statistics statistics(void) const
Return statistics.
Stop object used for controlling slaves in a portfolio.
void share(std::atomic< bool > *ts)
Set pointer to shared tostop variable.
PortfolioStop(Stop *so, const WorkerControl &control)
Initialize.
Completion event for the current run.
virtual void terminated(void)
Signal completion.
void wait(void)
Wait for completion and consume the signal.
Completion(void)
Initialize as completed.
Support::Event done
The completion event.
Runnable slave of a portfolio master.
Engine * slave
The slave engine.
PBS< Collect > * master
The master engine.
void wait(void)
Wait for the slave to complete its current run.
virtual Support::Terminator * terminator(void) const
Return the completion terminator.
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.
Gecode::Search::Par::Slave::Completion completion
void wake(void)
Wake a paused slave so that it can observe the portfolio stop.
void constrain(const Space &b)
Constrain with better solution b.
bool limited(void) const
Check whether slave stopped at a local limit.
Base-class for Stop-object.
Stop(void)
Default constructor.
External control for the requested number of search workers.
void signal(void)
Signal the event.
Runnable(bool d=true)
Initialize, d defines whether object is deleted when terminated.
An interface for objects that can be called after a thread has terminated (after running the thread's...
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.
Space * clone(void) const
Clone space.
SpaceStatus status(StatusStatistics &stat)
Query space status.
@ SS_FAILED
Space is failed
Support algorithms and datastructures
Gecode toplevel namespace