Generated on Tue Feb 11 2025 17:33:26 for Gecode by doxygen 1.12.0
driver.hh
Go to the documentation of this file.
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2/*
3 * Main authors:
4 * Christian Schulte <schulte@gecode.org>
5 *
6 * Copyright:
7 * Christian Schulte, 2009
8 *
9 * This file is part of Gecode, the generic constraint
10 * development environment:
11 * http://www.gecode.org
12 *
13 * Permission is hereby granted, free of charge, to any person obtaining
14 * a copy of this software and associated documentation files (the
15 * "Software"), to deal in the Software without restriction, including
16 * without limitation the rights to use, copy, modify, merge, publish,
17 * distribute, sublicense, and/or sell copies of the Software, and to
18 * permit persons to whom the Software is furnished to do so, subject to
19 * the following conditions:
20 *
21 * The above copyright notice and this permission notice shall be
22 * included in all copies or substantial portions of the Software.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 *
32 */
33
34#ifndef __GECODE_DRIVER_HH__
35#define __GECODE_DRIVER_HH__
36
37#include <gecode/minimodel.hh>
38#include <gecode/search.hh>
39#ifdef GECODE_HAS_GIST
40#include <gecode/gist.hh>
41#endif
42
43/*
44 * Configure linking
45 *
46 */
47#if !defined(GECODE_STATIC_LIBS) && \
48 (defined(__CYGWIN__) || defined(__MINGW32__) || defined(_MSC_VER))
49
50#ifdef GECODE_BUILD_DRIVER
51#define GECODE_DRIVER_EXPORT __declspec( dllexport )
52#else
53#define GECODE_DRIVER_EXPORT __declspec( dllimport )
54#endif
55
56#else
57
58#ifdef GECODE_GCC_HAS_CLASS_VISIBILITY
59#define GECODE_DRIVER_EXPORT __attribute__ ((visibility("default")))
60#else
61#define GECODE_DRIVER_EXPORT
62#endif
63
64#endif
65
66// Configure auto-linking
67#ifndef GECODE_BUILD_DRIVER
68#define GECODE_LIBRARY_NAME "Driver"
70#endif
71
82namespace Gecode {
83
84
101
113
114 class BaseOptions;
115
116 namespace Driver {
123 protected:
124 const char* eopt;
125 const char* iopt;
126 const char* exp;
129 char* argument(int argc, char* argv[]) const;
130 public:
132 BaseOption(const char* o, const char* e);
134 virtual int parse(int argc, char* argv[]) = 0;
136 virtual void help(void) = 0;
138 virtual ~BaseOption(void);
140 static char* strdup(const char* s);
142 static char* stredup(const char* s);
144 static void strdel(const char* s);
145 };
146
152 protected:
153 const char* cur;
154 public:
156 StringValueOption(const char* o, const char* e, const char* v=NULL);
158 void value(const char* v);
160 const char* value(void) const;
162 virtual int parse(int argc, char* argv[]);
164 virtual void help(void);
166 virtual ~StringValueOption(void);
167 };
168
169
175 protected:
177 class Value {
178 public:
179 int val;
180 const char* opt;
181 const char* help;
183 };
184 int cur;
187 public:
189 StringOption(const char* o, const char* e, int v=0);
191 void value(int v);
193 int value(void) const;
195 void add(int v, const char* o, const char* h = NULL);
197 virtual int parse(int argc, char* argv[]);
199 virtual void help(void);
201 virtual ~StringOption(void);
202 };
203
204
210 protected:
211 int cur;
212 public:
214 IntOption(const char* o, const char* e, int v=0);
216 void value(int v);
218 int value(void) const;
220 virtual int parse(int argc, char* argv[]);
222 virtual void help(void);
223 };
224
230 protected:
231 unsigned int cur;
232 public:
234 UnsignedIntOption(const char* o, const char* e, unsigned int v=0);
236 void value(unsigned int v);
238 unsigned int value(void) const;
240 virtual int parse(int argc, char* argv[]);
242 virtual void help(void);
243 };
244
250 protected:
251 double cur;
252 public:
254 DoubleOption(const char* o, const char* e, double v=0);
256 void value(double v);
258 double value(void) const;
260 virtual int parse(int argc, char* argv[]);
262 virtual void help(void);
263 };
264
270 protected:
271 bool cur;
272 public:
274 BoolOption(const char* o, const char* e, bool v=false);
276 void value(bool v);
278 bool value(void) const;
280 virtual int parse(int argc, char* argv[]);
282 virtual void help(void);
283 };
284
290 protected:
292 public:
294 IplOption(IntPropLevel ipl=IPL_DEF);
296 void value(IntPropLevel l);
298 IntPropLevel value(void) const;
300 virtual int parse(int argc, char* argv[]);
302 virtual void help(void);
303 };
304
310 protected:
311 int cur;
312 public:
314 TraceOption(int f=0);
316 void value(int f);
318 int value(void) const;
320 virtual int parse(int argc, char* argv[]);
322 virtual void help(void);
323 };
324
325 }
326
332 protected:
335 const char* _name;
336 public:
338 BaseOptions(const char* s);
340 virtual void help(void);
341
343 void add(Driver::BaseOption& o);
351 void parse(int& argc, char* argv[]);
352
354 const char* name(void) const;
356 void name(const char*);
357
359 virtual ~BaseOptions(void);
360 };
361
367 protected:
369
379
381
401
403
411
412#ifdef GECODE_HAS_CPPROFILER
416#endif
417
419
420 public:
422 Options(const char* s);
423
425
426
427 void model(int v);
429 void model(int v, const char* o, const char* h = NULL);
431 int model(void) const;
432
434 void symmetry(int v);
436 void symmetry(int v, const char* o, const char* h = NULL);
438 int symmetry(void) const;
439
441 void propagation(int v);
443 void propagation(int v, const char* o, const char* h = NULL);
445 int propagation(void) const;
446
448 void ipl(IntPropLevel i);
450 IntPropLevel ipl(void) const;
451
453 void branching(int v);
455 void branching(int v, const char* o, const char* h = NULL);
457 int branching(void) const;
458
460 void decay(double d);
462 double decay(void) const;
463
465 void seed(unsigned int s);
467 unsigned int seed(void) const;
468
470 void step(double s);
472 double step(void) const;
474
476
477
478 void search(int v);
480 void search(int v, const char* o, const char* h = NULL);
482 int search(void) const;
483
485 void solutions(unsigned int n);
487 unsigned int solutions(void) const;
488
490 void threads(double n);
492 double threads(void) const;
493
495 void c_d(unsigned int d);
497 unsigned int c_d(void) const;
498
500 void a_d(unsigned int d);
502 unsigned int a_d(void) const;
503
505 void d_l(unsigned int d);
507 unsigned int d_l(void) const;
508
510 void node(unsigned int n);
512 unsigned int node(void) const;
513
515 void fail(unsigned int n);
517 unsigned int fail(void) const;
518
520 void time(unsigned int t);
522 unsigned int time(void) const;
523
525 void assets(unsigned int n);
527 unsigned int assets(void) const;
528
530 void slice(unsigned int n);
532 unsigned int slice(void) const;
533
535 void restart(RestartMode r);
537 RestartMode restart(void) const;
538
540 void restart_base(double base);
542 double restart_base(void) const;
543
545 void restart_scale(unsigned int scale);
547 unsigned int restart_scale(void) const;
548
550 void nogoods(bool b);
552 bool nogoods(void) const;
553
555 void nogoods_limit(unsigned int l);
557 unsigned int nogoods_limit(void) const;
558
560 void relax(double d);
562 double relax(void) const;
563
565 void interrupt(bool b);
567 bool interrupt(void) const;
569
571
572
573 void mode(ScriptMode em);
575 ScriptMode mode(void) const;
576
578 void samples(unsigned int s);
580 unsigned int samples(void) const;
581
583 void iterations(unsigned int i);
585 unsigned int iterations(void) const;
586
588 void print_last(bool p);
590 bool print_last(void) const;
591
593 void out_file(const char* f);
595 const char* out_file(void) const;
596
598 void log_file(const char* f);
600 const char* log_file(void) const;
601
603 void trace(int f);
605 int trace(void) const;
606
607#ifdef GECODE_HAS_CPPROFILER
609 void profiler_id(int i);
611 int profiler_id(void) const;
613 void profiler_port(unsigned int p);
615 unsigned int profiler_port(void) const;
617 void profiler_info(bool b);
619 bool profiler_info(void) const;
620#endif
622
623#ifdef GECODE_HAS_GIST
625 class _I {
626 private:
630 unsigned int n_click;
634 unsigned int n_solution;
638 unsigned int n_move;
642 unsigned int n_compare;
643 public:
645 _I(void);
647 void click(Gist::Inspector* i);
649 void solution(Gist::Inspector* i);
651 void move(Gist::Inspector* i);
653 void compare(Gist::Comparator* i);
654
656 Gist::Inspector* click(unsigned int i) const;
658 Gist::Inspector* solution(unsigned int i) const;
660 Gist::Inspector* move(unsigned int i) const;
662 Gist::Comparator* compare(unsigned int i) const;
663 } inspect;
664#endif
665 };
666
667}
668
669namespace Gecode {
670
676 protected:
677 unsigned int _size;
678 public:
680 SizeOptions(const char* s);
682 virtual void help(void);
684 void parse(int& argc, char* argv[]);
685
687 void size(unsigned int s);
689 unsigned int size(void) const;
690 };
691
697 protected:
698 const char* _inst;
699 public:
701 InstanceOptions(const char* s);
703 virtual void help(void);
705 void parse(int& argc, char* argv[]);
706
708 void instance(const char* s);
710 const char* instance(void) const;
712 ~InstanceOptions(void);
713 };
714
715}
716
718
719namespace Gecode { namespace Driver {
720
728 template<class BaseSpace>
729 class ScriptBase : public BaseSpace {
730 public:
732 ScriptBase(const Options& opt);
736 virtual void print(std::ostream& os) const;
738 virtual void compare(const Space& home, std::ostream& os) const;
740 static std::ostream& select_ostream(const char* sn, std::ofstream& ofs);
750 template<class Script, template<class> class Engine, class Options>
751 static void run(const Options& opt, Script* s=NULL);
752 private:
753 template<class Script, template<class> class Engine, class Options,
754 template<class, template<class> class> class Meta>
755 static void runMeta(const Options& opt, Script* s);
756 };
757
758#ifdef GECODE_HAS_FLOAT_VARS
759
761 template<class BaseSpace>
762 class ExtractStepOption : public BaseSpace {
763 public:
766 : BaseSpace(opt.step()) {}
768 ExtractStepOption(BaseSpace& e)
769 : BaseSpace(e) {}
770 };
771
772#endif
773
775 template<class BaseSpace>
776 class IgnoreStepOption : public BaseSpace {
777 public:
781 IgnoreStepOption(BaseSpace& e)
782 : BaseSpace(e) {}
783 };
784
785}}
786
788
789namespace Gecode {
790
800 typedef Driver::ScriptBase<Driver::IgnoreStepOption<Space> >
802
815
828
829#ifdef GECODE_HAS_FLOAT_VARS
830
843
844#endif
845
846}
847
848#endif
849
850// STATISTICS: driver-any
NNF * l
Left subtree.
struct Gecode::@603::NNF::@65::@66 b
For binary nodes (and, or, eqv)
NodeType t
Type of node.
int p
Number of positive literals for node type.
int n
Number of negative literals for node type.
NNF * r
Right subtree.
Base class for script options.
Definition driver.hh:331
const char * _name
Script name.
Definition driver.hh:335
Driver::BaseOption * fst
First registered option.
Definition driver.hh:333
Driver::BaseOption * lst
Last registered option.
Definition driver.hh:334
Base class for options.
Definition driver.hh:121
virtual void help(void)=0
Print help text.
const char * eopt
String for option (excluding hyphen)
Definition driver.hh:124
const char * exp
Short explanation.
Definition driver.hh:126
const char * iopt
String for option (including hyphen)
Definition driver.hh:125
virtual int parse(int argc, char *argv[])=0
Parse option at first position and return number of parsed arguments.
BaseOption * next
Next option Check for option and return its argument.
Definition driver.hh:127
Boolean option.
Definition driver.hh:269
bool cur
Current value.
Definition driver.hh:271
double cur
Current value.
Definition driver.hh:251
Class to extract the step option value.
Definition driver.hh:762
ExtractStepOption(BaseSpace &e)
Constructor used for cloning.
Definition driver.hh:768
ExtractStepOption(const Options &opt)
Constructor that extracts the step value.
Definition driver.hh:765
Class to ignore the step option value.
Definition driver.hh:776
IgnoreStepOption(BaseSpace &e)
Constructor used for cloning.
Definition driver.hh:781
IgnoreStepOption(const Options &)
Constructor.
Definition driver.hh:779
Integer option.
Definition driver.hh:209
int cur
Current value.
Definition driver.hh:211
Integer propagation level option.
Definition driver.hh:289
IntPropLevel cur
Current value.
Definition driver.hh:291
Parametric base-class for scripts.
Definition driver.hh:729
static void run(const Options &opt, Script *s=NULL)
Definition script.hpp:290
virtual void compare(const Space &home, std::ostream &os) const
Compare with s.
Definition script.hpp:243
virtual void print(std::ostream &os) const
Print a solution to os.
Definition script.hpp:239
static std::ostream & select_ostream(const char *sn, std::ofstream &ofs)
Choose output stream according to sn.
Definition script.hpp:247
ScriptBase(const Options &opt)
Constructor.
Definition script.hpp:229
const char * help
Optional help text.
Definition driver.hh:181
Value * next
Next option value.
Definition driver.hh:182
int val
Value for an option value.
Definition driver.hh:179
const char * opt
String for option value.
Definition driver.hh:180
String-valued option (integer value defined by strings)
Definition driver.hh:174
int cur
Current value.
Definition driver.hh:184
Value * lst
Last option value.
Definition driver.hh:186
Value * fst
First option value.
Definition driver.hh:185
String-valued option.
Definition driver.hh:151
const char * cur
Current value.
Definition driver.hh:153
Trace flag option.
Definition driver.hh:309
int cur
Current value.
Definition driver.hh:311
Unsigned integer option.
Definition driver.hh:229
unsigned int cur
Current value.
Definition driver.hh:231
Abstract base class for comparators.
Definition gist.hh:119
Abstract base class for inspectors.
Definition gist.hh:99
Options for scripts with additional instance parameter
Definition driver.hh:696
const char * _inst
Instance string.
Definition driver.hh:698
Helper class storing Gist inspectors.
Definition driver.hh:625
Options for scripts
Definition driver.hh:366
Driver::DoubleOption _relax
Probability to relax variable.
Definition driver.hh:398
Driver::StringValueOption _log_file
Where to print statistics.
Definition driver.hh:409
Driver::StringOption _model
General model options.
Definition driver.hh:370
Driver::StringOption _mode
Script mode to run.
Definition driver.hh:404
Driver::DoubleOption _decay
Decay option.
Definition driver.hh:375
Driver::UnsignedIntOption _nogoods_limit
Limit for no-good extraction.
Definition driver.hh:397
Driver::BoolOption _nogoods
Whether to use no-goods.
Definition driver.hh:396
Driver::UnsignedIntOption _slice
Size of a portfolio slice.
Definition driver.hh:392
Driver::TraceOption _trace
Trace flags for tracing.
Definition driver.hh:410
Driver::UnsignedIntOption _d_l
Discrepancy limit for LDS.
Definition driver.hh:387
Driver::UnsignedIntOption _assets
Number of assets in a portfolio.
Definition driver.hh:391
Driver::UnsignedIntOption _solutions
How many solutions.
Definition driver.hh:383
Driver::UnsignedIntOption _iterations
How many iterations per sample.
Definition driver.hh:406
Driver::StringOption _search
Search options.
Definition driver.hh:382
Driver::StringOption _propagation
Propagation options.
Definition driver.hh:372
Driver::IplOption _ipl
Integer propagation level.
Definition driver.hh:373
Driver::BoolOption _profiler_info
Whether solution information should be sent to the CPProfiler.
Definition driver.hh:415
Driver::BoolOption _print_last
Print only last solution found.
Definition driver.hh:407
Driver::UnsignedIntOption _c_d
Copy recomputation distance.
Definition driver.hh:385
Driver::DoubleOption _threads
How many threads to use.
Definition driver.hh:384
Driver::StringOption _branching
Branching options.
Definition driver.hh:374
Driver::StringOption _restart
Restart method option.
Definition driver.hh:393
Driver::UnsignedIntOption _seed
Seed option.
Definition driver.hh:376
Driver::UnsignedIntOption _time
Cutoff for time.
Definition driver.hh:390
Driver::DoubleOption _step
Step option.
Definition driver.hh:377
Driver::UnsignedIntOption _profiler_port
Connect to this port.
Definition driver.hh:414
Driver::UnsignedIntOption _r_scale
Restart scale factor.
Definition driver.hh:395
Driver::IntOption _profiler_id
Use this execution id for the CP-profiler.
Definition driver.hh:413
Driver::BoolOption _interrupt
Whether to catch SIGINT.
Definition driver.hh:399
Driver::UnsignedIntOption _a_d
Adaptive recomputation distance.
Definition driver.hh:386
Driver::DoubleOption _r_base
Restart base.
Definition driver.hh:394
Driver::StringOption _symmetry
General symmetry options.
Definition driver.hh:371
Driver::StringValueOption _out_file
Where to print solutions.
Definition driver.hh:408
Driver::UnsignedIntOption _node
Cutoff for number of nodes.
Definition driver.hh:388
Driver::UnsignedIntOption _samples
How many samples.
Definition driver.hh:405
Driver::UnsignedIntOption _fail
Cutoff for number of failures.
Definition driver.hh:389
Options for scripts with additional size parameter
Definition driver.hh:675
unsigned int _size
Size value.
Definition driver.hh:677
Computation spaces.
Definition core.hpp:1742
Array with arbitrary number of elements.
#define GECODE_DRIVER_EXPORT
Definition driver.hh:61
ScriptMode
Different modes for executing scripts.
Definition driver.hh:94
RestartMode
Different modes for restart-based search.
Definition driver.hh:106
@ SM_STAT
Print statistics for script.
Definition driver.hh:97
@ SM_SOLUTION
Print solution and some statistics.
Definition driver.hh:95
@ SM_GIST
Run script in Gist.
Definition driver.hh:98
@ SM_CPPROFILER
Run script with CP-profiler.
Definition driver.hh:99
@ SM_TIME
Measure average runtime.
Definition driver.hh:96
@ RM_CONSTANT
Restart with constant sequence.
Definition driver.hh:108
@ RM_LINEAR
Restart with linear sequence.
Definition driver.hh:109
@ RM_LUBY
Restart with Luby sequence.
Definition driver.hh:110
@ RM_NONE
No restarts.
Definition driver.hh:107
@ RM_GEOMETRIC
Restart with geometric sequence.
Definition driver.hh:111
Driver::ScriptBase< Driver::IgnoreStepOption< IntMaximizeSpace > > IntMaximizeScript
Base-class for scripts for finding solution of highest integer cost.
Definition driver.hh:814
Driver::ScriptBase< Driver::IgnoreStepOption< Space > > Script
Base-class for scripts.
Definition driver.hh:801
Driver::ScriptBase< Driver::ExtractStepOption< FloatMinimizeSpace > > FloatMinimizeScript
Base-class for scripts for finding solution of lowest float cost.
Definition driver.hh:836
Driver::ScriptBase< Driver::ExtractStepOption< FloatMaximizeSpace > > FloatMaximizeScript
Base-class for scripts for finding solution of highest float cost.
Definition driver.hh:842
Driver::ScriptBase< Driver::IgnoreStepOption< IntLexMaximizeSpace > > IntLexMaximizeScript
Base-class for scripts for finding solution of lexically highest integer costs.
Definition driver.hh:827
Driver::ScriptBase< Driver::IgnoreStepOption< IntLexMinimizeSpace > > IntLexMinimizeScript
Base-class for scripts for finding solution of lexically lowest integer costs.
Definition driver.hh:821
Driver::ScriptBase< Driver::IgnoreStepOption< IntMinimizeSpace > > IntMinimizeScript
Base-class for scripts for finding solution of lowest integer cost.
Definition driver.hh:808
GECODE_FLOAT_EXPORT void trace(Home home, const FloatVarArgs &x, TraceFilter tf, int te=(TE_INIT|TE_PRUNE|TE_FIX|TE_FAIL|TE_DONE), FloatTracer &t=StdFloatTracer::def)
Create a tracer for float variables.
Definition trace.cpp:39
IntPropLevel
Propagation levels for integer propagators.
Definition int.hh:974
Gecode toplevel namespace
GECODE_FLOAT_EXPORT void relax(Home home, const FloatVarArgs &x, const FloatVarArgs &sx, Rnd r, double p)
Definition relax.cpp:57