Generated on Sat Oct 20 2018 12:43:45 for Gecode by doxygen 1.8.13
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 
82 namespace Gecode {
83 
84 
94  enum ScriptMode {
100  };
101 
106  enum RestartMode {
112  };
113 
114  class BaseOptions;
115 
116  namespace Driver {
122  friend class Gecode::BaseOptions;
123  protected:
124  const char* eopt;
125  const char* iopt;
126  const char* exp;
128  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:
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 
378 
379 
381 
400 
401 
403 
411 
412 #ifdef GECODE_HAS_CPPROFILER
416 #endif
417 
419 
420  public:
422  Options(const char* s);
423 
425 
426  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  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  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
608  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
621 
622 
623 #ifdef GECODE_HAS_GIST
624  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 
669 namespace 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 
717 #include <gecode/driver/options.hpp>
718 
719 namespace 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 
787 #include <gecode/driver/script.hpp>
788 
789 namespace Gecode {
790 
802 
815 
828 
829 #ifdef GECODE_HAS_FLOAT_VARS
830 
843 
844 #endif
845 
846 }
847 
848 #endif
849 
850 // STATISTICS: driver-any
Driver::UnsignedIntOption _c_d
Copy recomputation distance.
Definition: driver.hh:385
Restart with linear sequence.
Definition: driver.hh:109
Driver::BoolOption _interrupt
Whether to catch SIGINT.
Definition: driver.hh:399
int cur
Current value.
Definition: driver.hh:184
Options for scripts with additional size parameter
Definition: driver.hh:675
const Gecode::FloatNum step
Definition: arithmetic.cpp:785
Helper class storing Gist inspectors.
Definition: driver.hh:625
NodeType t
Type of node.
Definition: bool-expr.cpp:230
Driver::UnsignedIntOption _iterations
How many iterations per sample.
Definition: driver.hh:406
ExtractStepOption(const Options &opt)
Constructor that extracts the step value.
Definition: driver.hh:765
NNF * l
Left subtree.
Definition: bool-expr.cpp:240
Driver::DoubleOption _decay
Decay option.
Definition: driver.hh:375
unsigned int cur
Current value.
Definition: driver.hh:231
Driver::DoubleOption _step
Step option.
Definition: driver.hh:377
Class to extract the step option value.
Definition: driver.hh:762
ExtractStepOption(BaseSpace &e)
Constructor used for cloning.
Definition: driver.hh:768
ScriptMode
Different modes for executing scripts.
Definition: driver.hh:94
const char * exp
Short explanation.
Definition: driver.hh:126
Value * next
Next option value.
Definition: driver.hh:182
const char * opt
String for option value.
Definition: driver.hh:180
Boolean option.
Definition: driver.hh:269
Abstract base class for comparators.
Definition: gist.hh:119
Driver::DoubleOption _threads
How many threads to use.
Definition: driver.hh:384
Driver::UnsignedIntOption _nogoods_limit
Limit for no-good extraction.
Definition: driver.hh:397
GECODE_FLATZINC_EXPORT FlatZincSpace * parse(const std::string &fileName, Printer &p, std::ostream &err=std::cerr, FlatZincSpace *fzs=NULL, Rnd &rnd=defrnd)
Parse FlatZinc file fileName into fzs and return it.
Driver::StringOption _restart
Restart method option.
Definition: driver.hh:393
Driver::BoolOption _nogoods
Whether to use no-goods.
Definition: driver.hh:396
Class to ignore the step option value.
Definition: driver.hh:776
Driver::UnsignedIntOption _d_l
Discrepancy limit for LDS.
Definition: driver.hh:387
Value * lst
Last option value.
Definition: driver.hh:186
Driver::UnsignedIntOption _profiler_port
Connect to this port.
Definition: driver.hh:414
Array with arbitrary number of elements.
Base class for options.
Definition: driver.hh:121
Restart with Luby sequence.
Definition: driver.hh:110
No restarts.
Definition: driver.hh:107
Driver::ScriptBase< Driver::IgnoreStepOption< IntMinimizeSpace > > IntMinimizeScript
Base-class for scripts for finding solution of lowest integer cost.
Definition: driver.hh:808
Driver::DoubleOption _r_base
Restart base.
Definition: driver.hh:394
Driver::ScriptBase< Driver::ExtractStepOption< FloatMaximizeSpace > > FloatMaximizeScript
Base-class for scripts for finding solution of highest float cost.
Definition: driver.hh:842
Driver::BoolOption _profiler_info
Whether solution information should be sent to the CPProfiler.
Definition: driver.hh:415
RestartMode
Different modes for restart-based search.
Definition: driver.hh:106
Computation spaces.
Definition: core.hpp:1701
Abstract base class for inspectors.
Definition: gist.hh:99
Parametric base-class for scripts.
Definition: driver.hh:729
String-valued option.
Definition: driver.hh:151
const char * iopt
String for option (including hyphen)
Definition: driver.hh:125
const char * eopt
String for option (excluding hyphen)
Definition: driver.hh:124
bool cur
Current value.
Definition: driver.hh:271
Gecode::IntSet d(v, 7)
Driver::StringOption _model
General model options.
Definition: driver.hh:370
unsigned int _size
Size value.
Definition: driver.hh:677
Integer propagation level option.
Definition: driver.hh:289
IgnoreStepOption(BaseSpace &e)
Constructor used for cloning.
Definition: driver.hh:781
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:232
Driver::ScriptBase< Driver::IgnoreStepOption< IntLexMaximizeSpace > > IntLexMaximizeScript
Base-class for scripts for finding solution of lexically highest integer costs.
Definition: driver.hh:827
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:234
Driver::ScriptBase< Driver::ExtractStepOption< FloatMinimizeSpace > > FloatMinimizeScript
Base-class for scripts for finding solution of lowest float cost.
Definition: driver.hh:836
Options opt
The options.
Definition: test.cpp:97
Driver::UnsignedIntOption _fail
Cutoff for number of failures.
Definition: driver.hh:389
Gecode::IntArgs i({1, 2, 3, 4})
Print solution and some statistics.
Definition: driver.hh:95
const char * help
Optional help text.
Definition: driver.hh:181
int cur
Current value.
Definition: driver.hh:311
Driver::UnsignedIntOption _samples
How many samples.
Definition: driver.hh:405
Driver::StringValueOption _log_file
Where to print statistics.
Definition: driver.hh:409
Driver::UnsignedIntOption _assets
Number of assets in a portfolio.
Definition: driver.hh:391
const unsigned int a_d
Create a clone during recomputation if distance is greater than a_d (adaptive distance) ...
Definition: search.hh:115
Simple propagation levels.
Definition: int.hh:976
Value * fst
First option value.
Definition: driver.hh:185
double cur
Current value.
Definition: driver.hh:251
Driver::StringOption _propagation
Propagation options.
Definition: driver.hh:372
Base class for script options.
Definition: driver.hh:331
const char * _name
Script name.
Definition: driver.hh:335
struct Gecode::@593::NNF::@62::@63 b
For binary nodes (and, or, eqv)
unsigned int size(I &i)
Size of all ranges of range iterator i.
Measure average runtime.
Definition: driver.hh:96
Unsigned integer option.
Definition: driver.hh:229
Driver::StringOption _search
Search options.
Definition: driver.hh:382
Driver::BoolOption _print_last
Print only last solution found.
Definition: driver.hh:407
BaseOption * next
Next option Check for option and return its argument.
Definition: driver.hh:127
const unsigned int d_l
Default discrepancy limit for LDS.
Definition: search.hh:123
#define GECODE_DRIVER_EXPORT
Definition: driver.hh:61
Driver::StringOption _symmetry
General symmetry options.
Definition: driver.hh:371
Driver::UnsignedIntOption _a_d
Adaptive recomputation distance.
Definition: driver.hh:386
Driver::UnsignedIntOption _time
Cutoff for time.
Definition: driver.hh:390
Driver::StringOption _mode
Script mode to run.
Definition: driver.hh:404
const double threads
Number of threads to use.
Definition: search.hh:110
int val
Value for an option value.
Definition: driver.hh:179
Driver::DoubleOption _relax
Probability to relax variable.
Definition: driver.hh:398
Driver::ScriptBase< Driver::IgnoreStepOption< IntLexMinimizeSpace > > IntLexMinimizeScript
Base-class for scripts for finding solution of lexically lowest integer costs.
Definition: driver.hh:821
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition: set.hh:767
const int v[7]
Definition: distinct.cpp:259
String-valued option (integer value defined by strings)
Definition: driver.hh:174
IntPropLevel
Propagation levels for integer propagators.
Definition: int.hh:974
void print(std::basic_ostream< Char, Traits > &s, bool assigned, IL &lb, IU &ub, unsigned int cardMin, unsigned int cardMax)
Print set view.
Definition: print.hpp:63
Post propagator for f(x \diamond_{\mathit{op}} y) \sim_r z \f$ void rel(Home home
Driver::ScriptBase< Driver::IgnoreStepOption< IntMaximizeSpace > > IntMaximizeScript
Base-class for scripts for finding solution of highest integer cost.
Definition: driver.hh:814
void relax(Home home, const FloatVarArgs &x, const FloatVarArgs &sx, Rnd r, double p)
Definition: relax.cpp:57
const double base
Base for geometric restart sequence.
Definition: search.hh:126
Print statistics for script.
Definition: driver.hh:97
Run script with CP-profiler.
Definition: driver.hh:99
Options for scripts with additional instance parameter
Definition: driver.hh:696
Driver::TraceOption _trace
Trace flags for tracing.
Definition: driver.hh:410
Restart with geometric sequence.
Definition: driver.hh:111
Driver::StringValueOption _out_file
Where to print solutions.
Definition: driver.hh:408
Driver::BaseOption * fst
First registered option.
Definition: driver.hh:333
Driver::IntOption _profiler_id
Use this execution id for the CP-profiler.
Definition: driver.hh:413
const char * _inst
Instance string.
Definition: driver.hh:698
Driver::UnsignedIntOption _solutions
How many solutions.
Definition: driver.hh:383
Driver::StringOption _branching
Branching options.
Definition: driver.hh:374
Run script in Gist.
Definition: driver.hh:98
IntPropLevel cur
Current value.
Definition: driver.hh:291
const char * cur
Current value.
Definition: driver.hh:153
Driver::BaseOption * lst
Last registered option.
Definition: driver.hh:334
const unsigned int c_d
Create a clone after every c_d commits (commit distance)
Definition: search.hh:113
Trace flag option.
Definition: driver.hh:309
void trace(Home home, const FloatVarArgs &x, TraceFilter tf, int te, FloatTracer &t)
Create a tracer for float variables.
Definition: trace.cpp:39
CompareStatus compare(I &i, J &j)
Check whether range iterator i is a subset of j, or whether they are disjoint.
Driver::IplOption _ipl
Integer propagation level.
Definition: driver.hh:373
int cur
Current value.
Definition: driver.hh:211
Gecode toplevel namespace
Driver::UnsignedIntOption _seed
Seed option.
Definition: driver.hh:376
IgnoreStepOption(const Options &)
Constructor.
Definition: driver.hh:779
const unsigned int nogoods_limit
Depth limit for no-good generation during search.
Definition: search.hh:131
Options for scripts
Definition: driver.hh:366
Restart with constant sequence.
Definition: driver.hh:108
Driver::UnsignedIntOption _r_scale
Restart scale factor.
Definition: driver.hh:395
Integer option.
Definition: driver.hh:209
const unsigned int slice
Size of a slice in a portfolio and scale factor for restarts(in number of failures) ...
Definition: search.hh:128
Driver::ScriptBase< Driver::IgnoreStepOption< Space > > Script
Base-class for scripts.
Definition: driver.hh:801
Driver::UnsignedIntOption _node
Cutoff for number of nodes.
Definition: driver.hh:388
int solutions(TestSpace *c, Gecode::Search::Options &o, int maxNbSol=-1)
Find number of solutions.
Definition: branch.cpp:412
Driver::UnsignedIntOption _slice
Size of a portfolio slice.
Definition: driver.hh:392
virtual void help(void)
Print help text.
Definition: options.cpp:486