40#ifndef GECODE_THREADS_WINDOWS
44namespace Gecode {
namespace Driver {
76 ((ns != NULL) && ns->
stop(s,o)) ||
77 ((fs != NULL) && fs->
stop(s,o)) ||
78 ((ts != NULL) && ts->
stop(s,o));
92 if ( (!intr) && (
node == 0) && (
fail == 0) && (
time == 0))
97#ifdef GECODE_THREADS_WINDOWS
100 if (
t == CTRL_C_EVENT) {
117 if (force || !sigint) {
118#ifdef GECODE_THREADS_WINDOWS
119 SetConsoleCtrlHandler( (PHANDLER_ROUTINE)
interrupt, install);
121 std::signal(SIGINT, install ?
interrupt : SIG_DFL);
127 delete ns;
delete fs;
delete ts;
142 am(
double t[],
unsigned int n);
148 dev(
double t[],
unsigned int n);
151 template<
class Options>
171#ifdef GECODE_HAS_GIST
176 template<
class Engine>
213#ifdef GECODE_HAS_CPPROFILER
216 template<
class BaseSpace>
227 template<
class BaseSpace>
232 template<
class BaseSpace>
237 template<
class BaseSpace>
241 template<
class BaseSpace>
245 template<
class BaseSpace>
248 if (strcmp(sn,
"stdout") == 0) {
250 }
else if (strcmp(sn,
"stdlog") == 0) {
252 }
else if (strcmp(sn,
"stderr") == 0) {
260#ifdef GECODE_HAS_CPPROFILER
262 template<
class BaseSpace>
265 template<
class BaseSpace>
268 std::stringstream ss;
281 template<
class T,
template<
class>
class E>
287 template<
class BaseSpace>
288 template<
class Script,
template<
class>
class Engine,
class Options>
292 std::cerr <<
"Cannot use restarts and portfolio..." << std::endl;
296 runMeta<Script,Engine,Options,RBS>(o,s);
297 }
else if (o.
assets() > 0) {
298 runMeta<Script,Engine,Options,PBS>(o,s);
300 runMeta<Script,Engine,Options,EngineToMeta>(o,s);
304 template<
class BaseSpace>
305 template<
class Script,
template<
class>
class Engine,
class Options,
306 template<
class,
template<
class>
class>
class Meta>
308 ScriptBase<BaseSpace>::runMeta(const Options& o, Script* s) {
311 ofstream sol_file, log_file;
313 ostream& s_out = select_ostream(o.out_file(), sol_file);
314 ostream& l_out = select_ostream(o.log_file(), log_file);
321#ifdef GECODE_HAS_GIST
326 opt.inspect.click(&
pi);
327 opt.inspect.compare(&vc);
331 for (
unsigned int i=0; o.inspect.click(i) != NULL; i++)
332 opt.inspect.click(o.inspect.click(i));
333 for (
unsigned int i=0; o.inspect.solution(i) != NULL; i++)
334 opt.inspect.solution(o.inspect.solution(i));
335 for (
unsigned int i=0; o.inspect.move(i) != NULL; i++)
336 opt.inspect.move(o.inspect.move(i));
337 for (
unsigned int i=0; o.inspect.compare(i) != NULL; i++)
338 opt.inspect.compare(o.inspect.compare(i));
341 (void)
GistEngine<Engine<Script> >::explore(s, opt);
349#ifdef GECODE_HAS_CPPROFILER
352 if (o.profiler_info())
353 getInfo =
new ScriptGetInfo<BaseSpace>;
355 (o.profiler_id(), o.name(), o.profiler_port(), getInfo);
360#ifndef GECODE_HAS_GIST
364 l_out << o.name() << endl;
366 int i =
static_cast<int>(o.solutions());
370 unsigned int n_p = PropagatorGroup::all.size(*s);
371 unsigned int n_b = BrancherGroup::all.size(*s);
377 so.
slice = o.slice();
378 so.
stop = CombinedStop::create(o.node(),o.fail(), o.time(),
380 so.
cutoff = createCutoff(o);
384 CombinedStop::installCtrlHandler(
true);
386 Meta<Script,Engine> e(s,so);
387 if (o.print_last()) {
390 Script* ex = e.next();
412 CombinedStop::installCtrlHandler(
false);
413 Search::Statistics stat = e.statistics();
416 l_out <<
"Search engine stopped..." << endl
418 int r =
static_cast<CombinedStop*
>(so.
stop)->reason(stat,so);
419 if (
r & CombinedStop::SR_INT)
420 l_out <<
"user interrupt " << endl;
422 if (
r & CombinedStop::SR_NODE)
424 if (
r & CombinedStop::SR_FAIL)
426 if (
r & CombinedStop::SR_TIME)
428 l_out <<
"limit reached" << endl << endl;
431 l_out <<
"Initial" << endl
432 <<
"\tpropagators: " << n_p << endl
433 <<
"\tbranchers: " << n_b << endl
440 << ::abs(
static_cast<int>(o.solutions()) - i) << endl
441 <<
"\tpropagations: " << stat.propagate << endl
442 <<
"\tnodes: " << stat.node << endl
443 <<
"\tfailures: " << stat.fail << endl
444 <<
"\trestarts: " << stat.restart << endl
445 <<
"\tno-goods: " << stat.nogood << endl
446 <<
"\tpeak depth: " << stat.depth << endl
447#ifdef GECODE_PEAKHEAP
449 <<
static_cast<int>((
heap.peak()+1023) / 1024) <<
" KB"
460 l_out << o.name() << endl;
462 int i =
static_cast<int>(o.solutions());
466 unsigned int n_p = PropagatorGroup::all.size(*s);
467 unsigned int n_b = BrancherGroup::all.size(*s);
472 so.
slice = o.slice();
476 so.
stop = CombinedStop::create(o.node(),o.fail(), o.time(),
481 CombinedStop::installCtrlHandler(
true);
483 Meta<Script,Engine> e(s,so);
491 CombinedStop::installCtrlHandler(
false);
492 Search::Statistics stat = e.statistics();
494 <<
"\tpropagators: " << n_p << endl
495 <<
"\tbranchers: " << n_b << endl
500 << ::abs(
static_cast<int>(o.solutions()) - i) << endl
501 <<
"\tpropagations: " << stat.propagate << endl
502 <<
"\tnodes: " << stat.node << endl
503 <<
"\tfailures: " << stat.fail << endl
504 <<
"\trestarts: " << stat.restart << endl
505 <<
"\tno-goods: " << stat.nogood << endl
506 <<
"\tpeak depth: " << stat.depth << endl
507#ifdef GECODE_PEAKHEAP
509 <<
static_cast<int>((
heap.peak()+1023) / 1024) <<
" KB"
519 l_out << o.name() << endl;
521 double* ts =
new double[o.samples()];
522 bool stopped =
false;
523 for (
unsigned int ns = o.samples(); !stopped && ns--; ) {
525 for (
unsigned int k = o.iterations(); !stopped && k--; ) {
526 unsigned int i = o.solutions();
530 sok.threads = o.threads();
531 sok.assets = o.assets();
532 sok.slice = o.slice();
536 sok.stop = CombinedStop::create(o.node(),o.fail(), o.time(),
539 sok.nogoods_limit = o.nogoods() ? o.nogoods_limit() : 0U;
541 Meta<Script,Engine> e(s1,sok);
553 ts[ns] =
t.stop() / o.iterations();
556 l_out <<
"\tSTOPPED" << endl;
558 double m =
am(ts,o.samples());
559 double d =
dev(ts,o.samples()) * 100.0;
560 l_out <<
"\truntime: "
562 << showpoint << fixed
563 << setprecision(6) << m <<
"ms"
564 << setprecision(2) <<
" (" <<
d <<
"% deviation)"
571 }
catch (Exception& e) {
572 cerr <<
"Exception: " << e.what() <<
"." << endl
573 <<
"Stopping..." << endl;
574 if (sol_file.is_open())
576 if (log_file.is_open())
580 if (sol_file.is_open())
582 if (log_file.is_open())
int n
Number of negative literals for node type.
Depth-first branch-and-bound search engine.
Class to send solution information to CPProfiler.
Class to record search trace info for CPProfiler.
Depth-first search engine.
Stop object based on nodes, failures, and time.
~CombinedStop(void)
Destructor.
static void installCtrlHandler(bool install, bool force=false)
Install handler for catching Ctrl-C.
virtual bool stop(const Search::Statistics &s, const Search::Options &o)
Test whether search must be stopped.
static Search::Stop * create(unsigned int node, unsigned int fail, unsigned int time, bool intr)
Create appropriate stop-object.
static void interrupt(int)
Handler for catching Ctrl-C.
@ SR_INT
Interrupted by user.
@ SR_NODE
Node limit reached.
@ SR_FAIL
Fail limit reached.
@ SR_TIME
Time limit reached.
int reason(const Search::Statistics &s, const Search::Options &o)
Report reason why search has been stopped.
static void explore(S *root, const Gist::Options &opt)
static void explore(S *root, const Gist::Options &opt)
static void explore(S *root, const Gist::Options &opt)
Traits class for search engines.
static void explore(Space *root, const Gist::Options &opt)
Parametric base-class for scripts.
static void run(const Options &opt, Script *s=NULL)
virtual void compare(const Space &home, std::ostream &os) const
Compare with s.
virtual void print(std::ostream &os) const
Print a solution to os.
static std::ostream & select_ostream(const char *sn, std::ofstream &ofs)
Choose output stream according to sn.
ScriptBase(const Options &opt)
Constructor.
Class to send solution information to CPProfiler for a script.
ScriptGetInfo(void)
Initialize.
virtual std::string getInfo(const Space &home) const
Return info for a space (which must be a script)
An inspector for printing simple text output.
Limited discrepancy search engine.
void restart(RestartMode r)
Set default restart mode.
void assets(unsigned int n)
Set default number of assets in a portfolio.
void restart_scale(unsigned int scale)
Set default restart scale factor.
void restart_base(double base)
Set default restart base.
Base class for cutoff generators for restart-based meta engine.
static Cutoff * linear(unsigned long int scale=Config::slice)
Create generator for linear sequence scaled by scale.
static Cutoff * geometric(unsigned long int scale=Config::slice, double base=Config::base)
static Cutoff * constant(unsigned long int scale=Config::slice)
Create generator for constant sequence with constant s.
static Cutoff * luby(unsigned long int scale=Config::slice)
Create generator for luby sequence with scale-factor scale.
Stop-object based on number of failures
virtual bool stop(const Statistics &s, const Options &o)
Return true if failure limit is exceeded.
Stop-object based on number of nodes
virtual bool stop(const Statistics &s, const Options &o)
Return true if node limit is exceeded.
unsigned int c_d
Create a clone after every c_d commits (commit distance)
bool clone
Whether engines create a clone when being initialized.
unsigned int d_l
Discrepancy limit (for LDS)
Cutoff * cutoff
Cutoff for restart-based search.
unsigned int a_d
Create a clone during recomputation if distance is greater than a_d (adaptive distance)
Stop * stop
Stop object for stopping search.
SearchTracer * tracer
Tracer object for tracing search.
unsigned int assets
Number of assets (engines) in a portfolio.
unsigned int slice
Size of a slice in a portfolio (in number of failures)
unsigned int nogoods_limit
Depth limit for extraction of no-goods.
double threads
Number of threads to use.
Base-class for Stop-object.
static Stop * node(unsigned long int l)
Stop if node limit l has been exceeded.
static Stop * time(unsigned long int l)
Stop if time limit l (in milliseconds) has been exceeded.
static Stop * fail(unsigned long int l)
Stop if failure limit l has been exceeded.
Stop-object based on time
virtual bool stop(const Statistics &s, const Options &o)
Return true if time limit is exceeded.
#define GECODE_DRIVER_EXPORT
Heap heap
The single global heap.
@ SM_STAT
Print statistics for script.
@ SM_GIST
Run script in Gist.
@ SM_CPPROFILER
Run script with CP-profiler.
@ SM_TIME
Measure average runtime.
@ RM_CONSTANT
Restart with constant sequence.
@ RM_LINEAR
Restart with linear sequence.
@ RM_LUBY
Restart with Luby sequence.
@ RM_GEOMETRIC
Restart with geometric sequence.
Driver::ScriptBase< Driver::IgnoreStepOption< Space > > Script
Base-class for scripts.
int bab(Space *root, const Gist::Options &opt=Gist::Options::def)
Create a new stand-alone Gist for branch-and-bound search of root.
int dfs(Space *root, const Gist::Options &opt=Gist::Options::def)
Create a new stand-alone Gist for root.
double dev(double t[], unsigned int n)
Compute deviation of n elements in t.
void stop(Support::Timer &timer, std::ostream &os)
Get time since start of timer and print user friendly time information.
Search::Cutoff * createCutoff(const Options &o)
Create cutoff object from options.
double am(double t[], unsigned int n)
Compute arithmetic mean of n elements in t.
Gecode toplevel namespace
Gecode::IntArgs i({1, 2, 3, 4})
#define GECODE_NEVER
Assert that this command is never executed.