40 template<
class T,
template<
class>
class E>
50 template<
class T,
template<
class>
class E>
55 template<
class T,
template<
class>
class E>
78namespace Gecode {
namespace Search {
namespace Par {
91namespace Gecode {
namespace Search {
93 template<
class T,
template<
class>
class E>
101 static_cast<double>(opt.
assets)),1.0);
103 unsigned int n_slaves = opt.
assets;
110 for (
unsigned int i=0U; i<n_slaves; i++) {
112 Space* slave = (i == n_slaves-1) ?
113 master : master->clone();
114 (void) slave->
slave(i);
121 template<
class T,
template<
class>
class E>
127 int n_slaves = sebs.
size();
133 static_cast<unsigned int>(n_slaves));
135 for (
int i=0; i<n_slaves; i++) {
138 sebs[i]->options().stop = stops[i];
139 sebs[i]->options().clone =
false;
140 Space* slave = (i == n_slaves-1) ?
141 master : master->clone();
142 (void) slave->
slave(
static_cast<unsigned int>(i));
143 slaves[i] = (*sebs[i])(slave);
147 return Seq::pbsengine(slaves,stops,
static_cast<unsigned int>(n_slaves),
151#ifdef GECODE_HAS_THREADS
153 template<
class T,
template<
class>
class E>
160 unsigned int n_slaves = std::min(
static_cast<unsigned int>(opt.
threads),
171 for (
unsigned int i=0U; i<n_slaves; i++) {
173 Space* slave = (i == n_slaves-1) ?
174 master : master->clone();
175 (void) slave->
slave(
static_cast<unsigned int>(i));
182 template<
class T,
template<
class>
class E>
189 int n_slaves = std::min(
static_cast<int>(opt.
threads),
194 static_cast<unsigned int>(n_slaves));
199 for (
int i=0; i<n_slaves; i++) {
202 sebs[i]->options().stop = stops[i];
203 sebs[i]->options().clone =
false;
204 Space* slave = (i == n_slaves-1) ?
205 master : master->clone();
206 (void) slave->
slave(
static_cast<unsigned int>(i));
207 slaves[i] = (*sebs[i])(slave);
211 for (
int i=n_slaves; i<sebs.
size(); i++)
214 return Par::pbsengine(slaves,stops,
static_cast<unsigned int>(n_slaves),
224 template<
class T,
template<
class>
class E>
242 T* master = opt.clone ?
243 dynamic_cast<T*
>(s->clone()) : s;
247 (void) master->master(0);
251 (void) master->slave(0);
256#ifdef GECODE_HAS_THREADS
264 template<
class T,
template<
class>
class E>
271 for (
int i=0; i<sebs.
size(); i++)
272 b += sebs[i]->
best() ? 1 : 0;
273 if ((b > 0) && (b < sebs.
size()))
290 T* master = opt.clone ?
291 dynamic_cast<T*
>(s->clone()) : s;
295 (void) master->master(0);
297#ifdef GECODE_HAS_THREADS
305 template<
class T,
template<
class>
class E>
311 template<
class T,
template<
class>
class E>
318 template<
class T,
template<
class>
class E>
int size(void) const
Return size of array (number of elements).
void assets(unsigned int n)
Set default number of assets in a portfolio.
void threads(double n)
Set number of parallel threads.
Meta engine using a portfolio of search engines.
void build(T *s, SEBs &sebs, const Search::Options &o)
The actual build function.
PBS(T *s, const Search::Options &o=Search::Options::def)
Initialize with engines running copies of s with options o.
static const bool best
Whether engine does best solution search.
T * alloc(long unsigned int n)
Allocate block of n objects of type T from region.
Passing search engine builder arguments.
@ PBS
Engine is a PBS engine.
virtual T * next(void)
Return next solution (nullptr, if none exists or search has been stopped).
Engine * e
The actual search engine.
Options opt
Stored and already expanded options.
Builder(const Options &opt, bool best)
Initialize with options opt and best solution search support.
bool best(void) const
Whether engine is a best solution search engine.
Search engine implementation interface
Exception: Mixed non-best and best solution search requested
Exception: No assets requested for portfolio-based search
Options expand(void) const
Expand with real number of threads.
Stop * stop
Stop object for stopping search.
SearchTracer * tracer
Tracer object for tracing search.
unsigned int assets
Number of assets (engines) in a portfolio.
double threads
Number of threads to use.
Parallel depth-first search engine
PbsBuilder(const Options &opt)
The constructor.
virtual Engine * operator()(Space *s) const
The actual build function.
unsigned long long int fail
Number of failed nodes in search tree.
Base-class for Stop-object.
static void engine(SearchTracer *tracer, SearchTracer::EngineType t, unsigned int n)
Register engine.
virtual bool slave(const MetaInfo &mi)
Slave configuration function for meta search engines.
T * pbs(T *s, const Search::Options &o=Search::Options::def)
Run a portfolio of search engines.
@ SS_FAILED
Space is failed
Engine * pbsengine(Engine **slaves, Stop **stops, unsigned int n_slaves, const Statistics &stat, bool best)
Create parallel portfolio engine.
Stop * pbsstop(Stop *so)
Create stop object.
Engine * dead(const Options &o, const Statistics &stat)
Stop * pbsstop(Stop *so)
Create stop object.
Engine * pbsengine(Engine **slaves, Stop **stops, unsigned int n_slaves, const Statistics &stat, const Search::Options &opt, bool best)
Create sequential portfolio engine.
Engine * build(Space *s, const Options &opt)
Build an engine of type E for a script T.
Engine * pbspar(T *master, const Search::Statistics &stat, Options &opt)
Engine * pbsseq(T *master, const Search::Statistics &stat, Options &opt)
Gecode toplevel namespace
Search::Builder * SEB
Type for a search engine builder.
#define GECODE_SEARCH_EXPORT