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
00109 enum RestartMode {
00110 RM_NONE,
00111 RM_CONSTANT,
00112 RM_LINEAR,
00113 RM_LUBY,
00114 RM_GEOMETRIC
00115 };
00116
00117 class BaseOptions;
00118
00119 namespace Driver {
00124 class GECODE_DRIVER_EXPORT BaseOption {
00125 friend class Gecode::BaseOptions;
00126 protected:
00127 const char* opt;
00128 const char* exp;
00129 BaseOption* next;
00130
00131 char* argument(int argc, char* argv[]) const;
00132 public:
00134 BaseOption(const char* o, const char* e);
00136 virtual int parse(int argc, char* argv[]) = 0;
00138 virtual void help(void) = 0;
00140 virtual ~BaseOption(void);
00142 static char* strdup(const char* s);
00144 static void strdel(const char* s);
00145 };
00146
00151 class GECODE_DRIVER_EXPORT StringValueOption : public BaseOption {
00152 protected:
00153 const char* cur;
00154 public:
00156 StringValueOption(const char* o, const char* e, const char* v=NULL);
00158 void value(const char* v);
00160 const char* value(void) const;
00162 virtual int parse(int argc, char* argv[]);
00164 virtual void help(void);
00166 virtual ~StringValueOption(void);
00167 };
00168
00169
00174 class GECODE_DRIVER_EXPORT StringOption : public BaseOption {
00175 protected:
00177 class Value {
00178 public:
00179 int val;
00180 const char* opt;
00181 const char* help;
00182 Value* next;
00183 };
00184 int cur;
00185 Value* fst;
00186 Value* lst;
00187 public:
00189 StringOption(const char* o, const char* e, int v=0);
00191 void value(int v);
00193 int value(void) const;
00195 void add(int v, const char* o, const char* h = NULL);
00197 virtual int parse(int argc, char* argv[]);
00199 virtual void help(void);
00201 virtual ~StringOption(void);
00202 };
00203
00204
00209 class GECODE_DRIVER_EXPORT IntOption : public BaseOption {
00210 protected:
00211 int cur;
00212 public:
00214 IntOption(const char* o, const char* e, int v=0);
00216 void value(int v);
00218 int value(void) const;
00220 virtual int parse(int argc, char* argv[]);
00222 virtual void help(void);
00223 };
00224
00229 class GECODE_DRIVER_EXPORT UnsignedIntOption : public BaseOption {
00230 protected:
00231 unsigned int cur;
00232 public:
00234 UnsignedIntOption(const char* o, const char* e, unsigned int v=0);
00236 void value(unsigned int v);
00238 unsigned int value(void) const;
00240 virtual int parse(int argc, char* argv[]);
00242 virtual void help(void);
00243 };
00244
00249 class GECODE_DRIVER_EXPORT DoubleOption : public BaseOption {
00250 protected:
00251 double cur;
00252 public:
00254 DoubleOption(const char* o, const char* e, double v=0);
00256 void value(double v);
00258 double value(void) const;
00260 virtual int parse(int argc, char* argv[]);
00262 virtual void help(void);
00263 };
00264
00269 class GECODE_DRIVER_EXPORT BoolOption : public BaseOption {
00270 protected:
00271 bool cur;
00272 public:
00274 BoolOption(const char* o, const char* e, bool v=false);
00276 void value(bool v);
00278 bool value(void) const;
00280 virtual int parse(int argc, char* argv[]);
00282 virtual void help(void);
00283 };
00284
00285 }
00286
00291 class GECODE_DRIVER_EXPORT BaseOptions {
00292 protected:
00293 Driver::BaseOption* fst;
00294 Driver::BaseOption* lst;
00295 const char* _name;
00296 public:
00298 BaseOptions(const char* s);
00300 virtual void help(void);
00301
00303 void add(Driver::BaseOption& o);
00311 void parse(int& argc, char* argv[]);
00312
00314 const char* name(void) const;
00316 void name(const char*);
00317
00319 virtual ~BaseOptions(void);
00320 };
00321
00326 class GECODE_DRIVER_EXPORT Options : public BaseOptions {
00327 protected:
00329
00330 Driver::StringOption _model;
00331 Driver::StringOption _symmetry;
00332 Driver::StringOption _propagation;
00333 Driver::StringOption _icl;
00334 Driver::StringOption _branching;
00335 Driver::DoubleOption _decay;
00336
00337
00339
00340 Driver::StringOption _search;
00341 Driver::UnsignedIntOption _solutions;
00342 Driver::DoubleOption _threads;
00343 Driver::UnsignedIntOption _c_d;
00344 Driver::UnsignedIntOption _a_d;
00345 Driver::UnsignedIntOption _node;
00346 Driver::UnsignedIntOption _fail;
00347 Driver::UnsignedIntOption _time;
00348 Driver::StringOption _restart;
00349 Driver::DoubleOption _r_base;
00350 Driver::UnsignedIntOption _r_scale;
00351 Driver::BoolOption _interrupt;
00352
00353
00355
00356 Driver::StringOption _mode;
00357 Driver::UnsignedIntOption _samples;
00358 Driver::UnsignedIntOption _iterations;
00359 Driver::BoolOption _print_last;
00360 Driver::StringValueOption _out_file;
00361 Driver::StringValueOption _log_file;
00362
00363
00364 public:
00366 Options(const char* s);
00367
00369
00370
00371 void model(int v);
00373 void model(int v, const char* o, const char* h = NULL);
00375 int model(void) const;
00376
00378 void symmetry(int v);
00380 void symmetry(int v, const char* o, const char* h = NULL);
00382 int symmetry(void) const;
00383
00385 void propagation(int v);
00387 void propagation(int v, const char* o, const char* h = NULL);
00389 int propagation(void) const;
00390
00392 void icl(IntConLevel i);
00394 IntConLevel icl(void) const;
00395
00397 void branching(int v);
00399 void branching(int v, const char* o, const char* h = NULL);
00401 int branching(void) const;
00402
00404 void decay(double d);
00406 double decay(void) const;
00408
00410
00411
00412 void search(int v);
00414 void search(int v, const char* o, const char* h = NULL);
00416 int search(void) const;
00417
00419 void solutions(unsigned int n);
00421 unsigned int solutions(void) const;
00422
00424 void threads(double n);
00426 double threads(void) const;
00427
00429 void c_d(unsigned int d);
00431 unsigned int c_d(void) const;
00432
00434 void a_d(unsigned int d);
00436 unsigned int a_d(void) const;
00437
00439 void node(unsigned int n);
00441 unsigned int node(void) const;
00442
00444 void fail(unsigned int n);
00446 unsigned int fail(void) const;
00447
00449 void time(unsigned int t);
00451 unsigned int time(void) const;
00452
00454 void restart(RestartMode r);
00456 RestartMode restart(void) const;
00457
00459 void restart_base(double base);
00461 double restart_base(void) const;
00462
00464 void restart_scale(unsigned int scale);
00466 unsigned int restart_scale(void) const;
00467
00469 void interrupt(bool b);
00471 bool interrupt(void) const;
00473
00475
00476
00477 void mode(ScriptMode em);
00479 ScriptMode mode(void) const;
00480
00482 void samples(unsigned int s);
00484 unsigned int samples(void) const;
00485
00487 void iterations(unsigned int i);
00489 unsigned int iterations(void) const;
00490
00492 void print_last(bool p);
00494 bool print_last(void) const;
00495
00497 void out_file(const char* f);
00499 const char* out_file(void) const;
00500
00502 void log_file(const char* f);
00504 const char* log_file(void) const;
00506
00507 #ifdef GECODE_HAS_GIST
00508
00509 class _I {
00510 private:
00512 Support::DynamicArray<Gist::Inspector*,Heap> _click;
00514 unsigned int n_click;
00516 Support::DynamicArray<Gist::Inspector*,Heap> _solution;
00518 unsigned int n_solution;
00520 Support::DynamicArray<Gist::Inspector*,Heap> _move;
00522 unsigned int n_move;
00524 Support::DynamicArray<Gist::Comparator*,Heap> _compare;
00526 unsigned int n_compare;
00527 public:
00529 _I(void);
00531 void click(Gist::Inspector* i);
00533 void solution(Gist::Inspector* i);
00535 void move(Gist::Inspector* i);
00537 void compare(Gist::Comparator* i);
00538
00540 Gist::Inspector* click(unsigned int i) const;
00542 Gist::Inspector* solution(unsigned int i) const;
00544 Gist::Inspector* move(unsigned int i) const;
00546 Gist::Comparator* compare(unsigned int i) const;
00547 } inspect;
00548 #endif
00549 };
00550
00555 class GECODE_DRIVER_EXPORT SizeOptions : public Options {
00556 protected:
00557 unsigned int _size;
00558 public:
00560 SizeOptions(const char* s);
00562 virtual void help(void);
00564 void parse(int& argc, char* argv[]);
00565
00567 void size(unsigned int s);
00569 unsigned int size(void) const;
00570 };
00571
00576 class GECODE_DRIVER_EXPORT InstanceOptions : public Options {
00577 protected:
00578 const char* _inst;
00579 public:
00581 InstanceOptions(const char* s);
00583 virtual void help(void);
00585 void parse(int& argc, char* argv[]);
00586
00588 void instance(const char* s);
00590 const char* instance(void) const;
00592 ~InstanceOptions(void);
00593 };
00594
00595 }
00596
00597 #include <gecode/driver/options.hpp>
00598
00599 namespace Gecode {
00600
00601 namespace Driver {
00609 template<class BaseSpace>
00610 class ScriptBase : public BaseSpace {
00611 public:
00613 ScriptBase(void) {}
00615 ScriptBase(bool share, ScriptBase& e) : BaseSpace(share,e) {}
00617 virtual void print(std::ostream& os) const { (void) os; }
00619 virtual void compare(const Space&, std::ostream& os) const {
00620 (void) os;
00621 }
00623 static std::ostream& select_ostream(const char* name, std::ofstream& ofs);
00633 template<class Script, template<class> class Engine, class Options>
00634 static void run(const Options& opt, Script* s=NULL);
00635 private:
00636 template<class Script, template<class> class Engine, class Options,
00637 template<template<class> class,class> class Meta>
00638 static void runMeta(const Options& opt, Script* s);
00640 explicit ScriptBase(ScriptBase& e);
00641 };
00642 }
00643
00653 typedef Driver::ScriptBase<Space> Script;
00658 typedef Driver::ScriptBase<MinimizeSpace> MinimizeScript;
00663 typedef Driver::ScriptBase<MaximizeSpace> MaximizeScript;
00664
00665 }
00666
00667 #include <gecode/driver/script.hpp>
00668
00669 #endif
00670
00671