Generated on Fri Mar 20 15:55:55 2015 for Gecode by doxygen 1.6.3

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: 2015-03-19 11:42:29 +0100 (Thu, 19 Mar 2015) $ by $Author: tack $
00011  *     $Revision: 14462 $
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 
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     Driver::UnsignedIntOption _seed;        
00337     Driver::DoubleOption      _step;        
00338 
00339     
00341 
00342     Driver::StringOption      _search;        
00343     Driver::UnsignedIntOption _solutions;     
00344     Driver::DoubleOption      _threads;       
00345     Driver::UnsignedIntOption _c_d;           
00346     Driver::UnsignedIntOption _a_d;           
00347     Driver::UnsignedIntOption _node;          
00348     Driver::UnsignedIntOption _fail;          
00349     Driver::UnsignedIntOption _time;          
00350     Driver::StringOption      _restart;       
00351     Driver::DoubleOption      _r_base;        
00352     Driver::UnsignedIntOption _r_scale;       
00353     Driver::BoolOption        _nogoods;       
00354     Driver::UnsignedIntOption _nogoods_limit; 
00355     Driver::BoolOption        _interrupt;     
00356 
00357     
00359 
00360     Driver::StringOption      _mode;       
00361     Driver::UnsignedIntOption _samples;    
00362     Driver::UnsignedIntOption _iterations; 
00363     Driver::BoolOption        _print_last; 
00364     Driver::StringValueOption _out_file;   
00365     Driver::StringValueOption _log_file;   
00366 
00367 
00368   public:
00370     Options(const char* s);
00371     
00373 
00374 
00375     void model(int v);
00377     void model(int v, const char* o, const char* h = NULL);
00379     int model(void) const;
00380     
00382     void symmetry(int v);
00384     void symmetry(int v, const char* o, const char* h = NULL);
00386     int symmetry(void) const;
00387     
00389     void propagation(int v);
00391     void propagation(int v, const char* o, const char* h = NULL);
00393     int propagation(void) const;
00394     
00396     void icl(IntConLevel i);
00398     IntConLevel icl(void) const;
00399     
00401     void branching(int v);
00403     void branching(int v, const char* o, const char* h = NULL);
00405     int branching(void) const;
00406 
00408     void decay(double d);
00410     double decay(void) const;
00411 
00413     void seed(unsigned int s);
00415     unsigned int seed(void) const;
00416 
00418     void step(double s);
00420     double step(void) const;
00422     
00424 
00425 
00426     void search(int v);
00428     void search(int v, const char* o, const char* h = NULL);
00430     int search(void) const;
00431     
00433     void solutions(unsigned int n);
00435     unsigned int solutions(void) const;
00436 
00438     void threads(double n);
00440     double threads(void) const;
00441     
00443     void c_d(unsigned int d);
00445     unsigned int c_d(void) const;
00446     
00448     void a_d(unsigned int d);
00450     unsigned int a_d(void) const;
00451     
00453     void node(unsigned int n);
00455     unsigned int node(void) const;
00456     
00458     void fail(unsigned int n);
00460     unsigned int fail(void) const;
00461     
00463     void time(unsigned int t);
00465     unsigned int time(void) const;
00466     
00468     void restart(RestartMode r);
00470     RestartMode restart(void) const;
00471     
00473     void restart_base(double base);
00475     double restart_base(void) const;
00476     
00478     void restart_scale(unsigned int scale);
00480     unsigned int restart_scale(void) const;
00481     
00483     void nogoods(bool b);
00485     bool nogoods(void) const;
00486     
00488     void nogoods_limit(unsigned int l);
00490     unsigned int nogoods_limit(void) const;
00491     
00493     void interrupt(bool b);
00495     bool interrupt(void) const;
00497 
00499 
00500 
00501     void mode(ScriptMode em);
00503     ScriptMode mode(void) const;
00504     
00506     void samples(unsigned int s);
00508     unsigned int samples(void) const;
00509 
00511     void iterations(unsigned int i);
00513     unsigned int iterations(void) const;
00514     
00516     void print_last(bool p);
00518     bool print_last(void) const;
00519 
00521     void out_file(const char* f);
00523     const char* out_file(void) const;
00524 
00526     void log_file(const char* f);
00528     const char* log_file(void) const;
00530 
00531 #ifdef GECODE_HAS_GIST
00532 
00533     class _I {
00534     private:
00536       Support::DynamicArray<Gist::Inspector*,Heap> _click;
00538       unsigned int n_click;
00540       Support::DynamicArray<Gist::Inspector*,Heap> _solution;
00542       unsigned int n_solution;
00544       Support::DynamicArray<Gist::Inspector*,Heap> _move;
00546       unsigned int n_move;
00548       Support::DynamicArray<Gist::Comparator*,Heap> _compare;
00550       unsigned int n_compare;
00551     public:
00553       _I(void);
00555       void click(Gist::Inspector* i);
00557       void solution(Gist::Inspector* i);
00559       void move(Gist::Inspector* i);
00561       void compare(Gist::Comparator* i);
00562       
00564       Gist::Inspector* click(unsigned int i) const;
00566       Gist::Inspector* solution(unsigned int i) const;
00568       Gist::Inspector* move(unsigned int i) const;
00570       Gist::Comparator* compare(unsigned int i) const;
00571     } inspect;
00572 #endif
00573   };
00574 
00579   class GECODE_DRIVER_EXPORT SizeOptions : public Options {
00580   protected:
00581     unsigned int _size; 
00582   public:
00584     SizeOptions(const char* s);
00586     virtual void help(void);
00588     void parse(int& argc, char* argv[]);
00589     
00591     void size(unsigned int s);
00593     unsigned int size(void) const;
00594   };
00595 
00600   class GECODE_DRIVER_EXPORT InstanceOptions : public Options {
00601   protected:
00602     const char* _inst; 
00603   public:
00605     InstanceOptions(const char* s);
00607     virtual void help(void);
00609     void parse(int& argc, char* argv[]);
00610     
00612     void instance(const char* s);
00614     const char* instance(void) const;
00616     ~InstanceOptions(void);
00617   };
00618 
00619 }
00620 
00621 #include <gecode/driver/options.hpp>
00622 
00623 namespace Gecode { namespace Driver {
00624 
00632   template<class BaseSpace>
00633   class ScriptBase : public BaseSpace {
00634   public:
00636     ScriptBase(const Options& opt);
00638     ScriptBase(bool share, ScriptBase& e);
00640     virtual void print(std::ostream& os) const;
00642     virtual void compare(const Space& home, std::ostream& os) const;
00644     static std::ostream& select_ostream(const char* name, std::ofstream& ofs);
00654     template<class Script, template<class> class Engine, class Options>
00655     static void run(const Options& opt, Script* s=NULL);
00656   private:
00657     template<class Script, template<class> class Engine, class Options,
00658              template<template<class> class,class> class Meta>
00659              static void runMeta(const Options& opt, Script* s);
00661     explicit ScriptBase(ScriptBase& e);
00662   };
00663 
00664 #ifdef GECODE_HAS_FLOAT_VARS 
00665 
00667   template<class BaseSpace>
00668   class ExtractStepOption : public BaseSpace {
00669   public:
00671     ExtractStepOption(const Options& opt) 
00672       : BaseSpace(opt.step()) {}
00674     ExtractStepOption(bool share, BaseSpace& e) 
00675       : BaseSpace(share,e) {}
00676   };
00677 
00678 #endif
00679 
00681   template<class BaseSpace>
00682   class IgnoreStepOption : public BaseSpace {
00683   public:
00685     IgnoreStepOption(const Options&) {}
00687     IgnoreStepOption(bool share, BaseSpace& e) 
00688       : BaseSpace(share,e) {}
00689   };
00690 
00691 
00692 }}
00693 
00694 #include <gecode/driver/script.hpp>
00695 
00696 namespace Gecode {
00697   
00707   typedef Driver::ScriptBase<Driver::IgnoreStepOption<Space> > 
00708     Script;
00713   typedef Driver::ScriptBase<Driver::IgnoreStepOption<MinimizeSpace> > 
00714     MinimizeScript;
00719   typedef Driver::ScriptBase<Driver::IgnoreStepOption<MaximizeSpace> > 
00720     MaximizeScript;
00725   typedef Driver::ScriptBase<Driver::IgnoreStepOption<IntMinimizeSpace> > 
00726     IntMinimizeScript;
00731   typedef Driver::ScriptBase<Driver::IgnoreStepOption<IntMaximizeSpace> > 
00732     IntMaximizeScript;
00733 
00734 #ifdef GECODE_HAS_FLOAT_VARS 
00735 
00740   typedef Driver::ScriptBase<Driver::ExtractStepOption<FloatMinimizeSpace> > 
00741     FloatMinimizeScript;
00746   typedef Driver::ScriptBase<Driver::ExtractStepOption<FloatMaximizeSpace> > 
00747     FloatMaximizeScript;
00748 
00749 #endif
00750 
00751 }
00752 
00753 #endif
00754 
00755 // STATISTICS: driver-any