Generated on Fri Oct 19 11:24:50 2018 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  *  This file is part of Gecode, the generic constraint
00010  *  development environment:
00011  *     http://www.gecode.org
00012  *
00013  *  Permission is hereby granted, free of charge, to any person obtaining
00014  *  a copy of this software and associated documentation files (the
00015  *  "Software"), to deal in the Software without restriction, including
00016  *  without limitation the rights to use, copy, modify, merge, publish,
00017  *  distribute, sublicense, and/or sell copies of the Software, and to
00018  *  permit persons to whom the Software is furnished to do so, subject to
00019  *  the following conditions:
00020  *
00021  *  The above copyright notice and this permission notice shall be
00022  *  included in all copies or substantial portions of the Software.
00023  *
00024  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00025  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00026  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00027  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00028  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00029  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00030  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00031  *
00032  */
00033 
00034 #ifndef __GECODE_DRIVER_HH__
00035 #define __GECODE_DRIVER_HH__
00036 
00037 #include <gecode/minimodel.hh>
00038 #include <gecode/search.hh>
00039 #ifdef GECODE_HAS_GIST
00040 #include <gecode/gist.hh>
00041 #endif
00042 
00043 /*
00044  * Configure linking
00045  *
00046  */
00047 #if !defined(GECODE_STATIC_LIBS) && \
00048     (defined(__CYGWIN__) || defined(__MINGW32__) || defined(_MSC_VER))
00049 
00050 #ifdef GECODE_BUILD_DRIVER
00051 #define GECODE_DRIVER_EXPORT __declspec( dllexport )
00052 #else
00053 #define GECODE_DRIVER_EXPORT __declspec( dllimport )
00054 #endif
00055 
00056 #else
00057 
00058 #ifdef GECODE_GCC_HAS_CLASS_VISIBILITY
00059 #define GECODE_DRIVER_EXPORT __attribute__ ((visibility("default")))
00060 #else
00061 #define GECODE_DRIVER_EXPORT
00062 #endif
00063 
00064 #endif
00065 
00066 // Configure auto-linking
00067 #ifndef GECODE_BUILD_DRIVER
00068 #define GECODE_LIBRARY_NAME "Driver"
00069 #include <gecode/support/auto-link.hpp>
00070 #endif
00071 
00082 namespace Gecode {
00083 
00084 
00094   enum ScriptMode {
00095     SM_SOLUTION,  
00096     SM_TIME,      
00097     SM_STAT,      
00098     SM_GIST,      
00099     SM_CPPROFILER 
00100   };
00101 
00106   enum RestartMode {
00107     RM_NONE,     
00108     RM_CONSTANT, 
00109     RM_LINEAR,   
00110     RM_LUBY,     
00111     RM_GEOMETRIC 
00112   };
00113 
00114   class BaseOptions;
00115 
00116   namespace Driver {
00121     class GECODE_DRIVER_EXPORT BaseOption {
00122       friend class Gecode::BaseOptions;
00123     protected:
00124       const char* eopt;  
00125       const char* iopt;  
00126       const char* exp;   
00127       BaseOption* next;  
00128 
00129       char* argument(int argc, char* argv[]) const;
00130     public:
00132       BaseOption(const char* o, const char* e);
00134       virtual int parse(int argc, char* argv[]) = 0;
00136       virtual void help(void) = 0;
00138       virtual ~BaseOption(void);
00140       static char* strdup(const char* s);
00142       static char* stredup(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 
00289     class GECODE_DRIVER_EXPORT IplOption : public BaseOption {
00290     protected:
00291       IntPropLevel cur; 
00292     public:
00294       IplOption(IntPropLevel ipl=IPL_DEF);
00296       void value(IntPropLevel l);
00298       IntPropLevel value(void) const;
00300       virtual int parse(int argc, char* argv[]);
00302       virtual void help(void);
00303     };
00304 
00309     class GECODE_DRIVER_EXPORT TraceOption : public BaseOption {
00310     protected:
00311       int cur; 
00312     public:
00314       TraceOption(int f=0);
00316       void value(int f);
00318       int value(void) const;
00320       virtual int parse(int argc, char* argv[]);
00322       virtual void help(void);
00323     };
00324 
00325   }
00326 
00331   class GECODE_DRIVER_EXPORT BaseOptions {
00332   protected:
00333     Driver::BaseOption* fst;   
00334     Driver::BaseOption* lst;   
00335     const char* _name; 
00336   public:
00338     BaseOptions(const char* s);
00340     virtual void help(void);
00341 
00343     void add(Driver::BaseOption& o);
00351     void parse(int& argc, char* argv[]);
00352 
00354     const char* name(void) const;
00356     void name(const char*);
00357 
00359     virtual ~BaseOptions(void);
00360   };
00361 
00366   class GECODE_DRIVER_EXPORT Options : public BaseOptions {
00367   protected:
00369 
00370     Driver::StringOption      _model;       
00371     Driver::StringOption      _symmetry;    
00372     Driver::StringOption      _propagation; 
00373     Driver::IplOption         _ipl;         
00374     Driver::StringOption      _branching;   
00375     Driver::DoubleOption      _decay;       
00376     Driver::UnsignedIntOption _seed;        
00377     Driver::DoubleOption      _step;        
00378 
00379 
00381 
00382     Driver::StringOption      _search;        
00383     Driver::UnsignedIntOption _solutions;     
00384     Driver::DoubleOption      _threads;       
00385     Driver::UnsignedIntOption _c_d;           
00386     Driver::UnsignedIntOption _a_d;           
00387     Driver::UnsignedIntOption _d_l;           
00388     Driver::UnsignedIntOption _node;          
00389     Driver::UnsignedIntOption _fail;          
00390     Driver::UnsignedIntOption _time;          
00391     Driver::UnsignedIntOption _assets;        
00392     Driver::UnsignedIntOption _slice;         
00393     Driver::StringOption      _restart;       
00394     Driver::DoubleOption      _r_base;        
00395     Driver::UnsignedIntOption _r_scale;       
00396     Driver::BoolOption        _nogoods;       
00397     Driver::UnsignedIntOption _nogoods_limit; 
00398     Driver::DoubleOption      _relax;         
00399     Driver::BoolOption        _interrupt;     
00400 
00401 
00403 
00404     Driver::StringOption      _mode;          
00405     Driver::UnsignedIntOption _samples;       
00406     Driver::UnsignedIntOption _iterations;    
00407     Driver::BoolOption        _print_last;    
00408     Driver::StringValueOption _out_file;      
00409     Driver::StringValueOption _log_file;      
00410     Driver::TraceOption       _trace;         
00411 
00412 #ifdef GECODE_HAS_CPPROFILER
00413     Driver::IntOption         _profiler_id;   
00414     Driver::UnsignedIntOption _profiler_port; 
00415     Driver::BoolOption        _profiler_info; 
00416 #endif
00417 
00419 
00420   public:
00422     Options(const char* s);
00423 
00425 
00426 
00427     void model(int v);
00429     void model(int v, const char* o, const char* h = NULL);
00431     int model(void) const;
00432 
00434     void symmetry(int v);
00436     void symmetry(int v, const char* o, const char* h = NULL);
00438     int symmetry(void) const;
00439 
00441     void propagation(int v);
00443     void propagation(int v, const char* o, const char* h = NULL);
00445     int propagation(void) const;
00446 
00448     void ipl(IntPropLevel i);
00450     IntPropLevel ipl(void) const;
00451 
00453     void branching(int v);
00455     void branching(int v, const char* o, const char* h = NULL);
00457     int branching(void) const;
00458 
00460     void decay(double d);
00462     double decay(void) const;
00463 
00465     void seed(unsigned int s);
00467     unsigned int seed(void) const;
00468 
00470     void step(double s);
00472     double step(void) const;
00474 
00476 
00477 
00478     void search(int v);
00480     void search(int v, const char* o, const char* h = NULL);
00482     int search(void) const;
00483 
00485     void solutions(unsigned int n);
00487     unsigned int solutions(void) const;
00488 
00490     void threads(double n);
00492     double threads(void) const;
00493 
00495     void c_d(unsigned int d);
00497     unsigned int c_d(void) const;
00498 
00500     void a_d(unsigned int d);
00502     unsigned int a_d(void) const;
00503 
00505     void d_l(unsigned int d);
00507     unsigned int d_l(void) const;
00508 
00510     void node(unsigned int n);
00512     unsigned int node(void) const;
00513 
00515     void fail(unsigned int n);
00517     unsigned int fail(void) const;
00518 
00520     void time(unsigned int t);
00522     unsigned int time(void) const;
00523 
00525     void assets(unsigned int n);
00527     unsigned int assets(void) const;
00528 
00530     void slice(unsigned int n);
00532     unsigned int slice(void) const;
00533 
00535     void restart(RestartMode r);
00537     RestartMode restart(void) const;
00538 
00540     void restart_base(double base);
00542     double restart_base(void) const;
00543 
00545     void restart_scale(unsigned int scale);
00547     unsigned int restart_scale(void) const;
00548 
00550     void nogoods(bool b);
00552     bool nogoods(void) const;
00553 
00555     void nogoods_limit(unsigned int l);
00557     unsigned int nogoods_limit(void) const;
00558 
00560     void relax(double d);
00562     double relax(void) const;
00563 
00565     void interrupt(bool b);
00567     bool interrupt(void) const;
00569 
00571 
00572 
00573     void mode(ScriptMode em);
00575     ScriptMode mode(void) const;
00576 
00578     void samples(unsigned int s);
00580     unsigned int samples(void) const;
00581 
00583     void iterations(unsigned int i);
00585     unsigned int iterations(void) const;
00586 
00588     void print_last(bool p);
00590     bool print_last(void) const;
00591 
00593     void out_file(const char* f);
00595     const char* out_file(void) const;
00596 
00598     void log_file(const char* f);
00600     const char* log_file(void) const;
00601 
00603     void trace(int f);
00605     int trace(void) const;
00606 
00607 #ifdef GECODE_HAS_CPPROFILER
00608 
00609     void profiler_id(int i);
00611     int profiler_id(void) const;
00613     void profiler_port(unsigned int p);
00615     unsigned int profiler_port(void) const;
00617     void profiler_info(bool b);
00619     bool profiler_info(void) const;
00620 #endif
00621 
00622 
00623 #ifdef GECODE_HAS_GIST
00624 
00625     class _I {
00626     private:
00628       Support::DynamicArray<Gist::Inspector*,Heap> _click;
00630       unsigned int n_click;
00632       Support::DynamicArray<Gist::Inspector*,Heap> _solution;
00634       unsigned int n_solution;
00636       Support::DynamicArray<Gist::Inspector*,Heap> _move;
00638       unsigned int n_move;
00640       Support::DynamicArray<Gist::Comparator*,Heap> _compare;
00642       unsigned int n_compare;
00643     public:
00645       _I(void);
00647       void click(Gist::Inspector* i);
00649       void solution(Gist::Inspector* i);
00651       void move(Gist::Inspector* i);
00653       void compare(Gist::Comparator* i);
00654 
00656       Gist::Inspector* click(unsigned int i) const;
00658       Gist::Inspector* solution(unsigned int i) const;
00660       Gist::Inspector* move(unsigned int i) const;
00662       Gist::Comparator* compare(unsigned int i) const;
00663     } inspect;
00664 #endif
00665   };
00666 
00667 }
00668 
00669 namespace Gecode {
00670 
00675   class GECODE_DRIVER_EXPORT SizeOptions : public Options {
00676   protected:
00677     unsigned int _size; 
00678   public:
00680     SizeOptions(const char* s);
00682     virtual void help(void);
00684     void parse(int& argc, char* argv[]);
00685 
00687     void size(unsigned int s);
00689     unsigned int size(void) const;
00690   };
00691 
00696   class GECODE_DRIVER_EXPORT InstanceOptions : public Options {
00697   protected:
00698     const char* _inst; 
00699   public:
00701     InstanceOptions(const char* s);
00703     virtual void help(void);
00705     void parse(int& argc, char* argv[]);
00706 
00708     void instance(const char* s);
00710     const char* instance(void) const;
00712     ~InstanceOptions(void);
00713   };
00714 
00715 }
00716 
00717 #include <gecode/driver/options.hpp>
00718 
00719 namespace Gecode { namespace Driver {
00720 
00728   template<class BaseSpace>
00729   class ScriptBase : public BaseSpace {
00730   public:
00732     ScriptBase(const Options& opt);
00734     ScriptBase(ScriptBase& e);
00736     virtual void print(std::ostream& os) const;
00738     virtual void compare(const Space& home, std::ostream& os) const;
00740     static std::ostream& select_ostream(const char* sn, std::ofstream& ofs);
00750     template<class Script, template<class> class Engine, class Options>
00751     static void run(const Options& opt, Script* s=NULL);
00752   private:
00753     template<class Script, template<class> class Engine, class Options,
00754              template<class, template<class> class> class Meta>
00755     static void runMeta(const Options& opt, Script* s);
00756   };
00757 
00758 #ifdef GECODE_HAS_FLOAT_VARS
00759 
00761   template<class BaseSpace>
00762   class ExtractStepOption : public BaseSpace {
00763   public:
00765     ExtractStepOption(const Options& opt)
00766       : BaseSpace(opt.step()) {}
00768     ExtractStepOption(BaseSpace& e)
00769       : BaseSpace(e) {}
00770   };
00771 
00772 #endif
00773 
00775   template<class BaseSpace>
00776   class IgnoreStepOption : public BaseSpace {
00777   public:
00779     IgnoreStepOption(const Options&) {}
00781     IgnoreStepOption(BaseSpace& e)
00782       : BaseSpace(e) {}
00783   };
00784 
00785 }}
00786 
00787 #include <gecode/driver/script.hpp>
00788 
00789 namespace Gecode {
00790 
00800   typedef Driver::ScriptBase<Driver::IgnoreStepOption<Space> >
00801     Script;
00802 
00807   typedef Driver::ScriptBase<Driver::IgnoreStepOption<IntMinimizeSpace> >
00808     IntMinimizeScript;
00813   typedef Driver::ScriptBase<Driver::IgnoreStepOption<IntMaximizeSpace> >
00814     IntMaximizeScript;
00815 
00820   typedef Driver::ScriptBase<Driver::IgnoreStepOption<IntLexMinimizeSpace> >
00821     IntLexMinimizeScript;
00826   typedef Driver::ScriptBase<Driver::IgnoreStepOption<IntLexMaximizeSpace> >
00827     IntLexMaximizeScript;
00828 
00829 #ifdef GECODE_HAS_FLOAT_VARS
00830 
00835   typedef Driver::ScriptBase<Driver::ExtractStepOption<FloatMinimizeSpace> >
00836     FloatMinimizeScript;
00841   typedef Driver::ScriptBase<Driver::ExtractStepOption<FloatMaximizeSpace> >
00842     FloatMaximizeScript;
00843 
00844 #endif
00845 
00846 }
00847 
00848 #endif
00849 
00850 // STATISTICS: driver-any