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));
94 create(
unsigned int node,
unsigned int fail,
unsigned int time,
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>
217 #ifdef GECODE_HAS_CPPROFILER 220 template<
class BaseSpace>
226 virtual std::string getInfo(
const Space& home)
const;
231 template<
class BaseSpace>
236 template<
class BaseSpace>
241 template<
class BaseSpace>
245 template<
class BaseSpace>
249 template<
class BaseSpace>
252 if (strcmp(sn,
"stdout") == 0) {
254 }
else if (strcmp(sn,
"stdlog") == 0) {
256 }
else if (strcmp(sn,
"stderr") == 0) {
264 #ifdef GECODE_HAS_CPPROFILER 266 template<
class BaseSpace>
269 template<
class BaseSpace>
272 std::stringstream ss;
285 template<
class T,
template<
class>
class E>
291 template<
class BaseSpace>
292 template<
class Script,
template<
class>
class Engine,
class Options>
296 std::cerr <<
"Cannot use restarts and portfolio..." << std::endl;
300 runMeta<Script,Engine,Options,RBS>(o,s);
301 }
else if (o.
assets() > 0) {
302 runMeta<Script,Engine,Options,PBS>(o,s);
304 runMeta<Script,Engine,Options,EngineToMeta>(o,s);
308 template<
class BaseSpace>
309 template<
class Script,
template<
class>
class Engine,
class Options,
310 template<
class,
template<
class>
class>
class Meta>
312 ScriptBase<BaseSpace>::runMeta(const Options& o, Script* s) {
315 ofstream sol_file, log_file;
325 #ifdef GECODE_HAS_GIST 335 for (
unsigned int i=0; o.inspect.click(
i) != NULL;
i++)
336 opt.
inspect.click(o.inspect.click(
i));
337 for (
unsigned int i=0; o.inspect.solution(
i) != NULL;
i++)
338 opt.
inspect.solution(o.inspect.solution(
i));
339 for (
unsigned int i=0; o.inspect.move(
i) != NULL;
i++)
340 opt.
inspect.move(o.inspect.move(
i));
341 for (
unsigned int i=0; o.inspect.compare(
i) != NULL;
i++)
342 opt.
inspect.compare(o.inspect.compare(
i));
353 #ifdef GECODE_HAS_CPPROFILER 356 if (o.profiler_info())
359 (o.profiler_id(), o.name(), o.profiler_port(), getInfo);
364 #ifndef GECODE_HAS_GIST 368 l_out << o.name() << endl;
370 int i =
static_cast<int>(o.solutions());
376 so.threads = o.threads();
380 so.assets = o.assets();
381 so.slice = o.slice();
386 so.nogoods_limit = o.nogoods() ? o.nogoods_limit() : 0U;
390 Meta<Script,Engine> e(s,so);
391 if (o.print_last()) {
420 l_out <<
"Search engine stopped..." << endl
422 int r =
static_cast<CombinedStop*
>(so.stop)->reason(stat,so);
424 l_out <<
"user interrupt " << endl;
432 l_out <<
"limit reached" << endl << endl;
435 l_out <<
"Initial" << endl
436 <<
"\tpropagators: " << n_p << endl
437 <<
"\tbranchers: " << n_b << endl
444 <<
::abs(static_cast<int>(o.solutions()) - i) << endl
445 <<
"\tpropagations: " << stat.
propagate << endl
446 <<
"\tnodes: " << stat.
node << endl
447 <<
"\tfailures: " << stat.
fail << endl
448 <<
"\trestarts: " << stat.
restart << endl
449 <<
"\tno-goods: " << stat.
nogood << endl
450 <<
"\tpeak depth: " << stat.
depth << endl
451 #ifdef GECODE_PEAKHEAP 453 <<
static_cast<int>((
heap.peak()+1023) / 1024) <<
" KB" 464 l_out << o.name() << endl;
466 int i =
static_cast<int>(o.solutions());
474 so.threads = o.threads();
475 so.assets = o.assets();
476 so.slice = o.slice();
483 so.nogoods_limit = o.nogoods() ? o.nogoods_limit() : 0U;
487 Meta<Script,Engine> e(s,so);
498 <<
"\tpropagators: " << n_p << endl
499 <<
"\tbranchers: " << n_b << endl
504 <<
::abs(static_cast<int>(o.solutions()) - i) << endl
505 <<
"\tpropagations: " << stat.
propagate << endl
506 <<
"\tnodes: " << stat.
node << endl
507 <<
"\tfailures: " << stat.
fail << endl
508 <<
"\trestarts: " << stat.
restart << endl
509 <<
"\tno-goods: " << stat.
nogood << endl
510 <<
"\tpeak depth: " << stat.
depth << endl
511 #ifdef GECODE_PEAKHEAP 513 <<
static_cast<int>((
heap.peak()+1023) / 1024) <<
" KB" 523 l_out << o.name() << endl;
525 double* ts =
new double[o.samples()];
526 bool stopped =
false;
527 for (
unsigned int ns = o.samples(); !stopped && ns--; ) {
529 for (
unsigned int k = o.iterations(); !stopped && k--; ) {
530 unsigned int i = o.solutions();
536 so.
slice = o.slice();
545 Meta<Script,Engine> e(s1,so);
557 ts[ns] = t.
stop() / o.iterations();
560 l_out <<
"\tSTOPPED" << endl;
562 double m =
am(ts,o.samples());
563 double d =
dev(ts,o.samples()) * 100.0;
564 l_out <<
"\truntime: " 566 << showpoint << fixed
567 << setprecision(6) << m <<
"ms" 568 << setprecision(2) <<
" (" << d <<
"% deviation)" 576 cerr <<
"Exception: " << e.
what() <<
"." << endl
577 <<
"Stopping..." << endl;
578 if (sol_file.is_open())
580 if (log_file.is_open())
584 if (sol_file.is_open())
586 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.
Class to send solution information to CPProfiler.
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.
unsigned int slice
Size of a slice in a portfolio (in number of failures)
virtual void inspect(const Space &node)
Use the print method of the template class S to print a space.
unsigned long int fail
Number of failed nodes in search tree.
unsigned long int nogood
Number of no-goods posted.
unsigned long int depth
Maximum depth of search stack.
Restart with Luby sequence.
Base class for cutoff generators for restart-based meta engine.
Class to record search trace info for CPProfiler.
static Stop * fail(unsigned long int l)
Stop if failure limit l has been exceeded.
unsigned long int propagate
Number of propagator executions.
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)
void start(void)
Start timer.
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.
ScriptGetInfo(void)
Initialize.
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)
virtual const char * what(void) const
Return information.
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.
double stop(void)
Get time since start of timer.
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.
Exception: Base-class for exceptions
Print statistics for script.
Run script with CP-profiler.
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.
unsigned long int restart
Number of restarts.
Class to send solution information to CPProfiler for a script.
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.
unsigned long int node
Number of nodes expanded.
An inspector for printing simple text output.
Stop-object based on time
Base-class for Stop-object.
virtual std::string getInfo(const Space &home) const
Return info for a space (which must be a script)
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.