Generated on Thu Mar 16 2017 03:24:14 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  * Last modified:
10  * $Date: 2016-10-23 14:09:24 +0200 (Sun, 23 Oct 2016) $ by $Author: schulte $
11  * $Revision: 15218 $
12  *
13  * This file is part of Gecode, the generic constraint
14  * development environment:
15  * http://www.gecode.org
16  *
17  * Permission is hereby granted, free of charge, to any person obtaining
18  * a copy of this software and associated documentation files (the
19  * "Software"), to deal in the Software without restriction, including
20  * without limitation the rights to use, copy, modify, merge, publish,
21  * distribute, sublicense, and/or sell copies of the Software, and to
22  * permit persons to whom the Software is furnished to do so, subject to
23  * the following conditions:
24  *
25  * The above copyright notice and this permission notice shall be
26  * included in all copies or substantial portions of the Software.
27  *
28  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35  *
36  */
37 
38 #ifndef __GECODE_DRIVER_HH__
39 #define __GECODE_DRIVER_HH__
40 
41 #include <gecode/minimodel.hh>
42 #include <gecode/search.hh>
43 #ifdef GECODE_HAS_GIST
44 #include <gecode/gist.hh>
45 #endif
46 
47 /*
48  * Configure linking
49  *
50  */
51 #if !defined(GECODE_STATIC_LIBS) && \
52  (defined(__CYGWIN__) || defined(__MINGW32__) || defined(_MSC_VER))
53 
54 #ifdef GECODE_BUILD_DRIVER
55 #define GECODE_DRIVER_EXPORT __declspec( dllexport )
56 #else
57 #define GECODE_DRIVER_EXPORT __declspec( dllimport )
58 #endif
59 
60 #else
61 
62 #ifdef GECODE_GCC_HAS_CLASS_VISIBILITY
63 #define GECODE_DRIVER_EXPORT __attribute__ ((visibility("default")))
64 #else
65 #define GECODE_DRIVER_EXPORT
66 #endif
67 
68 #endif
69 
70 // Configure auto-linking
71 #ifndef GECODE_BUILD_DRIVER
72 #define GECODE_LIBRARY_NAME "Driver"
74 #endif
75 
86 namespace Gecode {
87 
88 
98  enum ScriptMode {
103  };
104 
109  enum RestartMode {
115  };
116 
117  class BaseOptions;
118 
119  namespace Driver {
125  friend class Gecode::BaseOptions;
126  protected:
127  const char* opt;
128  const char* exp;
130  char* argument(int argc, char* argv[]) const;
132  public:
134  BaseOption(const char* o, const char* e);
136  virtual int parse(int argc, char* argv[]) = 0;
138  virtual void help(void) = 0;
140  virtual ~BaseOption(void);
142  static char* strdup(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 
413  public:
415  Options(const char* s);
416 
418 
419  void model(int v);
422  void model(int v, const char* o, const char* h = NULL);
424  int model(void) const;
425 
427  void symmetry(int v);
429  void symmetry(int v, const char* o, const char* h = NULL);
431  int symmetry(void) const;
432 
434  void propagation(int v);
436  void propagation(int v, const char* o, const char* h = NULL);
438  int propagation(void) const;
439 
441  void ipl(IntPropLevel i);
443  IntPropLevel ipl(void) const;
444 
446  void branching(int v);
448  void branching(int v, const char* o, const char* h = NULL);
450  int branching(void) const;
451 
453  void decay(double d);
455  double decay(void) const;
456 
458  void seed(unsigned int s);
460  unsigned int seed(void) const;
461 
463  void step(double s);
465  double step(void) const;
467 
469 
470  void search(int v);
473  void search(int v, const char* o, const char* h = NULL);
475  int search(void) const;
476 
478  void solutions(unsigned int n);
480  unsigned int solutions(void) const;
481 
483  void threads(double n);
485  double threads(void) const;
486 
488  void c_d(unsigned int d);
490  unsigned int c_d(void) const;
491 
493  void a_d(unsigned int d);
495  unsigned int a_d(void) const;
496 
498  void d_l(unsigned int d);
500  unsigned int d_l(void) const;
501 
503  void node(unsigned int n);
505  unsigned int node(void) const;
506 
508  void fail(unsigned int n);
510  unsigned int fail(void) const;
511 
513  void time(unsigned int t);
515  unsigned int time(void) const;
516 
518  void assets(unsigned int n);
520  unsigned int assets(void) const;
521 
523  void slice(unsigned int n);
525  unsigned int slice(void) const;
526 
528  void restart(RestartMode r);
530  RestartMode restart(void) const;
531 
533  void restart_base(double base);
535  double restart_base(void) const;
536 
538  void restart_scale(unsigned int scale);
540  unsigned int restart_scale(void) const;
541 
543  void nogoods(bool b);
545  bool nogoods(void) const;
546 
548  void nogoods_limit(unsigned int l);
550  unsigned int nogoods_limit(void) const;
551 
553  void relax(double d);
555  double relax(void) const;
556 
558  void interrupt(bool b);
560  bool interrupt(void) const;
562 
564 
565  void mode(ScriptMode em);
568  ScriptMode mode(void) const;
569 
571  void samples(unsigned int s);
573  unsigned int samples(void) const;
574 
576  void iterations(unsigned int i);
578  unsigned int iterations(void) const;
579 
581  void print_last(bool p);
583  bool print_last(void) const;
584 
586  void out_file(const char* f);
588  const char* out_file(void) const;
589 
591  void log_file(const char* f);
593  const char* log_file(void) const;
594 
596  void trace(int f);
598  int trace(void) const;
600 
601 #ifdef GECODE_HAS_GIST
602  class _I {
604  private:
608  unsigned int n_click;
612  unsigned int n_solution;
616  unsigned int n_move;
620  unsigned int n_compare;
621  public:
623  _I(void);
625  void click(Gist::Inspector* i);
627  void solution(Gist::Inspector* i);
629  void move(Gist::Inspector* i);
631  void compare(Gist::Comparator* i);
632 
634  Gist::Inspector* click(unsigned int i) const;
636  Gist::Inspector* solution(unsigned int i) const;
638  Gist::Inspector* move(unsigned int i) const;
640  Gist::Comparator* compare(unsigned int i) const;
641  } inspect;
642 #endif
643  };
644 
650  protected:
651  unsigned int _size;
652  public:
654  SizeOptions(const char* s);
656  virtual void help(void);
658  void parse(int& argc, char* argv[]);
659 
661  void size(unsigned int s);
663  unsigned int size(void) const;
664  };
665 
671  protected:
672  const char* _inst;
673  public:
675  InstanceOptions(const char* s);
677  virtual void help(void);
679  void parse(int& argc, char* argv[]);
680 
682  void instance(const char* s);
684  const char* instance(void) const;
686  ~InstanceOptions(void);
687  };
688 
689 }
690 
691 #include <gecode/driver/options.hpp>
692 
693 namespace Gecode { namespace Driver {
694 
702  template<class BaseSpace>
703  class ScriptBase : public BaseSpace {
704  public:
706  ScriptBase(const Options& opt);
708  ScriptBase(bool share, ScriptBase& e);
710  virtual void print(std::ostream& os) const;
712  virtual void compare(const Space& home, std::ostream& os) const;
714  static std::ostream& select_ostream(const char* sn, std::ofstream& ofs);
724  template<class Script, template<class> class Engine, class Options>
725  static void run(const Options& opt, Script* s=NULL);
726  private:
727  template<class Script, template<class> class Engine, class Options,
728  template<class, template<class> class> class Meta>
729  static void runMeta(const Options& opt, Script* s);
731  explicit ScriptBase(ScriptBase& e);
732  };
733 
734 #ifdef GECODE_HAS_FLOAT_VARS
735 
737  template<class BaseSpace>
738  class ExtractStepOption : public BaseSpace {
739  public:
742  : BaseSpace(opt.step()) {}
744  ExtractStepOption(bool share, BaseSpace& e)
745  : BaseSpace(share,e) {}
746  };
747 
748 #endif
749 
751  template<class BaseSpace>
752  class IgnoreStepOption : public BaseSpace {
753  public:
757  IgnoreStepOption(bool share, BaseSpace& e)
758  : BaseSpace(share,e) {}
759  };
760 
761 
762 }}
763 
764 #include <gecode/driver/script.hpp>
765 
766 namespace Gecode {
767 
803 
804 #ifdef GECODE_HAS_FLOAT_VARS
805 
818 
819 #endif
820 
821 }
822 
823 #endif
824 
825 // STATISTICS: driver-any
Driver::ScriptBase< Driver::IgnoreStepOption< MaximizeSpace > > MaximizeScript
Base-class for scripts for finding solution of highest integer cost.
Definition: driver.hh:790
Driver::UnsignedIntOption _c_d
Copy recomputation distance.
Definition: driver.hh:385
Restart with linear sequence.
Definition: driver.hh:112
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:649
const Gecode::FloatNum step
Definition: arithmetic.cpp:789
Helper class storing Gist inspectors.
Definition: driver.hh:603
NodeType t
Type of node.
Definition: bool-expr.cpp:234
Driver::ScriptBase< Driver::IgnoreStepOption< MinimizeSpace > > MinimizeScript
Base-class for scripts for finding solution of lowest integer cost.
Definition: driver.hh:784
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:741
NNF * l
Left subtree.
Definition: bool-expr.cpp:244
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
void trace(Home home, const FloatVarArgs &x, TraceFilter tf, int te, FloatTracer &t)
Create a tracer for float variables.
Definition: trace.cpp:43
Class to extract the step option value.
Definition: driver.hh:738
ScriptMode
Different modes for executing scripts.
Definition: driver.hh:98
const char * exp
Short explanation.
Definition: driver.hh:128
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:123
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
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:752
Driver::UnsignedIntOption _d_l
Discrepancy limit for LDS.
Definition: driver.hh:387
Value * lst
Last option value.
Definition: driver.hh:186
Array with arbitrary number of elements.
Base class for options.
Definition: driver.hh:124
Restart with Luby sequence.
Definition: driver.hh:113
No restarts.
Definition: driver.hh:110
Driver::ScriptBase< Driver::IgnoreStepOption< IntMinimizeSpace > > IntMinimizeScript
Base-class for scripts for finding solution of lowest integer cost.
Definition: driver.hh:796
IgnoreStepOption(bool share, BaseSpace &e)
Constructor used for cloning.
Definition: driver.hh:757
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:817
RestartMode
Different modes for restart-based search.
Definition: driver.hh:109
Computation spaces.
Definition: core.hpp:1672
Abstract base class for inspectors.
Definition: gist.hh:103
Parametric base-class for scripts.
Definition: driver.hh:703
String-valued option.
Definition: driver.hh:151
GECODE_FLATZINC_EXPORT FlatZincSpace * parse(const std::string &fileName, Printer &p, std::ostream &err=std::cerr, FlatZincSpace *fzs=NULL, FznRnd *rnd=NULL)
Parse FlatZinc file fileName into fzs and return it.
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:651
Integer propagation level option.
Definition: driver.hh:289
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:236
Gecode::IntArgs i(4, 1, 2, 3, 4)
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
Driver::ScriptBase< Driver::ExtractStepOption< FloatMinimizeSpace > > FloatMinimizeScript
Base-class for scripts for finding solution of lowest float cost.
Definition: driver.hh:811
Options opt
The options.
Definition: test.cpp:101
Driver::UnsignedIntOption _fail
Cutoff for number of failures.
Definition: driver.hh:389
Print solution and some statistics.
Definition: driver.hh:99
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
NNF * r
Right subtree.
Definition: bool-expr.cpp:246
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:111
Simple propagation levels.
Definition: int.hh:943
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
unsigned int size(I &i)
Size of all ranges of range iterator i.
Measure average runtime.
Definition: driver.hh:100
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:129
const unsigned int d_l
Default discrepancy limit for LDS.
Definition: search.hh:119
#define GECODE_DRIVER_EXPORT
Definition: driver.hh:65
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:106
int val
Value for an option value.
Definition: driver.hh:179
Driver::DoubleOption _relax
Probability to relax variable.
Definition: driver.hh:398
const int v[7]
Definition: distinct.cpp:263
String-valued option (integer value defined by strings)
Definition: driver.hh:174
ExtractStepOption(bool share, BaseSpace &e)
Constructor used for cloning.
Definition: driver.hh:744
IntPropLevel
Propagation levels for integer propagators.
Definition: int.hh:941
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:67
Driver::ScriptBase< Driver::IgnoreStepOption< IntMaximizeSpace > > IntMaximizeScript
Base-class for scripts for finding solution of highest integer cost.
Definition: driver.hh:802
void relax(Home home, const FloatVarArgs &x, const FloatVarArgs &sx, Rnd r, double p)
Definition: relax.cpp:61
const double base
Base for geometric restart sequence.
Definition: search.hh:122
Print statistics for script.
Definition: driver.hh:101
Options for scripts with additional instance parameter
Definition: driver.hh:670
Driver::TraceOption _trace
Trace flags for tracing.
Definition: driver.hh:410
Restart with geometric sequence.
Definition: driver.hh:114
const char * opt
String for option (including hyphen)
Definition: driver.hh:127
Driver::StringValueOption _out_file
Where to print solutions.
Definition: driver.hh:408
Driver::BaseOption * fst
First registered option.
Definition: driver.hh:333
const char * _inst
Instance string.
Definition: driver.hh:672
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:102
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:109
Trace flag option.
Definition: driver.hh:309
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:755
const unsigned int nogoods_limit
Depth limit for no-good generation during search.
Definition: search.hh:127
struct Gecode::@554::NNF::@60::@61 b
For binary nodes (and, or, eqv)
Options for scripts
Definition: driver.hh:366
Restart with constant sequence.
Definition: driver.hh:111
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:124
Driver::ScriptBase< Driver::IgnoreStepOption< Space > > Script
Base-class for scripts.
Definition: driver.hh:778
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:379
Driver::UnsignedIntOption _slice
Size of a portfolio slice.
Definition: driver.hh:392
virtual void help(void)
Print help text.
Definition: options.cpp:430