Generated on Tue Jul 27 2010 21:59:10 for Gecode by doxygen 1.7.1

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: 2010-04-08 11:25:15 +0200 (Thu, 08 Apr 2010) $ by $Author: tack $
00010  *     $Revision: 10682 $
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 addHtml(const char* s);
00170     public:
00172       TextOutput(const std::string& name);
00174       void finalize(void);
00176       virtual ~TextOutput(void);
00178       virtual std::string name(void);
00179     };
00180     
00182     template<class S>
00183     class Print : public TextOutput, public Inspector {
00184     public:
00186       Print(const std::string& name);
00188       virtual void inspect(const Space& node);
00190       virtual std::string name(void);
00192       virtual void finalize(void);
00193     };
00194 
00205     template<class S>
00206     class VarComparator : public TextOutput, public Comparator {
00207     public:
00209       VarComparator(std::string name);
00211       virtual void compare(const Space& s0, const Space& s1);
00213       virtual std::string name(void);
00215       virtual void finalize(void);
00216     };
00217     
00219     GECODE_GIST_EXPORT
00220     void stopBranch(Space& home);
00221     
00229     class Options : public Search::Options {
00230     public:
00232       class _I {
00233       private:
00234         Support::DynamicArray<Inspector*,Heap> _click;
00235         unsigned int n_click;
00236         Support::DynamicArray<Inspector*,Heap> _solution;
00237         unsigned int n_solution;
00238         Support::DynamicArray<Inspector*,Heap> _move;
00239         unsigned int n_move;
00240         Support::DynamicArray<Comparator*,Heap> _compare;
00241         unsigned int n_compare;
00242       public:
00244         _I(void);
00246         void click(Inspector* i);
00248         void solution(Inspector* i);
00250         void move(Inspector* i);
00252         void compare(Comparator* c);
00253         
00255         Inspector* click(unsigned int i) const;
00257         Inspector* solution(unsigned int i) const;
00259         Inspector* move(unsigned int i) const;
00261         Comparator* compare(unsigned int i) const;
00262       } inspect;
00264       GECODE_GIST_EXPORT static const Options def;
00266       Options(void);
00267     };
00268 
00269     
00271     GECODE_GIST_EXPORT int 
00272     explore(Space* root, bool bab, const Options& opt);
00273     
00278     int 
00279     dfs(Space* root, const Gist::Options& opt = Gist::Options::def);
00280     
00285     int 
00286     bab(Space* root, const Gist::Options& opt = Gist::Options::def);
00287     
00288   }     
00289 
00290 }
00291 
00292 #include <gecode/gist/gist.hpp>
00293 
00294 #endif
00295 
00296 // STATISTICS: gist-any