Generated on Tue May 31 2016 10:19:12 for Gecode by doxygen 1.8.11
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: 2015-03-19 11:42:29 +0100 (Thu, 19 Mar 2015) $ by $Author: tack $
11  * $Revision: 14462 $
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 
285  }
286 
292  protected:
295  const char* _name;
296  public:
298  BaseOptions(const char* s);
300  virtual void help(void);
301 
303  void add(Driver::BaseOption& o);
311  void parse(int& argc, char* argv[]);
312 
314  const char* name(void) const;
316  void name(const char*);
317 
319  virtual ~BaseOptions(void);
320  };
321 
327  protected:
329 
338 
339 
341 
356 
357 
359 
366 
367 
368  public:
370  Options(const char* s);
371 
373 
374  void model(int v);
377  void model(int v, const char* o, const char* h = NULL);
379  int model(void) const;
380 
382  void symmetry(int v);
384  void symmetry(int v, const char* o, const char* h = NULL);
386  int symmetry(void) const;
387 
389  void propagation(int v);
391  void propagation(int v, const char* o, const char* h = NULL);
393  int propagation(void) const;
394 
396  void icl(IntConLevel i);
398  IntConLevel icl(void) const;
399 
401  void branching(int v);
403  void branching(int v, const char* o, const char* h = NULL);
405  int branching(void) const;
406 
408  void decay(double d);
410  double decay(void) const;
411 
413  void seed(unsigned int s);
415  unsigned int seed(void) const;
416 
418  void step(double s);
420  double step(void) const;
422 
424 
425  void search(int v);
428  void search(int v, const char* o, const char* h = NULL);
430  int search(void) const;
431 
433  void solutions(unsigned int n);
435  unsigned int solutions(void) const;
436 
438  void threads(double n);
440  double threads(void) const;
441 
443  void c_d(unsigned int d);
445  unsigned int c_d(void) const;
446 
448  void a_d(unsigned int d);
450  unsigned int a_d(void) const;
451 
453  void node(unsigned int n);
455  unsigned int node(void) const;
456 
458  void fail(unsigned int n);
460  unsigned int fail(void) const;
461 
463  void time(unsigned int t);
465  unsigned int time(void) const;
466 
468  void restart(RestartMode r);
470  RestartMode restart(void) const;
471 
473  void restart_base(double base);
475  double restart_base(void) const;
476 
478  void restart_scale(unsigned int scale);
480  unsigned int restart_scale(void) const;
481 
483  void nogoods(bool b);
485  bool nogoods(void) const;
486 
488  void nogoods_limit(unsigned int l);
490  unsigned int nogoods_limit(void) const;
491 
493  void interrupt(bool b);
495  bool interrupt(void) const;
497 
499 
500  void mode(ScriptMode em);
503  ScriptMode mode(void) const;
504 
506  void samples(unsigned int s);
508  unsigned int samples(void) const;
509 
511  void iterations(unsigned int i);
513  unsigned int iterations(void) const;
514 
516  void print_last(bool p);
518  bool print_last(void) const;
519 
521  void out_file(const char* f);
523  const char* out_file(void) const;
524 
526  void log_file(const char* f);
528  const char* log_file(void) const;
530 
531 #ifdef GECODE_HAS_GIST
532  class _I {
534  private:
538  unsigned int n_click;
542  unsigned int n_solution;
546  unsigned int n_move;
550  unsigned int n_compare;
551  public:
553  _I(void);
555  void click(Gist::Inspector* i);
557  void solution(Gist::Inspector* i);
559  void move(Gist::Inspector* i);
561  void compare(Gist::Comparator* i);
562 
564  Gist::Inspector* click(unsigned int i) const;
566  Gist::Inspector* solution(unsigned int i) const;
568  Gist::Inspector* move(unsigned int i) const;
570  Gist::Comparator* compare(unsigned int i) const;
571  } inspect;
572 #endif
573  };
574 
580  protected:
581  unsigned int _size;
582  public:
584  SizeOptions(const char* s);
586  virtual void help(void);
588  void parse(int& argc, char* argv[]);
589 
591  void size(unsigned int s);
593  unsigned int size(void) const;
594  };
595 
601  protected:
602  const char* _inst;
603  public:
605  InstanceOptions(const char* s);
607  virtual void help(void);
609  void parse(int& argc, char* argv[]);
610 
612  void instance(const char* s);
614  const char* instance(void) const;
616  ~InstanceOptions(void);
617  };
618 
619 }
620 
621 #include <gecode/driver/options.hpp>
622 
623 namespace Gecode { namespace Driver {
624 
632  template<class BaseSpace>
633  class ScriptBase : public BaseSpace {
634  public:
636  ScriptBase(const Options& opt);
638  ScriptBase(bool share, ScriptBase& e);
640  virtual void print(std::ostream& os) const;
642  virtual void compare(const Space& home, std::ostream& os) const;
644  static std::ostream& select_ostream(const char* name, std::ofstream& ofs);
654  template<class Script, template<class> class Engine, class Options>
655  static void run(const Options& opt, Script* s=NULL);
656  private:
657  template<class Script, template<class> class Engine, class Options,
658  template<template<class> class,class> class Meta>
659  static void runMeta(const Options& opt, Script* s);
661  explicit ScriptBase(ScriptBase& e);
662  };
663 
664 #ifdef GECODE_HAS_FLOAT_VARS
665 
667  template<class BaseSpace>
668  class ExtractStepOption : public BaseSpace {
669  public:
672  : BaseSpace(opt.step()) {}
674  ExtractStepOption(bool share, BaseSpace& e)
675  : BaseSpace(share,e) {}
676  };
677 
678 #endif
679 
681  template<class BaseSpace>
682  class IgnoreStepOption : public BaseSpace {
683  public:
687  IgnoreStepOption(bool share, BaseSpace& e)
688  : BaseSpace(share,e) {}
689  };
690 
691 
692 }}
693 
694 #include <gecode/driver/script.hpp>
695 
696 namespace Gecode {
697 
733 
734 #ifdef GECODE_HAS_FLOAT_VARS
735 
748 
749 #endif
750 
751 }
752 
753 #endif
754 
755 // STATISTICS: driver-any
Driver::ScriptBase< Driver::IgnoreStepOption< MaximizeSpace > > MaximizeScript
Base-class for scripts for finding solution of highest integer cost.
Definition: driver.hh:720
Driver::UnsignedIntOption _c_d
Copy recomputation distance.
Definition: driver.hh:345
Restart with linear sequence.
Definition: driver.hh:112
Driver::BoolOption _interrupt
Whether to catch SIGINT.
Definition: driver.hh:355
int cur
Current value.
Definition: driver.hh:184
Options for scripts with additional size parameter
Definition: driver.hh:579
const Gecode::FloatNum step
Definition: arithmetic.cpp:789
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:714
Driver::UnsignedIntOption _iterations
How many iterations per sample.
Definition: driver.hh:362
IntConLevel
Consistency levels for integer propagators.
Definition: int.hh:937
ExtractStepOption(const Options &opt)
Constructor that extracts the step value.
Definition: driver.hh:671
NNF * l
Left subtree.
Definition: bool-expr.cpp:244
Driver::DoubleOption _decay
Decay option.
Definition: driver.hh:335
unsigned int cur
Current value.
Definition: driver.hh:231
Driver::DoubleOption _step
Step option.
Definition: driver.hh:337
Class to extract the step option value.
Definition: driver.hh:668
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:344
Driver::UnsignedIntOption _nogoods_limit
Limit for no-good extraction.
Definition: driver.hh:354
Driver::StringOption _restart
Restart method option.
Definition: driver.hh:350
Driver::BoolOption _nogoods
Whether to use no-goods.
Definition: driver.hh:353
Class to ignore the step option value.
Definition: driver.hh:682
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:726
IgnoreStepOption(bool share, BaseSpace &e)
Constructor used for cloning.
Definition: driver.hh:687
Driver::DoubleOption _r_base
Restart base.
Definition: driver.hh:351
Driver::ScriptBase< Driver::ExtractStepOption< FloatMaximizeSpace > > FloatMaximizeScript
Base-class for scripts for finding solution of highest float cost.
Definition: driver.hh:747
RestartMode
Different modes for restart-based search.
Definition: driver.hh:109
Computation spaces.
Definition: core.hpp:1362
Abstract base class for inspectors.
Definition: gist.hh:103
Parametric base-class for scripts.
Definition: driver.hh:633
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:330
unsigned int _size
Size value.
Definition: driver.hh:581
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:741
Options opt
The options.
Definition: test.cpp:101
Driver::UnsignedIntOption _fail
Cutoff for number of failures.
Definition: driver.hh:348
Print solution and some statistics.
Definition: driver.hh:99
const char * help
Optional help text.
Definition: driver.hh:181
Driver::UnsignedIntOption _samples
How many samples.
Definition: driver.hh:361
NNF * r
Right subtree.
Definition: bool-expr.cpp:246
Driver::StringValueOption _log_file
Where to print statistics.
Definition: driver.hh:365
const unsigned int a_d
Create a clone during recomputation if distance is greater than a_d (adaptive distance) ...
Definition: search.hh:99
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:332
Base class for script options.
Definition: driver.hh:291
const char * _name
Script name.
Definition: driver.hh:295
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:342
Driver::BoolOption _print_last
Print only last solution found.
Definition: driver.hh:363
BaseOption * next
Next option Check for option and return its argument.
Definition: driver.hh:129
#define GECODE_DRIVER_EXPORT
Definition: driver.hh:65
Driver::StringOption _symmetry
General symmetry options.
Definition: driver.hh:331
Driver::UnsignedIntOption _a_d
Adaptive recomputation distance.
Definition: driver.hh:346
Driver::UnsignedIntOption _time
Cutoff for time.
Definition: driver.hh:349
Driver::StringOption _mode
Script mode to run.
Definition: driver.hh:360
const double threads
Number of threads to use.
Definition: search.hh:95
int val
Value for an option value.
Definition: driver.hh:179
const int v[7]
Definition: distinct.cpp:207
String-valued option (integer value defined by strings)
Definition: driver.hh:174
ExtractStepOption(bool share, BaseSpace &e)
Constructor used for cloning.
Definition: driver.hh:674
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::@519::NNF::@60::@61 b
For binary nodes (and, or, eqv)
Driver::ScriptBase< Driver::IgnoreStepOption< IntMaximizeSpace > > IntMaximizeScript
Base-class for scripts for finding solution of highest integer cost.
Definition: driver.hh:732
Print statistics for script.
Definition: driver.hh:101
Options for scripts with additional instance parameter
Definition: driver.hh:600
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:364
Driver::BaseOption * fst
First registered option.
Definition: driver.hh:293
const char * _inst
Instance string.
Definition: driver.hh:602
Driver::UnsignedIntOption _solutions
How many solutions.
Definition: driver.hh:343
Driver::StringOption _branching
Branching options.
Definition: driver.hh:334
Run script in Gist.
Definition: driver.hh:102
const char * cur
Current value.
Definition: driver.hh:153
Driver::BaseOption * lst
Last registered option.
Definition: driver.hh:294
const unsigned int c_d
Create a clone after every c_d commits (commit distance)
Definition: search.hh:97
CompareStatus compare(I &i, J &j)
Check whether range iterator i is a subset of j, or whether they are disjoint.
Driver::StringOption _icl
Integer consistency level.
Definition: driver.hh:333
int cur
Current value.
Definition: driver.hh:211
Gecode toplevel namespace
Driver::UnsignedIntOption _seed
Seed option.
Definition: driver.hh:336
IgnoreStepOption(const Options &)
Constructor.
Definition: driver.hh:685
const unsigned int nogoods_limit
Depth limit for no-good generation during search.
Definition: search.hh:107
Options for scripts
Definition: driver.hh:326
Restart with constant sequence.
Definition: driver.hh:111
Driver::UnsignedIntOption _r_scale
Restart scale factor.
Definition: driver.hh:352
Integer option.
Definition: driver.hh:209
Driver::ScriptBase< Driver::IgnoreStepOption< Space > > Script
Base-class for scripts.
Definition: driver.hh:708
Driver::UnsignedIntOption _node
Cutoff for number of nodes.
Definition: driver.hh:347
int solutions(TestSpace *c, Gecode::Search::Options &o, int maxNbSol=-1)
Find number of solutions.
Definition: branch.cpp:379
virtual void help(void)
Print help text.
Definition: options.cpp:284