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[],
int n);
152 dev(
double t[],
int n);
155 template<
class Options>
175 #ifdef GECODE_HAS_GIST
180 template<
class Engine>
190 class GistEngine<DFS<S> > {
192 static void explore(S* root,
const Gist::Options&
opt) {
199 class GistEngine<BAB<S> > {
201 static void explore(S* root,
const Gist::Options&
opt) {
209 template<
class BaseSpace>
214 template<
class BaseSpace>
217 : BaseSpace(share,e) {}
219 template<
class BaseSpace>
223 template<
class BaseSpace>
227 template<
class BaseSpace>
230 if (strcmp(name,
"stdout") == 0) {
232 }
else if (strcmp(name,
"stdlog") == 0) {
234 }
else if (strcmp(name,
"stderr") == 0) {
246 template<
template<
class>
class E,
class T>
252 template<
class BaseSpace>
253 template<
class Script,
template<
class>
class Engine,
class Options>
257 runMeta<Script,Engine,Options,EngineToMeta>(o,s);
259 runMeta<Script,Engine,Options,RBS>(o,s);
263 template<
class BaseSpace>
264 template<
class Script,
template<
class>
class Engine,
class Options,
265 template<
template<
class>
class,
class>
class Meta>
267 ScriptBase<BaseSpace>::runMeta(const Options& o, Script* s) {
270 ofstream sol_file, log_file;
272 ostream& s_out = select_ostream(o.out_file(), sol_file);
273 ostream& l_out = select_ostream(o.log_file(), log_file);
278 #ifdef GECODE_HAS_GIST
288 for (
int i=0; o.inspect.click(
i) != NULL;
i++)
289 opt.
inspect.click(o.inspect.click(
i));
290 for (
int i=0; o.inspect.solution(
i) != NULL;
i++)
291 opt.
inspect.solution(o.inspect.solution(
i));
292 for (
int i=0; o.inspect.move(
i) != NULL;
i++)
293 opt.
inspect.move(o.inspect.move(
i));
294 for (
int i=0; o.inspect.compare(
i) != NULL;
i++)
295 opt.
inspect.compare(o.inspect.compare(
i));
298 (void) GistEngine<Engine<Script> >::
explore(s, opt);
305 l_out << o.name() << endl;
307 int i = o.solutions();
311 unsigned int n_p = s->propagators();
312 unsigned int n_b = s->branchers();
325 Meta<Engine,Script> e(s,so);
326 if (o.print_last()) {
352 Search::Statistics stat = e.statistics();
355 l_out <<
"Search engine stopped..." << endl
357 int r =
static_cast<CombinedStop*
>(so.
stop)->reason(stat,so);
359 l_out <<
"user interrupt " << endl;
367 l_out <<
"limit reached" << endl << endl;
370 l_out <<
"Initial" << endl
371 <<
"\tpropagators: " << n_p << endl
372 <<
"\tbranchers: " << n_b << endl
379 <<
::abs(static_cast<int>(o.solutions()) - i) << endl
380 <<
"\tpropagations: " << stat.propagate << endl
381 <<
"\tnodes: " << stat.node << endl
382 <<
"\tfailures: " << stat.fail << endl
383 <<
"\trestarts: " << stat.restart << endl
384 <<
"\tno-goods: " << stat.nogood << endl
385 <<
"\tpeak depth: " << stat.depth << endl
386 #ifdef GECODE_PEAKHEAP
388 <<
static_cast<int>((
heap.peak()+1023) / 1024) <<
" KB"
398 l_out << o.name() << endl;
400 int i = o.solutions();
404 unsigned int n_p = s->propagators();
405 unsigned int n_b = s->branchers();
408 so.threads = o.threads();
414 so.nogoods_limit = o.nogoods() ? o.nogoods_limit() : 0U;
418 Meta<Engine,Script> e(s,so);
427 Search::Statistics stat = e.statistics();
429 <<
"\tpropagators: " << n_p << endl
430 <<
"\tbranchers: " << n_b << endl
435 <<
::abs(static_cast<int>(o.solutions()) - i) << endl
436 <<
"\tpropagations: " << stat.propagate << endl
437 <<
"\tnodes: " << stat.node << endl
438 <<
"\tfailures: " << stat.fail << endl
439 <<
"\trestarts: " << stat.restart << endl
440 <<
"\tno-goods: " << stat.nogood << endl
441 <<
"\tpeak depth: " << stat.depth << endl
442 #ifdef GECODE_PEAKHEAP
444 <<
static_cast<int>((
heap.peak()+1023) / 1024) <<
" KB"
454 l_out << o.name() << endl;
456 double* ts =
new double[o.samples()];
457 bool stopped =
false;
458 for (
unsigned int s = o.samples(); !stopped && s--; ) {
460 for (
unsigned int k = o.iterations(); !stopped && k--; ) {
461 unsigned int i = o.solutions();
465 so.threads = o.threads();
471 so.nogoods_limit = o.nogoods() ? o.nogoods_limit() : 0U;
473 Meta<Engine,Script> e(s,so);
485 ts[s] = t.stop() / o.iterations();
488 l_out <<
"\tSTOPPED" << endl;
490 double m =
am(ts,o.samples());
491 double d =
dev(ts,o.samples()) * 100.0;
492 l_out <<
"\truntime: "
494 << showpoint << fixed
495 << setprecision(6) << m <<
"ms"
496 << setprecision(2) <<
" (" << d <<
"% deviation)"
503 }
catch (Exception& e) {
504 cerr <<
"Exception: " << e.what() <<
"." << endl
505 <<
"Stopping..." << endl;
506 if (sol_file.is_open())
508 if (log_file.is_open())
512 if (sol_file.is_open())
514 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.
double am(double t[], int n)
Compute arithmetic mean of n elements in t.
unsigned int nogoods_limit
Depth limit for extraction of no-goods.
static std::ostream & select_ostream(const char *name, std::ofstream &ofs)
Choose output stream according to name.
Stop-object based on number of nodes
static Cutoff * geometric(unsigned long int scale=1U, double base=1.5)
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 .
void stop(Support::Timer &timer, std::ostream &os)
Get time since start of timer and print user friendly time information.
static void interrupt(int)
Handler for catching Ctrl-C.
virtual void inspect(const Space &node)
Use the print method of the template class S to print a space.
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.
virtual void compare(const Space &home, std::ostream &os) const
Compare with s.
Search::Cutoff * createCutoff(const Options &o)
Create cutoff object from options.
Parametric base-class for scripts.
Heap heap
The single global heap.
static Stop * node(unsigned long int l)
Stop if node limit l has been exceeded.
void start(void)
Start timer.
Cutoff * cutoff
Cutoff for restart-based search.
double threads
Number of threads to use.
double dev(double t[], int n)
Compute deviation of n elements in t.
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.
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.
static Cutoff * linear(unsigned long int scale=1U)
Create generator for linear sequence scaled by scale.
Stop object based on nodes, failures, and time.
virtual void print(std::ostream &os) const
Print a solution to os.
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.
static Cutoff * constant(unsigned long int scale=1U)
Create generator for constant sequence with constant s.
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.
~CombinedStop(void)
Destructor.
Print statistics for script.
Restart with geometric sequence.
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)
static Cutoff * luby(unsigned long int scale=1U)
Create generator for luby sequence with scale-factor scale.
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.
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.
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.
#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.
Stop-object based on number of failures
virtual bool stop(const Search::Statistics &s, const Search::Options &o)
Test whether search must be stopped.