Generated on Sat Feb 7 2015 02:01:13 for Gecode by doxygen 1.8.9.1
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: 2013-07-08 14:22:40 +0200 (Mon, 08 Jul 2013) $ by $Author: schulte $
11  * $Revision: 13820 $
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 
336 
337 
339 
354 
355 
357 
364 
365 
366  public:
368  Options(const char* s);
369 
371 
372  void model(int v);
375  void model(int v, const char* o, const char* h = NULL);
377  int model(void) const;
378 
380  void symmetry(int v);
382  void symmetry(int v, const char* o, const char* h = NULL);
384  int symmetry(void) const;
385 
387  void propagation(int v);
389  void propagation(int v, const char* o, const char* h = NULL);
391  int propagation(void) const;
392 
394  void icl(IntConLevel i);
396  IntConLevel icl(void) const;
397 
399  void branching(int v);
401  void branching(int v, const char* o, const char* h = NULL);
403  int branching(void) const;
404 
406  void decay(double d);
408  double decay(void) const;
410 
412 
413  void search(int v);
416  void search(int v, const char* o, const char* h = NULL);
418  int search(void) const;
419 
421  void solutions(unsigned int n);
423  unsigned int solutions(void) const;
424 
426  void threads(double n);
428  double threads(void) const;
429 
431  void c_d(unsigned int d);
433  unsigned int c_d(void) const;
434 
436  void a_d(unsigned int d);
438  unsigned int a_d(void) const;
439 
441  void node(unsigned int n);
443  unsigned int node(void) const;
444 
446  void fail(unsigned int n);
448  unsigned int fail(void) const;
449 
451  void time(unsigned int t);
453  unsigned int time(void) const;
454 
456  void restart(RestartMode r);
458  RestartMode restart(void) const;
459 
461  void restart_base(double base);
463  double restart_base(void) const;
464 
466  void restart_scale(unsigned int scale);
468  unsigned int restart_scale(void) const;
469 
471  void nogoods(bool b);
473  bool nogoods(void) const;
474 
476  void nogoods_limit(unsigned int l);
478  unsigned int nogoods_limit(void) const;
479 
481  void interrupt(bool b);
483  bool interrupt(void) const;
485 
487 
488  void mode(ScriptMode em);
491  ScriptMode mode(void) const;
492 
494  void samples(unsigned int s);
496  unsigned int samples(void) const;
497 
499  void iterations(unsigned int i);
501  unsigned int iterations(void) const;
502 
504  void print_last(bool p);
506  bool print_last(void) const;
507 
509  void out_file(const char* f);
511  const char* out_file(void) const;
512 
514  void log_file(const char* f);
516  const char* log_file(void) const;
518 
519 #ifdef GECODE_HAS_GIST
520  class _I {
522  private:
526  unsigned int n_click;
530  unsigned int n_solution;
534  unsigned int n_move;
538  unsigned int n_compare;
539  public:
541  _I(void);
543  void click(Gist::Inspector* i);
545  void solution(Gist::Inspector* i);
547  void move(Gist::Inspector* i);
549  void compare(Gist::Comparator* i);
550 
552  Gist::Inspector* click(unsigned int i) const;
554  Gist::Inspector* solution(unsigned int i) const;
556  Gist::Inspector* move(unsigned int i) const;
558  Gist::Comparator* compare(unsigned int i) const;
559  } inspect;
560 #endif
561  };
562 
568  protected:
569  unsigned int _size;
570  public:
572  SizeOptions(const char* s);
574  virtual void help(void);
576  void parse(int& argc, char* argv[]);
577 
579  void size(unsigned int s);
581  unsigned int size(void) const;
582  };
583 
589  protected:
590  const char* _inst;
591  public:
593  InstanceOptions(const char* s);
595  virtual void help(void);
597  void parse(int& argc, char* argv[]);
598 
600  void instance(const char* s);
602  const char* instance(void) const;
604  ~InstanceOptions(void);
605  };
606 
607 }
608 
609 #include <gecode/driver/options.hpp>
610 
611 namespace Gecode {
612 
613  namespace Driver {
621  template<class BaseSpace>
622  class ScriptBase : public BaseSpace {
623  public:
625  ScriptBase(void) {}
627  ScriptBase(bool share, ScriptBase& e)
628  : BaseSpace(share,e) {}
630  virtual void print(std::ostream& os) const { (void) os; }
632  virtual void compare(const Space&, std::ostream& os) const {
633  (void) os;
634  }
636  static std::ostream& select_ostream(const char* name, std::ofstream& ofs);
646  template<class Script, template<class> class Engine, class Options>
647  static void run(const Options& opt, Script* s=NULL);
648  private:
649  template<class Script, template<class> class Engine, class Options,
650  template<template<class> class,class> class Meta>
651  static void runMeta(const Options& opt, Script* s);
653  explicit ScriptBase(ScriptBase& e);
654  };
655  }
656 
687 
688 #ifdef GECODE_HAS_FLOAT_VARS
689 
700 
701 #endif
702 
703 }
704 
705 #include <gecode/driver/script.hpp>
706 
707 #endif
708 
709 // STATISTICS: driver-any
Driver::UnsignedIntOption _c_d
Copy recomputation distance.
Definition: driver.hh:343
Restart with linear sequence.
Definition: driver.hh:112
Driver::BoolOption _interrupt
Whether to catch SIGINT.
Definition: driver.hh:353
int cur
Current value.
Definition: driver.hh:184
virtual void compare(const Space &, std::ostream &os) const
Compare with s.
Definition: driver.hh:632
Options for scripts with additional size parameter
Definition: driver.hh:567
NodeType t
Type of node.
Definition: bool-expr.cpp:234
Driver::UnsignedIntOption _iterations
How many iterations per sample.
Definition: driver.hh:360
IntConLevel
Consistency levels for integer propagators.
Definition: int.hh:937
Driver::ScriptBase< FloatMinimizeSpace > FloatMinimizeScript
Base-class for scripts for finding solution of lowest float cost.
Definition: driver.hh:694
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
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:342
Driver::UnsignedIntOption _nogoods_limit
Limit for no-good extraction.
Definition: driver.hh:352
Driver::StringOption _restart
Restart method option.
Definition: driver.hh:348
Driver::BoolOption _nogoods
Whether to use no-goods.
Definition: driver.hh:351
Driver::ScriptBase< Space > Script
Base-class for scripts.
Definition: driver.hh:666
Driver::ScriptBase< MinimizeSpace > MinimizeScript
Base-class for scripts for finding solution of lowest integer cost.
Definition: driver.hh:671
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::DoubleOption _r_base
Restart base.
Definition: driver.hh:349
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
Driver::ScriptBase< MaximizeSpace > MaximizeScript
Base-class for scripts for finding solution of highest integer cost.
Definition: driver.hh:676
Parametric base-class for scripts.
Definition: driver.hh:622
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.
static std::ostream & select_ostream(const char *name, std::ofstream &ofs)
Choose output stream according to name.
Definition: script.hpp:211
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:569
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
Options opt
The options.
Definition: test.cpp:101
Driver::UnsignedIntOption _fail
Cutoff for number of failures.
Definition: driver.hh:346
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:359
NNF * r
Right subtree.
Definition: bool-expr.cpp:246
Driver::ScriptBase< FloatMaximizeSpace > FloatMaximizeScript
Base-class for scripts for finding solution of highest float cost.
Definition: driver.hh:699
Driver::StringValueOption _log_file
Where to print statistics.
Definition: driver.hh:363
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:340
Driver::BoolOption _print_last
Print only last solution found.
Definition: driver.hh:361
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:344
Driver::UnsignedIntOption _time
Cutoff for time.
Definition: driver.hh:347
Driver::StringOption _mode
Script mode to run.
Definition: driver.hh:358
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
Print statistics for script.
Definition: driver.hh:101
Options for scripts with additional instance parameter
Definition: driver.hh:588
ScriptBase(bool share, ScriptBase &e)
Constructor used for cloning.
Definition: driver.hh:627
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:362
Driver::BaseOption * fst
First registered option.
Definition: driver.hh:293
virtual void print(std::ostream &os) const
Print a solution to os.
Definition: driver.hh:630
const char * _inst
Instance string.
Definition: driver.hh:590
Driver::UnsignedIntOption _solutions
How many solutions.
Definition: driver.hh:341
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
static void run(const Options &opt, Script *s=NULL)
Definition: script.hpp:236
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
Driver::ScriptBase< IntMaximizeSpace > IntMaximizeScript
Base-class for scripts for finding solution of highest integer cost.
Definition: driver.hh:686
struct Gecode::@518::NNF::@57::@58 b
For binary nodes (and, or, eqv)
Gecode toplevel namespace
const unsigned int nogoods_limit
Depth limit for no-good generation during search.
Definition: search.hh:107
Driver::ScriptBase< IntMinimizeSpace > IntMinimizeScript
Base-class for scripts for finding solution of lowest integer cost.
Definition: driver.hh:681
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:350
Integer option.
Definition: driver.hh:209
Driver::UnsignedIntOption _node
Cutoff for number of nodes.
Definition: driver.hh:345
int solutions(TestSpace *c, Gecode::Search::Options &o, int maxNbSol=-1)
Find number of solutions.
Definition: branch.cpp:379
ScriptBase(void)
Default constructor.
Definition: driver.hh:625
virtual void help(void)
Print help text.
Definition: options.cpp:284