44 #ifndef GECODE_THREADS_WINDOWS
48 namespace Gecode {
namespace Driver {
61 CombinedStop(
unsigned int node,
unsigned int fail,
unsigned int time)
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 Space>
212 if (strcmp(name,
"stdout") == 0) {
214 }
else if (strcmp(name,
"stdlog") == 0) {
216 }
else if (strcmp(name,
"stderr") == 0) {
227 template<
template<
class>
class E,
class T>
233 template<
class Space>
234 template<
class Script,
template<
class>
class Engine,
class Options>
238 runMeta<Script,Engine,Options,EngineToMeta>(o,s);
240 runMeta<Script,Engine,Options,RBS>(o,s);
244 template<
class Space>
245 template<
class Script,
template<
class>
class Engine,
class Options,
246 template<
template<
class>
class,
class>
class Meta>
251 ofstream sol_file, log_file;
253 ostream& s_out = select_ostream(o.out_file(), sol_file);
254 ostream& l_out = select_ostream(o.log_file(), log_file);
259 #ifdef GECODE_HAS_GIST
269 for (
int i=0; o.inspect.click(
i) != NULL;
i++)
270 opt.
inspect.click(o.inspect.click(
i));
271 for (
int i=0; o.inspect.solution(
i) != NULL;
i++)
272 opt.
inspect.solution(o.inspect.solution(
i));
273 for (
int i=0; o.inspect.move(
i) != NULL;
i++)
274 opt.
inspect.move(o.inspect.move(
i));
275 for (
int i=0; o.inspect.compare(
i) != NULL;
i++)
276 opt.
inspect.compare(o.inspect.compare(
i));
279 (void) GistEngine<Engine<Script> >::
explore(s, opt);
286 l_out << o.name() << endl;
288 int i = o.solutions();
292 unsigned int n_p = s->propagators();
293 unsigned int n_b = s->branchers();
306 Meta<Engine,Script> e(s,so);
307 if (o.print_last()) {
333 Search::Statistics stat = e.statistics();
336 l_out <<
"Search engine stopped..." << endl
338 int r =
static_cast<CombinedStop*
>(so.
stop)->reason(stat,so);
340 l_out <<
"user interrupt " << endl;
348 l_out <<
"limit reached" << endl << endl;
351 l_out <<
"Initial" << endl
352 <<
"\tpropagators: " << n_p << endl
353 <<
"\tbranchers: " << n_b << endl
360 <<
::abs(static_cast<int>(o.solutions()) - i) << endl
361 <<
"\tpropagations: " << stat.propagate << endl
362 <<
"\tnodes: " << stat.node << endl
363 <<
"\tfailures: " << stat.fail << endl
364 <<
"\trestarts: " << stat.restart << endl
365 <<
"\tno-goods: " << stat.nogood << endl
366 <<
"\tpeak depth: " << stat.depth << endl
367 #ifdef GECODE_PEAKHEAP
369 <<
static_cast<int>((
heap.peak()+1023) / 1024) <<
" KB"
379 l_out << o.name() << endl;
381 int i = o.solutions();
385 unsigned int n_p = s->propagators();
386 unsigned int n_b = s->branchers();
389 so.threads = o.threads();
395 so.nogoods_limit = o.nogoods() ? o.nogoods_limit() : 0U;
399 Meta<Engine,Script> e(s,so);
408 Search::Statistics stat = e.statistics();
410 <<
"\tpropagators: " << n_p << endl
411 <<
"\tbranchers: " << n_b << endl
416 <<
::abs(static_cast<int>(o.solutions()) - i) << endl
417 <<
"\tpropagations: " << stat.propagate << endl
418 <<
"\tnodes: " << stat.node << endl
419 <<
"\tfailures: " << stat.fail << endl
420 <<
"\trestarts: " << stat.restart << endl
421 <<
"\tno-goods: " << stat.nogood << endl
422 <<
"\tpeak depth: " << stat.depth << endl
423 #ifdef GECODE_PEAKHEAP
425 <<
static_cast<int>((
heap.peak()+1023) / 1024) <<
" KB"
435 l_out << o.name() << endl;
437 double* ts =
new double[o.samples()];
438 bool stopped =
false;
439 for (
unsigned int s = o.samples(); !stopped && s--; ) {
441 for (
unsigned int k = o.iterations(); !stopped && k--; ) {
442 unsigned int i = o.solutions();
446 so.threads = o.threads();
452 so.nogoods_limit = o.nogoods() ? o.nogoods_limit() : 0U;
454 Meta<Engine,Script> e(s,so);
466 ts[s] = t.stop() / o.iterations();
469 l_out <<
"\tSTOPPED" << endl;
471 double m =
am(ts,o.samples());
472 double d =
dev(ts,o.samples()) * 100.0;
473 l_out <<
"\truntime: "
475 << showpoint << fixed
476 << setprecision(6) << m <<
"ms"
477 << setprecision(2) <<
" (" << d <<
"% deviation)"
484 }
catch (Exception& e) {
485 cerr <<
"Exception: " << e.what() <<
"." << endl
486 <<
"Stopping..." << endl;
487 if (sol_file.is_open())
489 if (log_file.is_open())
493 if (sol_file.is_open())
495 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.
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.
Driver::ScriptBase< Space > Script
Base-class for scripts.
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.
Search::Cutoff * createCutoff(const Options &o)
Create cutoff object from options.
Parametric base-class for scripts.
Heap heap
The single global heap.
static std::ostream & select_ostream(const char *name, std::ofstream &ofs)
Choose output stream according to name.
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.
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
~CombinedStop(void)
Destructor.
Print statistics for script.
Restart with geometric sequence.
virtual void print(std::ostream &os) const
Print a solution to os.
virtual bool stop(const Statistics &s, const Options &o)
Return true if node limit is exceeded.
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.
static void run(const Options &opt, Script *s=NULL)
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
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.
Stop-object based on number of failures
virtual bool stop(const Search::Statistics &s, const Search::Options &o)
Test whether search must be stopped.