Generated on Tue Oct 22 2013 00:48:59 for Gecode by doxygen 1.8.4
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