Generated on Sat Feb 7 2015 02:01:18 for Gecode by doxygen 1.8.9.1
gist.hh
Go to the documentation of this file.
1 /*
2  * Main authors:
3  * Guido Tack <tack@gecode.org>
4  *
5  * Copyright:
6  * Guido Tack, 2006
7  *
8  * Last modified:
9  * $Date: 2012-03-30 05:58:02 +0200 (Fri, 30 Mar 2012) $ by $Author: tack $
10  * $Revision: 12665 $
11  *
12  * This file is part of Gecode, the generic constraint
13  * development environment:
14  * http://www.gecode.org
15  *
16  * Permission is hereby granted, free of charge, to any person obtaining
17  * a copy of this software and associated documentation files (the
18  * "Software"), to deal in the Software without restriction, including
19  * without limitation the rights to use, copy, modify, merge, publish,
20  * distribute, sublicense, and/or sell copies of the Software, and to
21  * permit persons to whom the Software is furnished to do so, subject to
22  * the following conditions:
23  *
24  * The above copyright notice and this permission notice shall be
25  * included in all copies or substantial portions of the Software.
26  *
27  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
28  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
29  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
30  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
31  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
32  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
33  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34  *
35  */
36 
37 #ifndef __GECODE_GIST_HH__
38 #define __GECODE_GIST_HH__
39 
40 #include <gecode/kernel.hh>
41 #include <gecode/search.hh>
42 #include <gecode/int.hh>
43 #ifdef GECODE_HAS_SET_VARS
44 #include <gecode/set.hh>
45 #endif
46 #ifdef GECODE_HAS_FLOAT_VARS
47 #include <gecode/float.hh>
48 #endif
49 
50 /*
51  * Configure linking
52  *
53  */
54 
55 #if !defined(GIST_STATIC_LIBS) && \
56  (defined(__CYGWIN__) || defined(__MINGW32__) || defined(_MSC_VER))
57 
58 #ifdef GECODE_BUILD_GIST
59 #define GECODE_GIST_EXPORT __declspec( dllexport )
60 #else
61 #define GECODE_GIST_EXPORT __declspec( dllimport )
62 #endif
63 
64 #else
65 
66 #ifdef GECODE_GCC_HAS_CLASS_VISIBILITY
67 #define GECODE_GIST_EXPORT __attribute__ ((visibility("default")))
68 #else
69 #define GECODE_GIST_EXPORT
70 #endif
71 
72 #endif
73 
74 // Configure auto-linking
75 #ifndef GECODE_BUILD_GIST
76 #define GECODE_LIBRARY_NAME "Gist"
78 #endif
79 
80 #include <string>
81 #include <sstream>
82 
83 namespace Gecode {
84 
93  namespace Gist {
94 
104  public:
106  virtual void inspect(const Space& s) = 0;
108  virtual std::string name(void);
110  virtual void finalize(void);
112  virtual ~Inspector(void);
113  };
114 
124  public:
126 
129  virtual void compare(const Space& s0, const Space& s1) = 0;
131  virtual std::string name(void);
133  virtual void finalize(void);
135  virtual ~Comparator(void);
136 
138 
140 
143  template<class Var>
144  static std::string compare(std::string x_n, const VarArgArray<Var>& x,
145  const VarArgArray<Var>& y);
147  static std::string compare(std::string x_n, IntVar x, IntVar y);
149  static std::string compare(std::string x_n, BoolVar x, BoolVar y);
150 #ifdef GECODE_HAS_SET_VARS
151  static std::string compare(std::string x_n, SetVar x, SetVar y);
153 #endif
154 #ifdef GECODE_HAS_FLOAT_VARS
155  static std::string compare(std::string x_n, FloatVar x, FloatVar y);
157 #endif
158 
159  };
160 
161  class TextOutputI;
162 
165  private:
167  TextOutputI *t;
169  std::string n;
170  protected:
172  void init(void);
174  std::ostream& getStream(void);
176  void flush(void);
178  void addHtml(const char* s);
179  public:
181  TextOutput(const std::string& name);
183  void finalize(void);
185  virtual ~TextOutput(void);
187  virtual std::string name(void);
188  };
189 
191  template<class S>
192  class Print : public TextOutput, public Inspector {
193  public:
195  Print(const std::string& name);
197  virtual void inspect(const Space& node);
199  virtual std::string name(void);
201  virtual void finalize(void);
202  };
203 
214  template<class S>
215  class VarComparator : public TextOutput, public Comparator {
216  public:
218  VarComparator(std::string name);
220  virtual void compare(const Space& s0, const Space& s1);
222  virtual std::string name(void);
224  virtual void finalize(void);
225  };
226 
229  void stopBranch(Space& home);
230 
238  class Options : public Search::Options {
239  public:
241  class _I {
242  private:
244  unsigned int n_click;
246  unsigned int n_solution;
248  unsigned int n_move;
250  unsigned int n_compare;
251  public:
253  _I(void);
255  void click(Inspector* i);
257  void solution(Inspector* i);
259  void move(Inspector* i);
261  void compare(Comparator* c);
262 
264  Inspector* click(unsigned int i) const;
266  Inspector* solution(unsigned int i) const;
268  Inspector* move(unsigned int i) const;
270  Comparator* compare(unsigned int i) const;
271  } inspect;
275  Options(void);
276  };
277 
278 
280  GECODE_GIST_EXPORT int
281  explore(Space* root, bool bab, const Options& opt);
282 
287  int
288  dfs(Space* root, const Gist::Options& opt = Gist::Options::def);
289 
294  int
295  bab(Space* root, const Gist::Options& opt = Gist::Options::def);
296 
297  }
298 
299 }
300 
301 #include <gecode/gist/gist.hpp>
302 
303 #endif
304 
305 // STATISTICS: gist-any
void click(Inspector *i)
Add inspector that reacts on node double clicks.
Definition: gist.hpp:174
NodeType t
Type of node.
Definition: bool-expr.cpp:234
Search engine options
Definition: search.hh:204
Abstract base class for comparators.
Definition: gist.hh:123
#define GECODE_GIST_EXPORT
Definition: gist.hh:69
void stopBranch(Space &home)
A branching that stops exploration.
Definition: gist.cpp:114
virtual void inspect(const Space &node)
Use the print method of the template class S to print a space.
Definition: gist.hpp:145
Array with arbitrary number of elements.
Computation spaces.
Definition: core.hpp:1362
Helper class storing inspectors.
Definition: gist.hh:241
Abstract base class for inspectors.
Definition: gist.hh:103
_I(void)
Constructor.
Definition: gist.hpp:169
virtual void finalize(void)
Clean up when Gist exits.
Definition: gist.hpp:161
void solution(Inspector *i)
Add inspector that reacts on each new solution that is found.
Definition: gist.hpp:178
Gecode::FloatVal c(-8, 8)
Gecode::IntArgs i(4, 1, 2, 3, 4)
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
Options opt
The options.
Definition: test.cpp:101
int dfs(Space *root, const Gist::Options &opt)
Create a new stand-alone Gist for root.
Definition: gist.hpp:207
Print(const std::string &name)
Constructor.
Definition: gist.hpp:140
A simple comparator.
Definition: gist.hh:215
Options(void)
Initialize with default values.
Definition: gist.hpp:166
Boolean integer variables.
Definition: int.hh:491
VarComparator(std::string name)
Constructor.
Definition: gist.hpp:41
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:253
virtual void finalize(void)
Finalize when Gist exits.
Definition: gist.hpp:65
Set variables
Definition: set.hh:129
Integer variables.
Definition: int.hh:350
virtual void compare(const Space &s0, const Space &s1)
Compare s0 to s1.
Definition: gist.hpp:46
int bab(Space *root, const Gist::Options &opt)
Create a new stand-alone Gist for branch-and-bound search of root.
Definition: gist.hpp:212
An window for simple text output.
Definition: gist.hh:164
virtual std::string name(void)
Return name.
Definition: gist.hpp:59
static const Options def
Default options.
Definition: gist.hh:273
Float variables.
Definition: float.hh:857
CompareStatus compare(I &i, J &j)
Check whether range iterator i is a subset of j, or whether they are disjoint.
class Gecode::Gist::Options::_I inspect
int explore(Space *root, bool bab, const Options &opt)
Create a new stand-alone Gist for root using bab.
Definition: gist.cpp:105
Gecode toplevel namespace
Argument array for variables.
Definition: array.hpp:53
An inspector for printing simple text output.
Definition: gist.hh:192
Window with associated ostream, used for inspecting Gist nodes.
Definition: textoutput.hh:46
Options for Gist
Definition: gist.hh:238
void compare(Comparator *c)
Add comparator.
Definition: gist.hpp:186
virtual std::string name(void)
Return name.
Definition: gist.hpp:155
void move(Inspector *i)
Add inspector that reacts on each move of the cursor.
Definition: gist.hpp:182