44 #ifndef GECODE_THREADS_WINDOWS 48 namespace Gecode {
namespace Driver {
80 ((ns != NULL) && ns->
stop(s,o)) ||
81 ((fs != NULL) && fs->
stop(s,o)) ||
82 ((ts != NULL) && ts->
stop(s,o));
96 if ( (!intr) && (
node == 0) && (
fail == 0) && (
time == 0))
101 #ifdef GECODE_THREADS_WINDOWS 104 if (
t == CTRL_C_EVENT) {
121 if (force || !sigint) {
122 #ifdef GECODE_THREADS_WINDOWS 123 SetConsoleCtrlHandler( (PHANDLER_ROUTINE)
interrupt, install);
125 std::signal(SIGINT, install ?
interrupt : SIG_DFL);
131 delete ns;
delete fs;
delete ts;
146 am(
double t[],
unsigned int n);
152 dev(
double t[],
unsigned int n);
155 template<
class Options>
175 #ifdef GECODE_HAS_GIST 180 template<
class Engine>
218 template<
class BaseSpace>
223 template<
class BaseSpace>
226 : BaseSpace(share,e) {}
228 template<
class BaseSpace>
232 template<
class BaseSpace>
236 template<
class BaseSpace>
239 if (strcmp(sn,
"stdout") == 0) {
241 }
else if (strcmp(sn,
"stdlog") == 0) {
243 }
else if (strcmp(sn,
"stderr") == 0) {
255 template<
class T,
template<
class>
class E>
261 template<
class BaseSpace>
262 template<
class Script,
template<
class>
class Engine,
class Options>
266 std::cerr <<
"Cannot use restarts and portfolio..." << std::endl;
270 runMeta<Script,Engine,Options,RBS>(o,s);
271 }
else if (o.
assets() > 0) {
272 runMeta<Script,Engine,Options,PBS>(o,s);
274 runMeta<Script,Engine,Options,EngineToMeta>(o,s);
278 template<
class BaseSpace>
279 template<
class Script,
template<
class>
class Engine,
class Options,
280 template<
class,
template<
class>
class>
class Meta>
282 ScriptBase<BaseSpace>::runMeta(const Options& o, Script* s) {
285 ofstream sol_file, log_file;
287 ostream& s_out = select_ostream(o.out_file(), sol_file);
288 ostream& l_out = select_ostream(o.log_file(), log_file);
293 #ifdef GECODE_HAS_GIST 298 opt.inspect.click(&
pi);
299 opt.inspect.compare(&vc);
303 for (
unsigned int i=0; o.inspect.click(
i) != NULL;
i++)
304 opt.inspect.click(o.inspect.click(
i));
305 for (
unsigned int i=0; o.inspect.solution(
i) != NULL;
i++)
306 opt.inspect.solution(o.inspect.solution(
i));
307 for (
unsigned int i=0; o.inspect.move(
i) != NULL;
i++)
308 opt.inspect.move(o.inspect.move(
i));
309 for (
unsigned int i=0; o.inspect.compare(
i) != NULL;
i++)
310 opt.inspect.compare(o.inspect.compare(
i));
320 l_out << o.name() << endl;
322 int i = static_cast<int>(o.solutions());
342 Meta<Script,Engine> e(s,so);
343 if (o.print_last()) {
369 Search::Statistics stat = e.statistics();
372 l_out <<
"Search engine stopped..." << endl
374 int r = static_cast<CombinedStop*>(so.
stop)->reason(stat,so);
376 l_out <<
"user interrupt " << endl;
384 l_out <<
"limit reached" << endl << endl;
387 l_out <<
"Initial" << endl
388 <<
"\tpropagators: " << n_p << endl
389 <<
"\tbranchers: " << n_b << endl
396 <<
::abs(static_cast<int>(o.solutions()) -
i) << endl
397 <<
"\tpropagations: " << stat.propagate << endl
398 <<
"\tnodes: " << stat.node << endl
399 <<
"\tfailures: " << stat.fail << endl
400 <<
"\trestarts: " << stat.restart << endl
401 <<
"\tno-goods: " << stat.nogood << endl
402 <<
"\tpeak depth: " << stat.depth << endl
403 #ifdef GECODE_PEAKHEAP 405 << static_cast<int>((
heap.peak()+1023) / 1024) <<
" KB" 415 l_out << o.name() << endl;
417 int i = static_cast<int>(o.solutions());
425 so.threads = o.threads();
426 so.assets = o.assets();
433 so.nogoods_limit = o.nogoods() ? o.nogoods_limit() : 0U;
437 Meta<Script,Engine> e(s,so);
446 Search::Statistics stat = e.statistics();
448 <<
"\tpropagators: " << n_p << endl
449 <<
"\tbranchers: " << n_b << endl
454 <<
::abs(static_cast<int>(o.solutions()) -
i) << endl
455 <<
"\tpropagations: " << stat.propagate << endl
456 <<
"\tnodes: " << stat.node << endl
457 <<
"\tfailures: " << stat.fail << endl
458 <<
"\trestarts: " << stat.restart << endl
459 <<
"\tno-goods: " << stat.nogood << endl
460 <<
"\tpeak depth: " << stat.depth << endl
461 #ifdef GECODE_PEAKHEAP 463 << static_cast<int>((
heap.peak()+1023) / 1024) <<
" KB" 473 l_out << o.name() << endl;
475 double* ts =
new double[o.samples()];
476 bool stopped =
false;
477 for (
unsigned int ns = o.samples(); !stopped && ns--; ) {
479 for (
unsigned int k = o.iterations(); !stopped && k--; ) {
480 unsigned int i = o.solutions();
484 so.threads = o.threads();
485 so.assets = o.assets();
492 so.nogoods_limit = o.nogoods() ? o.nogoods_limit() : 0U;
494 Meta<Script,Engine> e(s1,so);
506 ts[ns] =
t.stop() / o.iterations();
509 l_out <<
"\tSTOPPED" << endl;
511 double m =
am(ts,o.samples());
512 double d =
dev(ts,o.samples()) * 100.0;
513 l_out <<
"\truntime: " 515 << showpoint << fixed
516 << setprecision(6) << m <<
"ms" 517 << setprecision(2) <<
" (" <<
d <<
"% deviation)" 524 }
catch (Exception& e) {
525 cerr <<
"Exception: " << e.what() <<
"." << endl
526 <<
"Stopping..." << endl;
527 if (sol_file.is_open())
529 if (log_file.is_open())
533 if (sol_file.is_open())
535 if (log_file.is_open())
unsigned int a_d
Create a clone during recomputation if distance is greater than a_d (adaptive distance)
Restart with linear sequence.
unsigned int nogoods_limit
Depth limit for extraction of no-goods.
Limited discrepancy search engine.
static BrancherGroup all
Group of all branchers.
Stop-object based on number of nodes
unsigned int c_d
Create a clone after every c_d commits (commit distance)
void abs(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
static PropagatorGroup all
Group of all propagators.
void stop(Support::Timer &timer, std::ostream &os)
Get time since start of timer and print user friendly time information.
Traits class for search engines.
virtual void print(std::ostream &os) const
Print a solution to os.
static void interrupt(int)
Handler for catching Ctrl-C.
Restart with Luby sequence.
Base class for cutoff generators for restart-based meta engine.
static Stop * fail(unsigned long int l)
Stop if failure limit l has been exceeded.
Search::Cutoff * createCutoff(const Options &o)
Create cutoff object from options.
unsigned int d_l
Discrepancy limit (for LDS)
Parametric base-class for scripts.
unsigned int size(Space &home) const
Return number of propagators in a group.
virtual void compare(const Space &home, std::ostream &os) const
Compare with s.
static Stop * node(unsigned long int l)
Stop if node limit l has been exceeded.
static void explore(S *root, const Gist::Options &opt)
Cutoff * cutoff
Cutoff for restart-based search.
double threads
Number of threads to use.
Gecode::IntArgs i(4, 1, 2, 3, 4)
int n
Number of negative literals for node type.
int dfs(Space *root, const Gist::Options &opt)
Create a new stand-alone Gist for root.
Print solution and some statistics.
Depth-first branch-and-bound search engine.
static void installCtrlHandler(bool install, bool force=false)
Install handler for catching Ctrl-C.
static Search::Stop * create(unsigned int node, unsigned int fail, unsigned int time, bool intr)
Create appropriate stop-object.
Stop object based on nodes, failures, and time.
static void explore(S *root, const Gist::Options &opt)
unsigned int size(Space &home) const
Return number of branchers in a group.
double am(double t[], unsigned int n)
Compute arithmetic mean of n elements in t.
int reason(const Search::Statistics &s, const Search::Options &o)
Report reason why search has been stopped.
void restart_scale(unsigned int scale)
Set default restart scale factor.
bool clone
Whether engines create a clone when being initialized.
virtual bool stop(const Statistics &s, const Options &o)
Return true if failure limit is exceeded.
#define GECODE_DRIVER_EXPORT
static Stop * time(unsigned long int l)
Stop if time limit l (in milliseconds) has been exceeded.
static Cutoff * geometric(unsigned long int scale=Config::slice, double base=Config::base)
unsigned int assets
Number of assets (engines) in a portfolio.
Post propagator for SetVar SetOpType SetVar SetRelType r
double dev(double t[], unsigned int n)
Compute deviation of n elements in t.
~CombinedStop(void)
Destructor.
void assets(unsigned int n)
Set default number of assets in a portfolio.
Print statistics for script.
Restart with geometric sequence.
static Cutoff * linear(unsigned long int scale=Config::slice)
Create generator for linear sequence scaled by scale.
static Cutoff * luby(unsigned long int scale=Config::slice)
Create generator for luby sequence with scale-factor scale.
Heap heap
The single global heap.
virtual bool stop(const Statistics &s, const Options &o)
Return true if node limit is exceeded.
static void run(const Options &opt, Script *s=NULL)
void restart_base(double base)
Set default restart base.
int bab(Space *root, const Gist::Options &opt)
Create a new stand-alone Gist for branch-and-bound search of root.
ScriptBase(const Options &opt)
Constructor.
static Cutoff * constant(unsigned long int scale=Config::slice)
Create generator for constant sequence with constant s.
Stop * stop
Stop object for stopping search.
int explore(Space *root, bool bab, const Options &opt)
Create a new stand-alone Gist for root using bab.
Gecode toplevel namespace
static std::ostream & select_ostream(const char *sn, std::ofstream &ofs)
Choose output stream according to sn.
An inspector for printing simple text output.
Stop-object based on time
Base-class for Stop-object.
void restart(RestartMode r)
Set default restart mode.
static void explore(S *root, const Gist::Options &opt)
#define GECODE_NEVER
Assert that this command is never executed.
virtual bool stop(const Statistics &s, const Options &o)
Return true if time limit is exceeded.
Restart with constant sequence.
Driver::ScriptBase< Driver::IgnoreStepOption< Space > > Script
Base-class for scripts.
Depth-first search engine.
Stop-object based on number of failures
static void explore(Space *root, const Gist::Options &opt)
virtual bool stop(const Search::Statistics &s, const Search::Options &o)
Test whether search must be stopped.