38#ifndef GECODE_SEARCH_PAR_PBS_HH
39#define GECODE_SEARCH_PAR_PBS_HH
56 std::atomic<bool>* tostop;
61 void share(std::atomic<bool>* ts);
73 template<
class Collect>
77 template<
class Collect>
117 virtual void run(
void);
129 static const bool best =
false;
137 bool empty(
void)
const;
161 bool empty(
void)
const;
169 template<
class Collect>
171 friend class Slave<Collect>;
213 virtual bool stopped(
void)
const;
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.
static const bool best
Whether it collects best solutions.
bool constrain(const Space &b)
Dummy function.
CollectBest(void)
Initialize.
static const bool best
Whether it collects best solutions.
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).
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.
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.
bool incomplete
Whether a slave stopped at a local limit.
Collect solutions
Collect solutions in this.
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.
void wake(void)
Wake workers so that a paused asset can observe the portfolio stop.
void share(std::atomic< bool > *ts)
Set pointer to shared tostop variable.
void stop(bool s)
Signal whether search must be stopped.
PortfolioStop(Stop *so, Stop *po, const WorkerControl &control)
Initialize with slave stop so, portfolio stop po, and control.
virtual bool stop(const Statistics &s, const Options &o)
Return true if portfolio engine must be stopped.
bool stop(void) const
Whether search must be stopped.
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.
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 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.
Queue with arbitrary number of elements.
An event for synchronization.
A mutex for mutual exclausion among several threads.
An interface for objects that can be run by a thread.
An interface for objects that can be called after a thread has terminated (after running the thread's...
Gecode toplevel namespace
#define GECODE_SEARCH_EXPORT