42 template<
class Collect>
51 template<
class Collect>
57 template<
class Collect>
144 : so(so0), po(po0), worker_control(control), tostop(nullptr) {}
152 template<
class Collect>
156 template<
class Collect>
159 return slave->statistics();
161 template<
class Collect>
164 return slave->stopped();
166 template<
class Collect>
169#ifdef GECODE_HAS_EXPERIMENTAL
170 return slave->limited();
175 template<
class Collect>
180 template<
class Collect>
185 template<
class Collect>
190 template<
class Collect>
195 template<
class Collect>
203 template<
class Collect>
218 template<
class Collect>
228 tostop.store(
true, std::memory_order_release);
232 if (!
tostop.load(std::memory_order_acquire)) {
233 slave_stop.store(
true, std::memory_order_release);
234 tostop.store(
true, std::memory_order_release);
243 while (
slaves[i] != slave)
248 tostop.store(
true, std::memory_order_release);
252 for (
unsigned int i=0U; i<
n_active; i++)
262 template<
class Collect>
268 }
while (!
master->report(
this,s));
271 template<
class Collect>
276 slave_stop.store(
false, std::memory_order_release);
278 !
slave_stop.load(std::memory_order_acquire)) {
280 tostop.store(
false, std::memory_order_release);
284 assert(!
tostop.load(std::memory_order_acquire));
288 for (
unsigned int i=0U; i<
n_active; i++) {
304 slave_stop.store(
true, std::memory_order_release);
315 for (
unsigned int i=0U; i<
n_active; i++)
324 template<
class Collect>
327 return slave_stop.load(std::memory_order_acquire);
330 template<
class Collect>
335 for (
unsigned int i=0U; i<
n_slaves; i++)
340 template<
class Collect>
345 throw NoBest(
"PBS::constrain");
348 for (
unsigned int i=0U; i<
n_active; i++)
353 template<
class Collect>
358 for (
unsigned int i=0U; i<
n_slaves; i++)
361 for (
unsigned int i=0U; i<
n_slaves; i++)
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 (nullptr if solution has already been reported).
~CollectBest(void)
Destructor.
Space * b
Currently best solution.
Parallel depth-first search engine
Engine(const Options &o)
Initialize with options o.
void stop(unsigned long long int r)
Report that a worker was stopped during call r of next().
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, Stop *po, const WorkerControl &control)
Initialize with slave stop so, portfolio stop po, and control.
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.
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
void wait(Home home, FloatVar x, std::function< void(Space &home)> c)
Execute c when x becomes assigned.