Generated on Mon Nov 30 23:53:18 2009 for Gecode by doxygen 1.6.1

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-09-08 21:10:29 +0200 (Tue, 08 Sep 2009) $ by $Author: schulte $
00011  *     $Revision: 9692 $
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);
00128       static char* strdup(const char* s);
00130       static void strdel(const char* s);
00131     };
00132     
00137     class GECODE_DRIVER_EXPORT StringOption : public BaseOption {
00138     protected:
00140       class Value {
00141       public:
00142         int         val;  
00143         const char* opt;  
00144         const char* help; 
00145         Value*      next; 
00146       };
00147       int    cur; 
00148       Value* fst; 
00149       Value* lst; 
00150     public:
00152       StringOption(const char* o, const char* e, int v=0);
00154       void value(int v);
00156       int value(void) const;
00158       void add(int v, const char* o, const char* h = NULL);
00160       virtual bool parse(int& argc, char* argv[]);
00162       virtual void help(void);
00164       virtual ~StringOption(void);
00165     };
00166   
00167 
00172     class GECODE_DRIVER_EXPORT IntOption : public BaseOption {
00173     protected:
00174       int cur; 
00175     public:
00177       IntOption(const char* o, const char* e, int v=0);
00179       void value(int v);
00181       int value(void) const;
00183       virtual bool parse(int& argc, char* argv[]);
00185       virtual void help(void);
00186     };
00187 
00192     class GECODE_DRIVER_EXPORT UnsignedIntOption : public BaseOption {
00193     protected:
00194       unsigned int cur; 
00195     public:
00197       UnsignedIntOption(const char* o, const char* e, unsigned int v=0);
00199       void value(unsigned int v);
00201       unsigned int value(void) const;
00203       virtual bool parse(int& argc, char* argv[]);
00205       virtual void help(void);
00206     };
00207 
00212     class GECODE_DRIVER_EXPORT DoubleOption : public BaseOption {
00213     protected:
00214       double cur; 
00215     public:
00217       DoubleOption(const char* o, const char* e, unsigned int v=0);
00219       void value(double v);
00221       double value(void) const;
00223       virtual bool parse(int& argc, char* argv[]);
00225       virtual void help(void);
00226     };
00227 
00232     class GECODE_DRIVER_EXPORT BoolOption : public BaseOption {
00233     protected:
00234       bool cur; 
00235     public:
00237       BoolOption(const char* o, const char* e);
00239       void value(bool v);
00241       bool value(void) const;
00243       virtual bool parse(int& argc, char* argv[]);
00245       virtual void help(void);
00246     };
00247 
00248   }
00249   
00254   class GECODE_DRIVER_EXPORT BaseOptions {
00255   protected:
00256     Driver::BaseOption* fst;   
00257     Driver::BaseOption* lst;   
00258     const char* _name; 
00259   public:
00261     BaseOptions(const char* s);
00263     virtual void help(void);
00264 
00266     void add(Driver::BaseOption& o);
00268     void parse(int& argc, char* argv[]);
00269     
00271     const char* name(void) const;
00273     void name(const char*);
00274 
00276     virtual ~BaseOptions(void);
00277   };
00278   
00283   class GECODE_DRIVER_EXPORT Options : public BaseOptions {
00284   protected:    
00286 
00287     Driver::StringOption _model;       
00288     Driver::StringOption _symmetry;    
00289     Driver::StringOption _propagation; 
00290     Driver::StringOption _icl;         
00291     Driver::StringOption _branching;   
00292 
00293     
00295 
00296     Driver::StringOption      _search;    
00297     Driver::UnsignedIntOption _solutions; 
00298     Driver::DoubleOption      _threads;   
00299     Driver::UnsignedIntOption _c_d;       
00300     Driver::UnsignedIntOption _a_d;       
00301     Driver::UnsignedIntOption _node;      
00302     Driver::UnsignedIntOption _fail;      
00303     Driver::UnsignedIntOption _time;      
00304 
00305     
00307 
00308     Driver::StringOption      _mode;       
00309     Driver::UnsignedIntOption _samples;    
00310     Driver::UnsignedIntOption _iterations; 
00311 
00312 
00313   public:
00315     Options(const char* s);
00316     
00318 
00319 
00320     void model(int v);
00322     void model(int v, const char* o, const char* h = NULL);
00324     int model(void) const;
00325     
00327     void symmetry(int v);
00329     void symmetry(int v, const char* o, const char* h = NULL);
00331     int symmetry(void) const;
00332     
00334     void propagation(int v);
00336     void propagation(int v, const char* o, const char* h = NULL);
00338     int propagation(void) const;
00339     
00341     void icl(IntConLevel i);
00343     IntConLevel icl(void) const;
00344     
00346     void branching(int v);
00348     void branching(int v, const char* o, const char* h = NULL);
00350     int branching(void) const;
00352     
00354 
00355 
00356     void search(int v);
00358     void search(int v, const char* o, const char* h = NULL);
00360     int search(void) const;
00361     
00363     void solutions(unsigned int n);
00365     unsigned int solutions(void) const;
00366 
00368     void threads(double n);
00370     double threads(void) const;
00371     
00373     void c_d(unsigned int d);
00375     unsigned int c_d(void) const;
00376     
00378     void a_d(unsigned int d);
00380     unsigned int a_d(void) const;
00381     
00383     void node(unsigned int n);
00385     unsigned int node(void) const;
00386     
00388     void fail(unsigned int n);
00390     unsigned int fail(void) const;
00391     
00393     void time(unsigned int t);
00395     unsigned int time(void) const;
00397 
00399 
00400 
00401     void mode(ScriptMode em);
00403     ScriptMode mode(void) const;
00404     
00406     void iterations(unsigned int i);
00408     unsigned int iterations(void) const;
00409     
00411     void samples(unsigned int s);
00413     unsigned int samples(void) const;
00415   };
00416 
00421   class GECODE_DRIVER_EXPORT SizeOptions : public Options {
00422   protected:
00423     unsigned int _size; 
00424   public:
00426     SizeOptions(const char* s);
00428     virtual void help(void);
00430     void parse(int& argc, char* argv[]);
00431     
00433     void size(unsigned int s);
00435     unsigned int size(void) const;
00436   };
00437 
00438 }
00439 
00440 #include <gecode/driver/options.hpp>
00441 
00442 namespace Gecode {
00443 
00444   namespace Driver {
00452     template<class BaseSpace>
00453     class ScriptBase : public BaseSpace {
00454     public:
00456       ScriptBase(void) {}
00458       ScriptBase(bool share, ScriptBase& e) : BaseSpace(share,e) {}
00460       virtual void print(std::ostream& os) const { (void) os; }
00462       template<class Script, template<class> class Engine, class Options>
00463       static void run(const Options& opt);
00464     private:
00466       explicit ScriptBase(ScriptBase& e);
00467     };
00468   }
00469   
00479   typedef Driver::ScriptBase<Space> Script;
00484   typedef Driver::ScriptBase<MinimizeSpace> MinimizeScript;
00489   typedef Driver::ScriptBase<MaximizeSpace> MaximizeScript;
00490 
00491 }
00492 
00493 #include <gecode/driver/script.hpp>
00494 
00495 #endif
00496 
00497 // STATISTICS: driver-any