40 #ifndef GECODE_THREADS_WINDOWS 44 namespace Gecode {
namespace Driver {
76 ((ns != NULL) && ns->
stop(s,o)) ||
77 ((fs != NULL) && fs->
stop(s,o)) ||
78 ((ts != NULL) && ts->
stop(s,o));
90 create(
unsigned int node,
unsigned int fail,
unsigned int time,
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>
222 virtual std::string getInfo(
const Space& home)
const;
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;
321 #ifdef GECODE_HAS_GIST 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));
349 #ifdef GECODE_HAS_CPPROFILER 352 if (o.profiler_info())
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());
372 so.threads = o.threads();
376 so.assets = o.assets();
377 so.slice = o.slice();
382 so.nogoods_limit = o.nogoods() ? o.nogoods_limit() : 0U;
386 Meta<Script,Engine> e(s,so);
387 if (o.print_last()) {
416 l_out <<
"Search engine stopped..." << endl
418 int r =
static_cast<CombinedStop*
>(so.stop)->reason(stat,so);
420 l_out <<
"user interrupt " << endl;
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());
470 so.threads = o.threads();
471 so.assets = o.assets();
472 so.slice = o.slice();
479 so.nogoods_limit = o.nogoods() ? o.nogoods_limit() : 0U;
483 Meta<Script,Engine> e(s,so);
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();
532 so.
slice = o.slice();
541 Meta<Script,Engine> e(s1,so);
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)" 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())
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.