00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef __GECODE_DRIVER_HH__
00039 #define __GECODE_DRIVER_HH__
00040
00041 #include <gecode/minimodel.hh>
00042 #include <gecode/search.hh>
00043 #ifdef GECODE_HAS_GIST
00044 #include <gecode/gist.hh>
00045 #endif
00046
00047
00048
00049
00050
00051 #if !defined(GECODE_STATIC_LIBS) && \
00052 (defined(__CYGWIN__) || defined(__MINGW32__) || defined(_MSC_VER))
00053
00054 #ifdef GECODE_BUILD_DRIVER
00055 #define GECODE_DRIVER_EXPORT __declspec( dllexport )
00056 #else
00057 #define GECODE_DRIVER_EXPORT __declspec( dllimport )
00058 #endif
00059
00060 #else
00061
00062 #ifdef GECODE_GCC_HAS_CLASS_VISIBILITY
00063 #define GECODE_DRIVER_EXPORT __attribute__ ((visibility("default")))
00064 #else
00065 #define GECODE_DRIVER_EXPORT
00066 #endif
00067
00068 #endif
00069
00070
00071 #ifndef GECODE_BUILD_DRIVER
00072 #define GECODE_LIBRARY_NAME "Driver"
00073 #include <gecode/support/auto-link.hpp>
00074 #endif
00075
00086 namespace Gecode {
00087
00088
00098 enum ScriptMode {
00099 SM_SOLUTION,
00100 SM_TIME,
00101 SM_STAT,
00102 SM_GIST
00103 };
00104
00105 class BaseOptions;
00106
00107 namespace Driver {
00112 class GECODE_DRIVER_EXPORT BaseOption {
00113 friend class Gecode::BaseOptions;
00114 protected:
00115 const char* opt;
00116 const char* exp;
00117 BaseOption* next;
00118 public:
00120 BaseOption(const char* o, const char* e);
00122 virtual bool parse(int& argc, char* argv[]) = 0;
00124 virtual void help(void) = 0;
00126 virtual ~BaseOption(void);
00128 static char* strdup(const char* s);
00130 static void strdel(const char* s);
00131 };
00132
00137 class GECODE_DRIVER_EXPORT StringValueOption : public BaseOption {
00138 protected:
00139 const char* cur;
00140 public:
00142 StringValueOption(const char* o, const char* e, const char* v=NULL);
00144 void value(const char* v);
00146 const char* value(void) const;
00148 virtual bool parse(int& argc, char* argv[]);
00150 virtual void help(void);
00152 virtual ~StringValueOption(void);
00153 };
00154
00155
00160 class GECODE_DRIVER_EXPORT StringOption : public BaseOption {
00161 protected:
00163 class Value {
00164 public:
00165 int val;
00166 const char* opt;
00167 const char* help;
00168 Value* next;
00169 };
00170 int cur;
00171 Value* fst;
00172 Value* lst;
00173 public:
00175 StringOption(const char* o, const char* e, int v=0);
00177 void value(int v);
00179 int value(void) const;
00181 void add(int v, const char* o, const char* h = NULL);
00183 virtual bool parse(int& argc, char* argv[]);
00185 virtual void help(void);
00187 virtual ~StringOption(void);
00188 };
00189
00190
00195 class GECODE_DRIVER_EXPORT IntOption : public BaseOption {
00196 protected:
00197 int cur;
00198 public:
00200 IntOption(const char* o, const char* e, int v=0);
00202 void value(int v);
00204 int value(void) const;
00206 virtual bool parse(int& argc, char* argv[]);
00208 virtual void help(void);
00209 };
00210
00215 class GECODE_DRIVER_EXPORT UnsignedIntOption : public BaseOption {
00216 protected:
00217 unsigned int cur;
00218 public:
00220 UnsignedIntOption(const char* o, const char* e, unsigned int v=0);
00222 void value(unsigned int v);
00224 unsigned int value(void) const;
00226 virtual bool parse(int& argc, char* argv[]);
00228 virtual void help(void);
00229 };
00230
00235 class GECODE_DRIVER_EXPORT DoubleOption : public BaseOption {
00236 protected:
00237 double cur;
00238 public:
00240 DoubleOption(const char* o, const char* e, unsigned int v=0);
00242 void value(double v);
00244 double value(void) const;
00246 virtual bool parse(int& argc, char* argv[]);
00248 virtual void help(void);
00249 };
00250
00255 class GECODE_DRIVER_EXPORT BoolOption : public BaseOption {
00256 protected:
00257 bool cur;
00258 public:
00260 BoolOption(const char* o, const char* e);
00262 void value(bool v);
00264 bool value(void) const;
00266 virtual bool parse(int& argc, char* argv[]);
00268 virtual void help(void);
00269 };
00270
00271 }
00272
00277 class GECODE_DRIVER_EXPORT BaseOptions {
00278 protected:
00279 Driver::BaseOption* fst;
00280 Driver::BaseOption* lst;
00281 const char* _name;
00282 public:
00284 BaseOptions(const char* s);
00286 virtual void help(void);
00287
00289 void add(Driver::BaseOption& o);
00291 void parse(int& argc, char* argv[]);
00292
00294 const char* name(void) const;
00296 void name(const char*);
00297
00299 virtual ~BaseOptions(void);
00300 };
00301
00306 class GECODE_DRIVER_EXPORT Options : public BaseOptions {
00307 protected:
00309
00310 Driver::StringOption _model;
00311 Driver::StringOption _symmetry;
00312 Driver::StringOption _propagation;
00313 Driver::StringOption _icl;
00314 Driver::StringOption _branching;
00315
00316
00318
00319 Driver::StringOption _search;
00320 Driver::UnsignedIntOption _solutions;
00321 Driver::DoubleOption _threads;
00322 Driver::UnsignedIntOption _c_d;
00323 Driver::UnsignedIntOption _a_d;
00324 Driver::UnsignedIntOption _node;
00325 Driver::UnsignedIntOption _fail;
00326 Driver::UnsignedIntOption _time;
00327
00328
00330
00331 Driver::StringOption _mode;
00332 Driver::UnsignedIntOption _samples;
00333 Driver::UnsignedIntOption _iterations;
00334
00335
00336 public:
00338 Options(const char* s);
00339
00341
00342
00343 void model(int v);
00345 void model(int v, const char* o, const char* h = NULL);
00347 int model(void) const;
00348
00350 void symmetry(int v);
00352 void symmetry(int v, const char* o, const char* h = NULL);
00354 int symmetry(void) const;
00355
00357 void propagation(int v);
00359 void propagation(int v, const char* o, const char* h = NULL);
00361 int propagation(void) const;
00362
00364 void icl(IntConLevel i);
00366 IntConLevel icl(void) const;
00367
00369 void branching(int v);
00371 void branching(int v, const char* o, const char* h = NULL);
00373 int branching(void) const;
00375
00377
00378
00379 void search(int v);
00381 void search(int v, const char* o, const char* h = NULL);
00383 int search(void) const;
00384
00386 void solutions(unsigned int n);
00388 unsigned int solutions(void) const;
00389
00391 void threads(double n);
00393 double threads(void) const;
00394
00396 void c_d(unsigned int d);
00398 unsigned int c_d(void) const;
00399
00401 void a_d(unsigned int d);
00403 unsigned int a_d(void) const;
00404
00406 void node(unsigned int n);
00408 unsigned int node(void) const;
00409
00411 void fail(unsigned int n);
00413 unsigned int fail(void) const;
00414
00416 void time(unsigned int t);
00418 unsigned int time(void) const;
00420
00422
00423
00424 void mode(ScriptMode em);
00426 ScriptMode mode(void) const;
00427
00429 void iterations(unsigned int i);
00431 unsigned int iterations(void) const;
00432
00434 void samples(unsigned int s);
00436 unsigned int samples(void) const;
00438
00439 #ifdef GECODE_HAS_GIST
00440
00441 class _I {
00442 private:
00444 Support::DynamicArray<Gist::Inspector*,Heap> _click;
00446 unsigned int n_click;
00448 Support::DynamicArray<Gist::Inspector*,Heap> _solution;
00450 unsigned int n_solution;
00452 Support::DynamicArray<Gist::Inspector*,Heap> _move;
00454 unsigned int n_move;
00456 Support::DynamicArray<Gist::Comparator*,Heap> _compare;
00458 unsigned int n_compare;
00459 public:
00461 _I(void);
00463 void click(Gist::Inspector* i);
00465 void solution(Gist::Inspector* i);
00467 void move(Gist::Inspector* i);
00469 void compare(Gist::Comparator* i);
00470
00472 Gist::Inspector* click(unsigned int i) const;
00474 Gist::Inspector* solution(unsigned int i) const;
00476 Gist::Inspector* move(unsigned int i) const;
00478 Gist::Comparator* compare(unsigned int i) const;
00479 } inspect;
00480 #endif
00481 };
00482
00487 class GECODE_DRIVER_EXPORT SizeOptions : public Options {
00488 protected:
00489 unsigned int _size;
00490 public:
00492 SizeOptions(const char* s);
00494 virtual void help(void);
00496 void parse(int& argc, char* argv[]);
00497
00499 void size(unsigned int s);
00501 unsigned int size(void) const;
00502 };
00503
00504 }
00505
00506 #include <gecode/driver/options.hpp>
00507
00508 namespace Gecode {
00509
00510 namespace Driver {
00518 template<class BaseSpace>
00519 class ScriptBase : public BaseSpace {
00520 public:
00522 ScriptBase(void) {}
00524 ScriptBase(bool share, ScriptBase& e) : BaseSpace(share,e) {}
00526 virtual void print(std::ostream& os) const { (void) os; }
00528 virtual void compare(const Space&, std::ostream& os) const {
00529 (void) os;
00530 }
00532 template<class Script, template<class> class Engine, class Options>
00533 static void run(const Options& opt);
00534 private:
00536 explicit ScriptBase(ScriptBase& e);
00537 };
00538 }
00539
00549 typedef Driver::ScriptBase<Space> Script;
00554 typedef Driver::ScriptBase<MinimizeSpace> MinimizeScript;
00559 typedef Driver::ScriptBase<MaximizeSpace> MaximizeScript;
00560
00561 }
00562
00563 #include <gecode/driver/script.hpp>
00564
00565 #endif
00566
00567