42 template<
class Collect>
51 template<
class Collect>
57 template<
class Collect>
143 : so(so0), 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>
170 template<
class Collect>
175 template<
class Collect>
180 template<
class Collect>
188 template<
class Collect>
196 for (
unsigned int i=0U; i<
n_slaves; i++) {
203 template<
class Collect>
212 tostop.store(
true, std::memory_order_release);
214 if (!
tostop.load(std::memory_order_acquire))
215 slave_stop.store(
true, std::memory_order_release);
219 while (
slaves[i] != slave)
224 tostop.store(
true, std::memory_order_release);
234 template<
class Collect>
240 }
while (!
master->report(
this,s));
243 template<
class Collect>
249 tostop.store(
false, std::memory_order_release);
250 slave_stop.store(
false, std::memory_order_release);
254 assert(!
tostop.load(std::memory_order_acquire));
259 for (
unsigned int i=0U; i<
n_active; i++) {
284 for (
unsigned int i=0U; i<
n_active; i++)
293 template<
class Collect>
296 return slave_stop.load(std::memory_order_acquire);
299 template<
class Collect>
304 for (
unsigned int i=0U; i<
n_slaves; i++)
309 template<
class Collect>
314 throw NoBest(
"PBS::constrain");
317 for (
unsigned int i=0U; i<
n_active; i++)
322 template<
class Collect>
327 for (
unsigned int i=0U; i<
n_slaves; i++)
330 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.
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.
friend class Slave< Collect >
Support::Mutex m
Mutex for synchronization.
Slave< Collect > ** slaves
Slave engines.
std::atomic< bool > tostop
Shared stop flag.
unsigned int n_active
Number of active slave engines.
unsigned int n_slaves
Number of slave engines.
Statistics stat
Master statistics.
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
Whether a slave has been stopped.
virtual Space * next(void)
Return next solution (nullptr, if none exists or search has been stopped).
virtual Statistics statistics(void) const
Return statistics.
unsigned int n_busy
Number of busy slaves.
Stop object used for controlling slaves in a portfolio.
void share(std::atomic< bool > *ts)
Set pointer to shared tostop variable.
PortfolioStop(Stop *so)
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 constrain(const Space &b)
Constrain with better solution b.
Base-class for Stop-object.
Stop(void)
Default constructor.
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.