Generated on Thu Mar 22 10:39:32 2012 for Gecode by doxygen 1.6.3

gist.hh

Go to the documentation of this file.
00001 /*
00002  *  Main authors:
00003  *     Guido Tack <tack@gecode.org>
00004  *
00005  *  Copyright:
00006  *     Guido Tack, 2006
00007  *
00008  *  Last modified:
00009  *     $Date: 2011-08-25 10:43:31 +0200 (Thu, 25 Aug 2011) $ by $Author: tack $
00010  *     $Revision: 12352 $
00011  *
00012  *  This file is part of Gecode, the generic constraint
00013  *  development environment:
00014  *     http://www.gecode.org
00015  *
00016  * Permission is hereby granted, free of charge, to any person obtaining
00017  * a copy of this software and associated documentation files (the
00018  * "Software"), to deal in the Software without restriction, including
00019  * without limitation the rights to use, copy, modify, merge, publish,
00020  * distribute, sublicense, and/or sell copies of the Software, and to
00021  * permit persons to whom the Software is furnished to do so, subject to
00022  * the following conditions:
00023  *
00024  * The above copyright notice and this permission notice shall be
00025  * included in all copies or substantial portions of the Software.
00026  *
00027  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00028  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00029  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00030  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00031  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00032  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00033  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00034  *
00035  */
00036 
00037 #ifndef __GECODE_GIST_HH__
00038 #define __GECODE_GIST_HH__
00039 
00040 #include <gecode/kernel.hh>
00041 #include <gecode/search.hh>
00042 #include <gecode/int.hh>
00043 #ifdef GECODE_HAS_SET_VARS
00044 #include <gecode/set.hh>
00045 #endif
00046 
00047 /*
00048  * Configure linking
00049  *
00050  */
00051 
00052 #if !defined(GIST_STATIC_LIBS) && \
00053     (defined(__CYGWIN__) || defined(__MINGW32__) || defined(_MSC_VER))
00054 
00055 #ifdef GECODE_BUILD_GIST
00056 #define GECODE_GIST_EXPORT __declspec( dllexport )
00057 #else
00058 #define GECODE_GIST_EXPORT __declspec( dllimport )
00059 #endif
00060 
00061 #else
00062 
00063 #ifdef GECODE_GCC_HAS_CLASS_VISIBILITY
00064 #define GECODE_GIST_EXPORT __attribute__ ((visibility("default")))
00065 #else
00066 #define GECODE_GIST_EXPORT
00067 #endif
00068 
00069 #endif
00070 
00071 // Configure auto-linking
00072 #ifndef GECODE_BUILD_GIST
00073 #define GECODE_LIBRARY_NAME "Gist"
00074 #include <gecode/support/auto-link.hpp>
00075 #endif
00076 
00077 #include <string>
00078 #include <sstream>
00079 
00080 namespace Gecode {
00081 
00090   namespace Gist {
00091 
00100     class GECODE_GIST_EXPORT Inspector {
00101     public:
00103       virtual void inspect(const Space& s) = 0;
00105       virtual std::string name(void);
00107       virtual void finalize(void);
00109       virtual ~Inspector(void);
00110     };
00111 
00120     class GECODE_GIST_EXPORT Comparator {
00121     public:
00123 
00124       
00126       virtual void compare(const Space& s0, const Space& s1) = 0;
00128       virtual std::string name(void);
00130       virtual void finalize(void);
00132       virtual ~Comparator(void);
00133 
00135 
00137 
00138       
00140       template<class Var>
00141       static std::string compare(std::string x_n, const VarArgArray<Var>& x,
00142         const VarArgArray<Var>& y);
00144       static std::string compare(std::string x_n, IntVar x, IntVar y);
00146       static std::string compare(std::string x_n, BoolVar x, BoolVar y);
00147 #ifdef GECODE_HAS_SET_VARS
00148 
00149       static std::string compare(std::string x_n, SetVar x, SetVar y);
00150 #endif
00151 
00152     };
00153         
00154     class TextOutputI;
00155     
00157     class GECODE_GIST_EXPORT TextOutput {
00158     private:
00160       TextOutputI *t;
00162       std::string n;
00163     protected:
00165       void init(void);
00167       std::ostream& getStream(void);
00169       void flush(void);
00171       void addHtml(const char* s);
00172     public:
00174       TextOutput(const std::string& name);
00176       void finalize(void);
00178       virtual ~TextOutput(void);
00180       virtual std::string name(void);
00181     };
00182     
00184     template<class S>
00185     class Print : public TextOutput, public Inspector {
00186     public:
00188       Print(const std::string& name);
00190       virtual void inspect(const Space& node);
00192       virtual std::string name(void);
00194       virtual void finalize(void);
00195     };
00196 
00207     template<class S>
00208     class VarComparator : public TextOutput, public Comparator {
00209     public:
00211       VarComparator(std::string name);
00213       virtual void compare(const Space& s0, const Space& s1);
00215       virtual std::string name(void);
00217       virtual void finalize(void);
00218     };
00219     
00221     GECODE_GIST_EXPORT
00222     void stopBranch(Space& home);
00223     
00231     class Options : public Search::Options {
00232     public:
00234       class _I {
00235       private:
00236         Support::DynamicArray<Inspector*,Heap> _click;
00237         unsigned int n_click;
00238         Support::DynamicArray<Inspector*,Heap> _solution;
00239         unsigned int n_solution;
00240         Support::DynamicArray<Inspector*,Heap> _move;
00241         unsigned int n_move;
00242         Support::DynamicArray<Comparator*,Heap> _compare;
00243         unsigned int n_compare;
00244       public:
00246         _I(void);
00248         void click(Inspector* i);
00250         void solution(Inspector* i);
00252         void move(Inspector* i);
00254         void compare(Comparator* c);
00255         
00257         Inspector* click(unsigned int i) const;
00259         Inspector* solution(unsigned int i) const;
00261         Inspector* move(unsigned int i) const;
00263         Comparator* compare(unsigned int i) const;
00264       } inspect;
00266       GECODE_GIST_EXPORT static const Options def;
00268       Options(void);
00269     };
00270 
00271     
00273     GECODE_GIST_EXPORT int 
00274     explore(Space* root, bool bab, const Options& opt);
00275     
00280     int 
00281     dfs(Space* root, const Gist::Options& opt = Gist::Options::def);
00282     
00287     int 
00288     bab(Space* root, const Gist::Options& opt = Gist::Options::def);
00289     
00290   }     
00291 
00292 }
00293 
00294 #include <gecode/gist/gist.hpp>
00295 
00296 #endif
00297 
00298 // STATISTICS: gist-any