Generated on Mon Jul 6 18:09:02 2009 for Gecode by doxygen 1.5.9

driver.hh

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Christian Schulte <schulte@gecode.org>
00005  *
00006  *  Copyright:
00007  *     Christian Schulte, 2009
00008  *
00009  *  Last modified:
00010  *     $Date: 2009-05-14 04:16:05 +0200 (Thu, 14 May 2009) $ by $Author: tack $
00011  *     $Revision: 9102 $
00012  *
00013  *  This file is part of Gecode, the generic constraint
00014  *  development environment:
00015  *     http://www.gecode.org
00016  *
00017  *  Permission is hereby granted, free of charge, to any person obtaining
00018  *  a copy of this software and associated documentation files (the
00019  *  "Software"), to deal in the Software without restriction, including
00020  *  without limitation the rights to use, copy, modify, merge, publish,
00021  *  distribute, sublicense, and/or sell copies of the Software, and to
00022  *  permit persons to whom the Software is furnished to do so, subject to
00023  *  the following conditions:
00024  *
00025  *  The above copyright notice and this permission notice shall be
00026  *  included in all copies or substantial portions of the Software.
00027  *
00028  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00029  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00030  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00031  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00032  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00033  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00034  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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  * Configure linking
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 // Configure auto-linking
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);
00127     };
00128     
00133     class GECODE_DRIVER_EXPORT StringOption : public BaseOption {
00134     protected:
00136       class Value {
00137       public:
00138         int         val;  
00139         const char* opt;  
00140         const char* help; 
00141         Value*      next; 
00142       };
00143       int    cur; 
00144       Value* fst; 
00145       Value* lst; 
00146     public:
00148       StringOption(const char* o, const char* e, int v=0);
00150       void value(int v);
00152       int value(void) const;
00154       void add(int v, const char* o, const char* h = NULL);
00156       virtual bool parse(int& argc, char* argv[]);
00158       virtual void help(void);
00160       virtual ~StringOption(void);
00161     };
00162   
00163 
00168     class GECODE_DRIVER_EXPORT IntOption : public BaseOption {
00169     protected:
00170       int cur; 
00171     public:
00173       IntOption(const char* o, const char* e, int v=0);
00175       void value(int v);
00177       int value(void) const;
00179       virtual bool parse(int& argc, char* argv[]);
00181       virtual void help(void);
00182     };
00183 
00188     class GECODE_DRIVER_EXPORT UnsignedIntOption : public BaseOption {
00189     protected:
00190       unsigned int cur; 
00191     public:
00193       UnsignedIntOption(const char* o, const char* e, unsigned int v=0);
00195       void value(unsigned int v);
00197       unsigned int value(void) const;
00199       virtual bool parse(int& argc, char* argv[]);
00201       virtual void help(void);
00202     };
00203 
00208     class GECODE_DRIVER_EXPORT DoubleOption : public BaseOption {
00209     protected:
00210       double cur; 
00211     public:
00213       DoubleOption(const char* o, const char* e, unsigned int v=0);
00215       void value(double v);
00217       double value(void) const;
00219       virtual bool parse(int& argc, char* argv[]);
00221       virtual void help(void);
00222     };
00223 
00228     class GECODE_DRIVER_EXPORT BoolOption : public BaseOption {
00229     protected:
00230       bool cur; 
00231     public:
00233       BoolOption(const char* o, const char* e);
00235       void value(bool v);
00237       bool value(void) const;
00239       virtual bool parse(int& argc, char* argv[]);
00241       virtual void help(void);
00242     };
00243 
00244   }
00245   
00250   class GECODE_DRIVER_EXPORT BaseOptions {
00251   protected:
00252     Driver::BaseOption* fst;   
00253     Driver::BaseOption* lst;   
00254     const char* _name; 
00255   public:
00257     BaseOptions(const char* s);
00259     virtual void help(void);
00260 
00262     void add(Driver::BaseOption& o);
00264     void parse(int& argc, char* argv[]);
00265     
00267     const char* name(void) const;
00269     void name(const char*);
00270 
00272     virtual ~BaseOptions(void);
00273   };
00274   
00279   class GECODE_DRIVER_EXPORT Options : public BaseOptions {
00280   protected:    
00282 
00283     Driver::StringOption _model;       
00284     Driver::StringOption _propagation; 
00285     Driver::StringOption _icl;         
00286     Driver::StringOption _branching;   
00287 
00288     
00290 
00291     Driver::StringOption      _search;    
00292     Driver::UnsignedIntOption _solutions; 
00293     Driver::DoubleOption      _threads;   
00294     Driver::UnsignedIntOption _c_d;       
00295     Driver::UnsignedIntOption _a_d;       
00296     Driver::UnsignedIntOption _node;      
00297     Driver::UnsignedIntOption _fail;      
00298     Driver::UnsignedIntOption _time;      
00299 
00300     
00302 
00303     Driver::StringOption      _mode;       
00304     Driver::UnsignedIntOption _samples;    
00305     Driver::UnsignedIntOption _iterations; 
00306 
00307 
00308   public:
00310     Options(const char* s);
00311     
00313 
00314 
00315     void model(int v);
00317     void model(int v, const char* o, const char* h = NULL);
00319     int model(void) const;
00320     
00322     void propagation(int v);
00324     void propagation(int v, const char* o, const char* h = NULL);
00326     int propagation(void) const;
00327     
00329     void icl(IntConLevel i);
00331     IntConLevel icl(void) const;
00332     
00334     void branching(int v);
00336     void branching(int v, const char* o, const char* h = NULL);
00338     int branching(void) const;
00340     
00342 
00343 
00344     void search(int v);
00346     void search(int v, const char* o, const char* h = NULL);
00348     int search(void) const;
00349     
00351     void solutions(unsigned int n);
00353     unsigned int solutions(void) const;
00354 
00356     void threads(double n);
00358     double threads(void) const;
00359     
00361     void c_d(unsigned int d);
00363     unsigned int c_d(void) const;
00364     
00366     void a_d(unsigned int d);
00368     unsigned int a_d(void) const;
00369     
00371     void node(unsigned int n);
00373     unsigned int node(void) const;
00374     
00376     void fail(unsigned int n);
00378     unsigned int fail(void) const;
00379     
00381     void time(unsigned int t);
00383     unsigned int time(void) const;
00385 
00387 
00388 
00389     void mode(ScriptMode em);
00391     ScriptMode mode(void) const;
00392     
00394     void iterations(unsigned int i);
00396     unsigned int iterations(void) const;
00397     
00399     void samples(unsigned int s);
00401     unsigned int samples(void) const;
00403   };
00404 
00409   class GECODE_DRIVER_EXPORT SizeOptions : public Options {
00410   protected:
00411     unsigned int _size; 
00412   public:
00414     SizeOptions(const char* s);
00416     virtual void help(void);
00418     void parse(int& argc, char* argv[]);
00419     
00421     void size(unsigned int s);
00423     unsigned int size(void) const;
00424   };
00425 
00426 }
00427 
00428 #include <gecode/driver/options.hpp>
00429 
00430 namespace Gecode {
00431 
00432   namespace Driver {
00440     template <class BaseSpace>
00441     class ScriptBase : public BaseSpace {
00442     public:
00444       ScriptBase(void) {}
00446       ScriptBase(bool share, ScriptBase& e) : BaseSpace(share,e) {}
00448       virtual void print(std::ostream& os) const { (void) os; }
00450       template <class Script, template<class> class Engine, class Options>
00451       static void run(const Options& opt);
00452     private:
00454       explicit ScriptBase(ScriptBase& e);
00455     };
00456   }
00457   
00467   typedef Driver::ScriptBase<Space> Script;
00472   typedef Driver::ScriptBase<MinimizeSpace> MinimizeScript;
00477   typedef Driver::ScriptBase<MaximizeSpace> MaximizeScript;
00478 
00479 }
00480 
00481 #include <gecode/driver/script.hpp>
00482 
00483 #endif
00484 
00485 // STATISTICS: driver-any