support.hh
Go to the documentation of this file.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_EXAMPLES_SUPPORT_HH__
00039 #define __GECODE_EXAMPLES_SUPPORT_HH__
00040
00041 #include "gecode/kernel.hh"
00042 #include "gecode/int.hh"
00043 #include "gecode/search.hh"
00044
00045 #ifdef GECODE_HAS_GIST
00046 #include "gecode/gist.hh"
00047 #endif
00048
00049 using namespace Gecode;
00050
00051
00052
00053
00054
00055
00057 enum ExampleMode {
00058 EM_SOLUTION,
00059 EM_TIME,
00060 EM_STAT
00061 #ifdef GECODE_HAS_GIST
00062 ,
00063 EM_GIST
00064 #endif
00065 };
00066
00067 class Options;
00068
00073 class BaseOption {
00074 friend class Options;
00075 protected:
00076 const char* opt;
00077 const char* exp;
00078 BaseOption* next;
00079 public:
00081 BaseOption(const char* o, const char* e);
00083 virtual bool parse(int& argc, char* argv[]) = 0;
00085 virtual void help(void) = 0;
00087 virtual ~BaseOption(void);
00088 };
00089
00094 class StringOption : public BaseOption {
00095 protected:
00097 class Value {
00098 public:
00099 int val;
00100 const char* opt;
00101 const char* help;
00102 Value* next;
00103 };
00104 int cur;
00105 Value* fst;
00106 Value* lst;
00107 public:
00109 StringOption(const char* o, const char* e, int v=0);
00111 void value(int v);
00113 int value(void) const;
00115 void add(int v, const char* o, const char* h = NULL);
00117 virtual bool parse(int& argc, char* argv[]);
00119 virtual void help(void);
00121 virtual ~StringOption(void);
00122 };
00123
00124
00129 class UnsignedIntOption : public BaseOption {
00130 protected:
00131 unsigned int cur;
00132 public:
00134 UnsignedIntOption(const char* o, const char* e, unsigned int v=0);
00136 void value(unsigned int v);
00138 unsigned int value(void) const;
00140 virtual bool parse(int& argc, char* argv[]);
00142 virtual void help(void);
00143 };
00144
00145
00150 class Options {
00151 protected:
00152 BaseOption* fst;
00153 BaseOption* lst;
00154 const char* _name;
00155
00157
00158 StringOption _model;
00159 StringOption _propagation;
00160 StringOption _pk;
00161 StringOption _icl;
00162 StringOption _branching;
00163
00164
00166
00167 StringOption _search;
00168 UnsignedIntOption _solutions;
00169 UnsignedIntOption _c_d;
00170 UnsignedIntOption _a_d;
00171 UnsignedIntOption _fail;
00172 UnsignedIntOption _time;
00173
00174
00176
00177 StringOption _mode;
00178 UnsignedIntOption _samples;
00179 UnsignedIntOption _iterations;
00180
00181
00182 public:
00184 Options(const char* s);
00186 void add(BaseOption& o);
00188 virtual void help(void);
00190 void parse(int& argc, char* argv[]);
00191
00193 const char* name(void) const;
00194
00196
00197
00198 void model(int v);
00200 void model(int v, const char* o, const char* h = NULL);
00202 int model(void) const;
00203
00205 void propagation(int v);
00207 void propagation(int v, const char* o, const char* h = NULL);
00209 int propagation(void) const;
00210
00212 void pk(PropKind p);
00214 PropKind pk(void) const;
00215
00217 void icl(IntConLevel i);
00219 IntConLevel icl(void) const;
00220
00222 void branching(int v);
00224 void branching(int v, const char* o, const char* h = NULL);
00226 int branching(void) const;
00228
00230
00231
00232 void search(int v);
00234 void search(int v, const char* o, const char* h = NULL);
00236 int search(void) const;
00237
00239 void solutions(unsigned int n);
00241 unsigned int solutions(void) const;
00242
00244 void c_d(unsigned int d);
00246 unsigned int c_d(void) const;
00247
00249 void a_d(unsigned int d);
00251 unsigned int a_d(void) const;
00252
00254 void fail(unsigned int n);
00256 unsigned int fail(void) const;
00257
00259 void time(unsigned int t);
00261 unsigned int time(void) const;
00263
00265
00266
00267 void mode(ExampleMode em);
00269 ExampleMode mode(void) const;
00270
00272 void iterations(unsigned int i);
00274 unsigned int iterations(void) const;
00275
00277 void samples(unsigned int s);
00279 unsigned int samples(void) const;
00281
00283 virtual ~Options(void);
00284 };
00285
00290 class SizeOptions : public Options {
00291 protected:
00292 unsigned int _size;
00293 public:
00295 SizeOptions(const char* s);
00297 virtual void help(void);
00299 void parse(int& argc, char* argv[]);
00300
00302 void size(unsigned int s);
00304 unsigned int size(void) const;
00305 };
00306
00307 #include "examples/support/options.icc"
00308
00309
00318 class Example : public Space {
00319 public:
00321 Example(void) {}
00323 Example(bool share, Example& e) : Space(share,e) {}
00325 virtual void print(std::ostream& os) { (void)os; }
00327 template <class Script, template<class> class Engine, class Options>
00328 static void run(const Options& opt);
00329 private:
00331 explicit Example(Example& e);
00332 };
00333
00334 #include "examples/support/example.icc"
00335
00336 #endif
00337
00338