Generated on Wed Mar 19 07:29:54 2008 for Gecode by doxygen 1.5.5

support.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, 2007
00008  *
00009  *  Last modified:
00010  *     $Date: 2008-02-05 18:46:41 +0100 (Tue, 05 Feb 2008) $ by $Author: schulte $
00011  *     $Revision: 6067 $
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_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  * Options for running the examples
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 
00148 enum SAC {
00149   SAC_NONE, 
00150   SAC_ONE,  
00151   SAC_FULL  
00152 };
00153 
00158 class Options {
00159 protected:
00160   BaseOption* fst;   
00161   BaseOption* lst;   
00162   const char* _name; 
00163 
00165 
00166   StringOption _model;       
00167   StringOption _propagation; 
00168   StringOption _pk;          
00169   StringOption _icl;         
00170   StringOption _branching;   
00171   StringOption _sac;         
00172 
00173 
00175 
00176   StringOption      _search;    
00177   UnsignedIntOption _solutions; 
00178   UnsignedIntOption _c_d;       
00179   UnsignedIntOption _a_d;       
00180   UnsignedIntOption _fail;      
00181   UnsignedIntOption _time;      
00182 
00183 
00185 
00186   StringOption      _mode;       
00187   UnsignedIntOption _samples;    
00188   UnsignedIntOption _iterations; 
00189 
00190 
00191 public:
00193   Options(const char* s);
00195   void add(BaseOption& o);
00197   virtual void help(void);
00199   void parse(int& argc, char* argv[]);
00200 
00202   const char* name(void) const;
00203 
00205 
00206 
00207   void model(int v);
00209   void model(int v, const char* o, const char* h = NULL);
00211   int model(void) const;
00212 
00214   void propagation(int v);
00216   void propagation(int v, const char* o, const char* h = NULL);
00218   int propagation(void) const;
00219 
00221   void pk(PropKind p);
00223   PropKind pk(void) const;
00224 
00226   void icl(IntConLevel i);
00228   IntConLevel icl(void) const;
00229 
00231   void branching(int v);
00233   void branching(int v, const char* o, const char* h = NULL);
00235   int branching(void) const;
00236 
00238   void sac(int v);
00240   void sac(int v, const char* p, const char* h = NULL);
00242   int sac(void) const;
00244 
00246 
00247 
00248   void search(int v);
00250   void search(int v, const char* o, const char* h = NULL);
00252   int search(void) const;
00253 
00255   void solutions(unsigned int n);
00257   unsigned int solutions(void) const;
00258 
00260   void c_d(unsigned int d);
00262   unsigned int c_d(void) const;
00263 
00265   void a_d(unsigned int d);
00267   unsigned int a_d(void) const;
00268 
00270   void fail(unsigned int n);
00272   unsigned int fail(void) const;
00273 
00275   void time(unsigned int t);
00277   unsigned int time(void) const;
00279 
00281 
00282 
00283   void mode(ExampleMode em);
00285   ExampleMode mode(void) const;  
00286 
00288   void iterations(unsigned int i);
00290   unsigned int iterations(void) const;
00291 
00293   void samples(unsigned int s);
00295   unsigned int samples(void) const;
00297 
00299   virtual ~Options(void);
00300 };
00301 
00306 class SizeOptions : public Options {
00307 protected:
00308   unsigned int _size; 
00309 public:
00311   SizeOptions(const char* s);
00313   virtual void help(void);
00315   void parse(int& argc, char* argv[]);
00316 
00318   void size(unsigned int s);
00320   unsigned int size(void) const;
00321 };
00322 
00323 #include "examples/support/options.icc"
00324 
00325 
00334 class Example : public Space {
00335 public:
00337   Example(void) {}
00339   Example(bool share, Example& e) : Space(share,e) {
00341     _sac_bva.update(this, share, e._sac_bva);
00342     _sac_iva.update(this, share, e._sac_iva);
00343   }
00345   virtual void print(std::ostream& os) { (void)os; }
00347   template <class Script, template<class> class Engine, class Options>
00348   static void run(const Options& opt);
00349  private:
00351   BoolVarArray _sac_bva;
00353   IntVarArray _sac_iva;
00354  protected:
00356   void sac_collect_vars(void);
00358   void sac_remove_vars(void);
00363   bool sac(unsigned long int& p);
00364  private:
00366   explicit Example(Example& e);
00367 };
00368 
00369 #include "examples/support/example.icc"
00370 
00371 #endif
00372 
00373 // STATISTICS: example-any