Generated on Thu Apr 5 2018 19:44:19 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$ by $Author$
11  * $Revision$
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 {
104  };
105 
110  enum RestartMode {
116  };
117 
118  class BaseOptions;
119 
120  namespace Driver {
126  friend class Gecode::BaseOptions;
127  protected:
128  const char* eopt;
129  const char* iopt;
130  const char* exp;
132  char* argument(int argc, char* argv[]) const;
134  public:
136  BaseOption(const char* o, const char* e);
138  virtual int parse(int argc, char* argv[]) = 0;
140  virtual void help(void) = 0;
142  virtual ~BaseOption(void);
144  static char* strdup(const char* s);
146  static char* stredup(const char* s);
148  static void strdel(const char* s);
149  };
150 
156  protected:
157  const char* cur;
158  public:
160  StringValueOption(const char* o, const char* e, const char* v=NULL);
162  void value(const char* v);
164  const char* value(void) const;
166  virtual int parse(int argc, char* argv[]);
168  virtual void help(void);
170  virtual ~StringValueOption(void);
171  };
172 
173 
179  protected:
181  class Value {
182  public:
183  int val;
184  const char* opt;
185  const char* help;
187  };
188  int cur;
191  public:
193  StringOption(const char* o, const char* e, int v=0);
195  void value(int v);
197  int value(void) const;
199  void add(int v, const char* o, const char* h = NULL);
201  virtual int parse(int argc, char* argv[]);
203  virtual void help(void);
205  virtual ~StringOption(void);
206  };
207 
208 
214  protected:
215  int cur;
216  public:
218  IntOption(const char* o, const char* e, int v=0);
220  void value(int v);
222  int value(void) const;
224  virtual int parse(int argc, char* argv[]);
226  virtual void help(void);
227  };
228 
234  protected:
235  unsigned int cur;
236  public:
238  UnsignedIntOption(const char* o, const char* e, unsigned int v=0);
240  void value(unsigned int v);
242  unsigned int value(void) const;
244  virtual int parse(int argc, char* argv[]);
246  virtual void help(void);
247  };
248 
254  protected:
255  double cur;
256  public:
258  DoubleOption(const char* o, const char* e, double v=0);
260  void value(double v);
262  double value(void) const;
264  virtual int parse(int argc, char* argv[]);
266  virtual void help(void);
267  };
268 
274  protected:
275  bool cur;
276  public:
278  BoolOption(const char* o, const char* e, bool v=false);
280  void value(bool v);
282  bool value(void) const;
284  virtual int parse(int argc, char* argv[]);
286  virtual void help(void);
287  };
288 
294  protected:
296  public:
300  void value(IntPropLevel l);
302  IntPropLevel value(void) const;
304  virtual int parse(int argc, char* argv[]);
306  virtual void help(void);
307  };
308 
314  protected:
315  int cur;
316  public:
318  TraceOption(int f=0);
320  void value(int f);
322  int value(void) const;
324  virtual int parse(int argc, char* argv[]);
326  virtual void help(void);
327  };
328 
329  }
330 
336  protected:
339  const char* _name;
340  public:
342  BaseOptions(const char* s);
344  virtual void help(void);
345 
347  void add(Driver::BaseOption& o);
355  void parse(int& argc, char* argv[]);
356 
358  const char* name(void) const;
360  void name(const char*);
361 
363  virtual ~BaseOptions(void);
364  };
365 
371  protected:
373 
382 
383 
385 
404 
405 
407 
415 
416 #ifdef GECODE_HAS_CPPROFILER
420 #endif
421 
423 
424  public:
426  Options(const char* s);
427 
429 
430  void model(int v);
433  void model(int v, const char* o, const char* h = NULL);
435  int model(void) const;
436 
438  void symmetry(int v);
440  void symmetry(int v, const char* o, const char* h = NULL);
442  int symmetry(void) const;
443 
445  void propagation(int v);
447  void propagation(int v, const char* o, const char* h = NULL);
449  int propagation(void) const;
450 
452  void ipl(IntPropLevel i);
454  IntPropLevel ipl(void) const;
455 
457  void branching(int v);
459  void branching(int v, const char* o, const char* h = NULL);
461  int branching(void) const;
462 
464  void decay(double d);
466  double decay(void) const;
467 
469  void seed(unsigned int s);
471  unsigned int seed(void) const;
472 
474  void step(double s);
476  double step(void) const;
478 
480 
481  void search(int v);
484  void search(int v, const char* o, const char* h = NULL);
486  int search(void) const;
487 
489  void solutions(unsigned int n);
491  unsigned int solutions(void) const;
492 
494  void threads(double n);
496  double threads(void) const;
497 
499  void c_d(unsigned int d);
501  unsigned int c_d(void) const;
502 
504  void a_d(unsigned int d);
506  unsigned int a_d(void) const;
507 
509  void d_l(unsigned int d);
511  unsigned int d_l(void) const;
512 
514  void node(unsigned int n);
516  unsigned int node(void) const;
517 
519  void fail(unsigned int n);
521  unsigned int fail(void) const;
522 
524  void time(unsigned int t);
526  unsigned int time(void) const;
527 
529  void assets(unsigned int n);
531  unsigned int assets(void) const;
532 
534  void slice(unsigned int n);
536  unsigned int slice(void) const;
537 
539  void restart(RestartMode r);
541  RestartMode restart(void) const;
542 
544  void restart_base(double base);
546  double restart_base(void) const;
547 
549  void restart_scale(unsigned int scale);
551  unsigned int restart_scale(void) const;
552 
554  void nogoods(bool b);
556  bool nogoods(void) const;
557 
559  void nogoods_limit(unsigned int l);
561  unsigned int nogoods_limit(void) const;
562 
564  void relax(double d);
566  double relax(void) const;
567 
569  void interrupt(bool b);
571  bool interrupt(void) const;
573 
575 
576  void mode(ScriptMode em);
579  ScriptMode mode(void) const;
580 
582  void samples(unsigned int s);
584  unsigned int samples(void) const;
585 
587  void iterations(unsigned int i);
589  unsigned int iterations(void) const;
590 
592  void print_last(bool p);
594  bool print_last(void) const;
595 
597  void out_file(const char* f);
599  const char* out_file(void) const;
600 
602  void log_file(const char* f);
604  const char* log_file(void) const;
605 
607  void trace(int f);
609  int trace(void) const;
610 
611 #ifdef GECODE_HAS_CPPROFILER
612  void profiler_id(int i);
615  int profiler_id(void) const;
617  void profiler_port(unsigned int p);
619  unsigned int profiler_port(void) const;
621  void profiler_info(bool b);
623  bool profiler_info(void) const;
624 #endif
625 
626 
627 #ifdef GECODE_HAS_GIST
628  class _I {
630  private:
634  unsigned int n_click;
638  unsigned int n_solution;
642  unsigned int n_move;
646  unsigned int n_compare;
647  public:
649  _I(void);
651  void click(Gist::Inspector* i);
653  void solution(Gist::Inspector* i);
655  void move(Gist::Inspector* i);
657  void compare(Gist::Comparator* i);
658 
660  Gist::Inspector* click(unsigned int i) const;
662  Gist::Inspector* solution(unsigned int i) const;
664  Gist::Inspector* move(unsigned int i) const;
666  Gist::Comparator* compare(unsigned int i) const;
667  } inspect;
668 #endif
669  };
670 
671 }
672 
673 namespace Gecode {
674 
680  protected:
681  unsigned int _size;
682  public:
684  SizeOptions(const char* s);
686  virtual void help(void);
688  void parse(int& argc, char* argv[]);
689 
691  void size(unsigned int s);
693  unsigned int size(void) const;
694  };
695 
701  protected:
702  const char* _inst;
703  public:
705  InstanceOptions(const char* s);
707  virtual void help(void);
709  void parse(int& argc, char* argv[]);
710 
712  void instance(const char* s);
714  const char* instance(void) const;
716  ~InstanceOptions(void);
717  };
718 
719 }
720 
721 #include <gecode/driver/options.hpp>
722 
723 namespace Gecode { namespace Driver {
724 
732  template<class BaseSpace>
733  class ScriptBase : public BaseSpace {
734  public:
736  ScriptBase(const Options& opt);
740  virtual void print(std::ostream& os) const;
742  virtual void compare(const Space& home, std::ostream& os) const;
744  static std::ostream& select_ostream(const char* sn, std::ofstream& ofs);
754  template<class Script, template<class> class Engine, class Options>
755  static void run(const Options& opt, Script* s=NULL);
756  private:
757  template<class Script, template<class> class Engine, class Options,
758  template<class, template<class> class> class Meta>
759  static void runMeta(const Options& opt, Script* s);
760  };
761 
762 #ifdef GECODE_HAS_FLOAT_VARS
763 
765  template<class BaseSpace>
766  class ExtractStepOption : public BaseSpace {
767  public:
770  : BaseSpace(opt.step()) {}
772  ExtractStepOption(BaseSpace& e)
773  : BaseSpace(e) {}
774  };
775 
776 #endif
777 
779  template<class BaseSpace>
780  class IgnoreStepOption : public BaseSpace {
781  public:
785  IgnoreStepOption(BaseSpace& e)
786  : BaseSpace(e) {}
787  };
788 
789 }}
790 
791 #include <gecode/driver/script.hpp>
792 
793 namespace Gecode {
794 
806 
819 
832 
833 #ifdef GECODE_HAS_FLOAT_VARS
834 
847 
848 #endif
849 
850 }
851 
852 #endif
853 
854 // STATISTICS: driver-any
Driver::UnsignedIntOption _c_d
Copy recomputation distance.
Definition: driver.hh:389
Restart with linear sequence.
Definition: driver.hh:113
Driver::BoolOption _interrupt
Whether to catch SIGINT.
Definition: driver.hh:403
int cur
Current value.
Definition: driver.hh:188
Options for scripts with additional size parameter
Definition: driver.hh:679
const Gecode::FloatNum step
Definition: arithmetic.cpp:789
Helper class storing Gist inspectors.
Definition: driver.hh:629
NodeType t
Type of node.
Definition: bool-expr.cpp:234
Driver::UnsignedIntOption _iterations
How many iterations per sample.
Definition: driver.hh:410
ExtractStepOption(const Options &opt)
Constructor that extracts the step value.
Definition: driver.hh:769
NNF * l
Left subtree.
Definition: bool-expr.cpp:244
Driver::DoubleOption _decay
Decay option.
Definition: driver.hh:379
unsigned int cur
Current value.
Definition: driver.hh:235
Driver::DoubleOption _step
Step option.
Definition: driver.hh:381
Class to extract the step option value.
Definition: driver.hh:766
ExtractStepOption(BaseSpace &e)
Constructor used for cloning.
Definition: driver.hh:772
ScriptMode
Different modes for executing scripts.
Definition: driver.hh:98
const char * exp
Short explanation.
Definition: driver.hh:130
Value * next
Next option value.
Definition: driver.hh:186
const char * opt
String for option value.
Definition: driver.hh:184
Boolean option.
Definition: driver.hh:273
Abstract base class for comparators.
Definition: gist.hh:123
Driver::DoubleOption _threads
How many threads to use.
Definition: driver.hh:388
Driver::UnsignedIntOption _nogoods_limit
Limit for no-good extraction.
Definition: driver.hh:401
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:397
Driver::BoolOption _nogoods
Whether to use no-goods.
Definition: driver.hh:400
Class to ignore the step option value.
Definition: driver.hh:780
Driver::UnsignedIntOption _d_l
Discrepancy limit for LDS.
Definition: driver.hh:391
Value * lst
Last option value.
Definition: driver.hh:190
Driver::UnsignedIntOption _profiler_port
Connect to this port.
Definition: driver.hh:418
Array with arbitrary number of elements.
Base class for options.
Definition: driver.hh:125
Restart with Luby sequence.
Definition: driver.hh:114
No restarts.
Definition: driver.hh:111
Driver::ScriptBase< Driver::IgnoreStepOption< IntMinimizeSpace > > IntMinimizeScript
Base-class for scripts for finding solution of lowest integer cost.
Definition: driver.hh:812
Driver::DoubleOption _r_base
Restart base.
Definition: driver.hh:398
Driver::ScriptBase< Driver::ExtractStepOption< FloatMaximizeSpace > > FloatMaximizeScript
Base-class for scripts for finding solution of highest float cost.
Definition: driver.hh:846
Driver::BoolOption _profiler_info
Whether solution information should be sent to the CPProfiler.
Definition: driver.hh:419
RestartMode
Different modes for restart-based search.
Definition: driver.hh:110
Computation spaces.
Definition: core.hpp:1668
Abstract base class for inspectors.
Definition: gist.hh:103
Parametric base-class for scripts.
Definition: driver.hh:733
String-valued option.
Definition: driver.hh:155
const char * iopt
String for option (including hyphen)
Definition: driver.hh:129
const char * eopt
String for option (excluding hyphen)
Definition: driver.hh:128
bool cur
Current value.
Definition: driver.hh:275
Gecode::IntSet d(v, 7)
Driver::StringOption _model
General model options.
Definition: driver.hh:374
unsigned int _size
Size value.
Definition: driver.hh:681
Integer propagation level option.
Definition: driver.hh:293
IgnoreStepOption(BaseSpace &e)
Constructor used for cloning.
Definition: driver.hh:785
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:236
Gecode::IntArgs i(4, 1, 2, 3, 4)
Driver::ScriptBase< Driver::IgnoreStepOption< IntLexMaximizeSpace > > IntLexMaximizeScript
Base-class for scripts for finding solution of lexically highest integer costs.
Definition: driver.hh:831
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:840
Options opt
The options.
Definition: test.cpp:101
Driver::UnsignedIntOption _fail
Cutoff for number of failures.
Definition: driver.hh:393
Print solution and some statistics.
Definition: driver.hh:99
const char * help
Optional help text.
Definition: driver.hh:185
int cur
Current value.
Definition: driver.hh:315
Driver::UnsignedIntOption _samples
How many samples.
Definition: driver.hh:409
Driver::StringValueOption _log_file
Where to print statistics.
Definition: driver.hh:413
Driver::UnsignedIntOption _assets
Number of assets in a portfolio.
Definition: driver.hh:395
const unsigned int a_d
Create a clone during recomputation if distance is greater than a_d (adaptive distance) ...
Definition: search.hh:117
Simple propagation levels.
Definition: int.hh:955
Value * fst
First option value.
Definition: driver.hh:189
double cur
Current value.
Definition: driver.hh:255
Driver::StringOption _propagation
Propagation options.
Definition: driver.hh:376
Base class for script options.
Definition: driver.hh:335
const char * _name
Script name.
Definition: driver.hh:339
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:233
Driver::StringOption _search
Search options.
Definition: driver.hh:386
Driver::BoolOption _print_last
Print only last solution found.
Definition: driver.hh:411
BaseOption * next
Next option Check for option and return its argument.
Definition: driver.hh:131
const unsigned int d_l
Default discrepancy limit for LDS.
Definition: search.hh:125
#define GECODE_DRIVER_EXPORT
Definition: driver.hh:65
Driver::StringOption _symmetry
General symmetry options.
Definition: driver.hh:375
Driver::UnsignedIntOption _a_d
Adaptive recomputation distance.
Definition: driver.hh:390
Driver::UnsignedIntOption _time
Cutoff for time.
Definition: driver.hh:394
Driver::StringOption _mode
Script mode to run.
Definition: driver.hh:408
const double threads
Number of threads to use.
Definition: search.hh:112
int val
Value for an option value.
Definition: driver.hh:183
Driver::DoubleOption _relax
Probability to relax variable.
Definition: driver.hh:402
Driver::ScriptBase< Driver::IgnoreStepOption< IntLexMinimizeSpace > > IntLexMinimizeScript
Base-class for scripts for finding solution of lexically lowest integer costs.
Definition: driver.hh:825
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition: set.hh:769
const int v[7]
Definition: distinct.cpp:263
String-valued option (integer value defined by strings)
Definition: driver.hh:178
IntPropLevel
Propagation levels for integer propagators.
Definition: int.hh:953
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
struct Gecode::@585::NNF::@62::@63 b
For binary nodes (and, or, eqv)
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:818
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:128
Print statistics for script.
Definition: driver.hh:101
Run script with CP-profiler.
Definition: driver.hh:103
Options for scripts with additional instance parameter
Definition: driver.hh:700
Driver::TraceOption _trace
Trace flags for tracing.
Definition: driver.hh:414
Restart with geometric sequence.
Definition: driver.hh:115
Driver::StringValueOption _out_file
Where to print solutions.
Definition: driver.hh:412
Driver::BaseOption * fst
First registered option.
Definition: driver.hh:337
Driver::IntOption _profiler_id
Use this execution id for the CP-profiler.
Definition: driver.hh:417
const char * _inst
Instance string.
Definition: driver.hh:702
Driver::UnsignedIntOption _solutions
How many solutions.
Definition: driver.hh:387
Driver::StringOption _branching
Branching options.
Definition: driver.hh:378
Run script in Gist.
Definition: driver.hh:102
IntPropLevel cur
Current value.
Definition: driver.hh:295
const char * cur
Current value.
Definition: driver.hh:157
Driver::BaseOption * lst
Last registered option.
Definition: driver.hh:338
const unsigned int c_d
Create a clone after every c_d commits (commit distance)
Definition: search.hh:115
Trace flag option.
Definition: driver.hh:313
void trace(Home home, const FloatVarArgs &x, TraceFilter tf, int te, FloatTracer &t)
Create a tracer for float variables.
Definition: trace.cpp:43
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:377
int cur
Current value.
Definition: driver.hh:215
Gecode toplevel namespace
Driver::UnsignedIntOption _seed
Seed option.
Definition: driver.hh:380
IgnoreStepOption(const Options &)
Constructor.
Definition: driver.hh:783
const unsigned int nogoods_limit
Depth limit for no-good generation during search.
Definition: search.hh:133
Options for scripts
Definition: driver.hh:370
Restart with constant sequence.
Definition: driver.hh:112
Driver::UnsignedIntOption _r_scale
Restart scale factor.
Definition: driver.hh:399
Integer option.
Definition: driver.hh:213
const unsigned int slice
Size of a slice in a portfolio and scale factor for restarts(in number of failures) ...
Definition: search.hh:130
Driver::ScriptBase< Driver::IgnoreStepOption< Space > > Script
Base-class for scripts.
Definition: driver.hh:805
Driver::UnsignedIntOption _node
Cutoff for number of nodes.
Definition: driver.hh:392
int solutions(TestSpace *c, Gecode::Search::Options &o, int maxNbSol=-1)
Find number of solutions.
Definition: branch.cpp:416
Driver::UnsignedIntOption _slice
Size of a portfolio slice.
Definition: driver.hh:396
virtual void help(void)
Print help text.
Definition: options.cpp:490