Generated on Tue Apr 18 10:21:45 2017 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: 2016-04-19 17:19:45 +0200 (Tue, 19 Apr 2016) $ by $Author: schulte $
00010  *     $Revision: 14967 $
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 #ifdef GECODE_HAS_FLOAT_VARS
00047 #include <gecode/float.hh>
00048 #endif
00049 
00050 /*
00051  * Configure linking
00052  *
00053  */
00054 
00055 #if !defined(GIST_STATIC_LIBS) && \
00056     (defined(__CYGWIN__) || defined(__MINGW32__) || defined(_MSC_VER))
00057 
00058 #ifdef GECODE_BUILD_GIST
00059 #define GECODE_GIST_EXPORT __declspec( dllexport )
00060 #else
00061 #define GECODE_GIST_EXPORT __declspec( dllimport )
00062 #endif
00063 
00064 #else
00065 
00066 #ifdef GECODE_GCC_HAS_CLASS_VISIBILITY
00067 #define GECODE_GIST_EXPORT __attribute__ ((visibility("default")))
00068 #else
00069 #define GECODE_GIST_EXPORT
00070 #endif
00071 
00072 #endif
00073 
00074 // Configure auto-linking
00075 #ifndef GECODE_BUILD_GIST
00076 #define GECODE_LIBRARY_NAME "Gist"
00077 #include <gecode/support/auto-link.hpp>
00078 #endif
00079 
00080 #include <string>
00081 #include <sstream>
00082 
00083 namespace Gecode {
00084 
00093   namespace Gist {
00094 
00103     class GECODE_GIST_EXPORT Inspector {
00104     public:
00106       virtual void inspect(const Space& s) = 0;
00108       virtual std::string name(void);
00110       virtual void finalize(void);
00112       virtual ~Inspector(void);
00113     };
00114 
00123     class GECODE_GIST_EXPORT Comparator {
00124     public:
00126 
00127 
00129       virtual void compare(const Space& s0, const Space& s1) = 0;
00131       virtual std::string name(void);
00133       virtual void finalize(void);
00135       virtual ~Comparator(void);
00136 
00138 
00140 
00141 
00143       template<class Var>
00144       static std::string compare(std::string x_n, const VarArgArray<Var>& x,
00145         const VarArgArray<Var>& y);
00147       static std::string compare(std::string x_n, IntVar x, IntVar y);
00149       static std::string compare(std::string x_n, BoolVar x, BoolVar y);
00150 #ifdef GECODE_HAS_SET_VARS
00151 
00152       static std::string compare(std::string x_n, SetVar x, SetVar y);
00153 #endif
00154 #ifdef GECODE_HAS_FLOAT_VARS
00155 
00156       static std::string compare(std::string x_n, FloatVar x, FloatVar y);
00157 #endif
00158 
00159     };
00160 
00161     class TextOutputI;
00162 
00164     class GECODE_GIST_EXPORT TextOutput {
00165     private:
00167       TextOutputI *t;
00169       std::string n;
00170     protected:
00172       void init(void);
00174       std::ostream& getStream(void);
00176       void flush(void);
00178       void addHtml(const char* s);
00179     public:
00181       TextOutput(const std::string& name);
00183       void finalize(void);
00185       virtual ~TextOutput(void);
00187       virtual std::string name(void);
00188     };
00189 
00191     template<class S>
00192     class Print : public TextOutput, public Inspector {
00193     public:
00195       Print(const std::string& name);
00197       virtual void inspect(const Space& node);
00199       virtual std::string name(void);
00201       virtual void finalize(void);
00202     };
00203 
00214     template<class S>
00215     class VarComparator : public TextOutput, public Comparator {
00216     public:
00218       VarComparator(std::string name);
00220       virtual void compare(const Space& s0, const Space& s1);
00222       virtual std::string name(void);
00224       virtual void finalize(void);
00225     };
00226 
00228     GECODE_GIST_EXPORT
00229     void stopBranch(Space& home);
00230 
00238     class Options : public Search::Options {
00239     public:
00241       class _I {
00242       private:
00243         Support::DynamicArray<Inspector*,Heap> _click;
00244         unsigned int n_click;
00245         Support::DynamicArray<Inspector*,Heap> _solution;
00246         unsigned int n_solution;
00247         Support::DynamicArray<Inspector*,Heap> _move;
00248         unsigned int n_move;
00249         Support::DynamicArray<Comparator*,Heap> _compare;
00250         unsigned int n_compare;
00251       public:
00253         _I(void);
00255         void click(Inspector* i);
00257         void solution(Inspector* i);
00259         void move(Inspector* i);
00261         void compare(Comparator* c);
00262 
00264         Inspector* click(unsigned int i) const;
00266         Inspector* solution(unsigned int i) const;
00268         Inspector* move(unsigned int i) const;
00270         Comparator* compare(unsigned int i) const;
00271       } inspect;
00273       GECODE_GIST_EXPORT static const Options def;
00275       Options(void);
00276     };
00277 
00278 
00280     GECODE_GIST_EXPORT int
00281     explore(Space* root, bool bab, const Options& opt);
00282 
00287     int
00288     dfs(Space* root, const Gist::Options& opt = Gist::Options::def);
00289 
00294     int
00295     bab(Space* root, const Gist::Options& opt = Gist::Options::def);
00296 
00297   }
00298 
00299 }
00300 
00301 #include <gecode/gist/gist.hpp>
00302 
00303 #endif
00304 
00305 // STATISTICS: gist-any