Generated on Mon Jul 27 2020 00:00:00 for Gecode by doxygen 1.8.18
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  * This file is part of Gecode, the generic constraint
9  * development environment:
10  * http://www.gecode.org
11  *
12  * Permission is hereby granted, free of charge, to any person obtaining
13  * a copy of this software and associated documentation files (the
14  * "Software"), to deal in the Software without restriction, including
15  * without limitation the rights to use, copy, modify, merge, publish,
16  * distribute, sublicense, and/or sell copies of the Software, and to
17  * permit persons to whom the Software is furnished to do so, subject to
18  * the following conditions:
19  *
20  * The above copyright notice and this permission notice shall be
21  * included in all copies or substantial portions of the Software.
22  *
23  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30  *
31  */
32 
33 #ifndef __GECODE_GIST_HH__
34 #define __GECODE_GIST_HH__
35 
36 #include <gecode/kernel.hh>
37 #include <gecode/search.hh>
38 #include <gecode/int.hh>
39 #ifdef GECODE_HAS_SET_VARS
40 #include <gecode/set.hh>
41 #endif
42 #ifdef GECODE_HAS_FLOAT_VARS
43 #include <gecode/float.hh>
44 #endif
45 
46 /*
47  * Configure linking
48  *
49  */
50 
51 #if !defined(GIST_STATIC_LIBS) && \
52  (defined(__CYGWIN__) || defined(__MINGW32__) || defined(_MSC_VER))
53 
54 #ifdef GECODE_BUILD_GIST
55 #define GECODE_GIST_EXPORT __declspec( dllexport )
56 #else
57 #define GECODE_GIST_EXPORT __declspec( dllimport )
58 #endif
59 
60 #else
61 
62 #ifdef GECODE_GCC_HAS_CLASS_VISIBILITY
63 #define GECODE_GIST_EXPORT __attribute__ ((visibility("default")))
64 #else
65 #define GECODE_GIST_EXPORT
66 #endif
67 
68 #endif
69 
70 // Configure auto-linking
71 #ifndef GECODE_BUILD_GIST
72 #define GECODE_LIBRARY_NAME "Gist"
74 #endif
75 
76 #include <string>
77 #include <sstream>
78 
79 namespace Gecode {
80 
89  namespace Gist {
90 
100  public:
102  virtual void inspect(const Space& s) = 0;
104  virtual std::string name(void);
106  virtual void finalize(void);
108  virtual ~Inspector(void);
109  };
110 
120  public:
122 
125  virtual void compare(const Space& s0, const Space& s1) = 0;
127  virtual std::string name(void);
129  virtual void finalize(void);
131  virtual ~Comparator(void);
132 
134 
136 
139  template<class Var>
140  static std::string compare(std::string x_n, const VarArgArray<Var>& x,
141  const VarArgArray<Var>& y);
143  static std::string compare(std::string x_n, IntVar x, IntVar y);
145  static std::string compare(std::string x_n, BoolVar x, BoolVar y);
146 #ifdef GECODE_HAS_SET_VARS
147  static std::string compare(std::string x_n, SetVar x, SetVar y);
149 #endif
150 #ifdef GECODE_HAS_FLOAT_VARS
151  static std::string compare(std::string x_n, FloatVar x, FloatVar y);
153 #endif
154 
155  };
156 
157  class TextOutputI;
158 
161  private:
163  TextOutputI *t;
165  std::string n;
166  protected:
168  void init(void);
170  std::ostream& getStream(void);
172  void flush(void);
174  void addHtml(const char* s);
175  public:
177  TextOutput(const std::string& name);
179  void finalize(void);
181  virtual ~TextOutput(void);
183  virtual std::string name(void);
184  };
185 
187  template<class S>
188  class Print : public TextOutput, public Inspector {
189  public:
191  Print(const std::string& name);
193  virtual void inspect(const Space& node);
195  virtual std::string name(void);
197  virtual void finalize(void);
198  };
199 
210  template<class S>
211  class VarComparator : public TextOutput, public Comparator {
212  public:
214  VarComparator(std::string name);
216  virtual void compare(const Space& s0, const Space& s1);
218  virtual std::string name(void);
220  virtual void finalize(void);
221  };
222 
225  void stopBranch(Space& home);
226 
234  class Options : public Search::Options {
235  public:
237  class _I {
238  private:
240  unsigned int n_click;
242  unsigned int n_solution;
244  unsigned int n_move;
246  unsigned int n_compare;
247  public:
249  _I(void);
251  void click(Inspector* i);
253  void solution(Inspector* i);
255  void move(Inspector* i);
257  void compare(Comparator* c);
258 
260  Inspector* click(unsigned int i) const;
262  Inspector* solution(unsigned int i) const;
264  Inspector* move(unsigned int i) const;
266  Comparator* compare(unsigned int i) const;
271  Options(void);
272  };
273 
274 
277  explore(Space* root, bool bab, const Options& opt);
278 
283  int
284  dfs(Space* root, const Gist::Options& opt = Gist::Options::def);
285 
290  int
291  bab(Space* root, const Gist::Options& opt = Gist::Options::def);
292 
293  }
294 
295 }
296 
297 #include <gecode/gist/gist.hpp>
298 
299 #endif
300 
301 // STATISTICS: gist-any
void compare(Comparator *c)
Add comparator.
Definition: gist.hpp:182
Post propagator for SetVar x
Definition: set.hh:767
Post propagator for SetVar SetOpType SetVar y
Definition: set.hh:767
Abstract base class for comparators.
Definition: gist.hh:119
Search engine options
Definition: search.hh:746
void click(Inspector *i)
Add inspector that reacts on node double clicks.
Definition: gist.hpp:170
class Gecode::Gist::Options::_I inspect
Array with arbitrary number of elements.
virtual void compare(const Space &s0, const Space &s1)=0
Call-back function.
NodeType t
Type of node.
Definition: bool-expr.cpp:230
void solution(Inspector *i)
Add inspector that reacts on each new solution that is found.
Definition: gist.hpp:174
Abstract base class for inspectors.
Definition: gist.hh:99
Computation spaces.
Definition: core.hpp:1742
A simple comparator.
Definition: gist.hh:211
virtual void finalize(void)
Clean up when Gist exits.
Definition: gist.hpp:157
virtual void inspect(const Space &node)
Use the print method of the template class S to print a space.
Definition: gist.hpp:141
int dfs(Space *root, const Gist::Options &opt)
Create a new stand-alone Gist for root.
Definition: gist.hpp:203
Gecode toplevel namespace
Print(const std::string &name)
Constructor.
Definition: gist.hpp:136
Options opt
The options.
Definition: test.cpp:97
Options for Gist
Definition: gist.hh:234
void stopBranch(Space &home)
A branching that stops exploration.
Definition: gist.cpp:127
#define GECODE_GIST_EXPORT
Definition: gist.hh:65
Options(void)
Initialize with default values.
Definition: gist.hpp:162
virtual void compare(const Space &s0, const Space &s1)
Compare s0 to s1.
Definition: gist.hpp:42
void move(Inspector *i)
Add inspector that reacts on each move of the cursor.
Definition: gist.hpp:178
Boolean integer variables.
Definition: int.hh:512
_I(void)
Constructor.
Definition: gist.hpp:165
Set variables
Definition: set.hh:127
VarComparator(std::string name)
Constructor.
Definition: gist.hpp:37
An inspector for printing simple text output.
Definition: gist.hh:188
Integer variables.
Definition: int.hh:371
Window with associated ostream, used for inspecting Gist nodes.
Definition: textoutput.hh:42
int explore(Space *root, bool bab, const Options &opt)
Create a new stand-alone Gist for root using bab.
Definition: gist.cpp:102
static const Options def
Default options.
Definition: gist.hh:269
Float variables.
Definition: float.hh:870
virtual void inspect(const Space &s)=0
Call-back function.
int bab(Space *root, const Gist::Options &opt)
Create a new stand-alone Gist for branch-and-bound search of root.
Definition: gist.hpp:208
Helper class storing inspectors.
Definition: gist.hh:237
Gecode::FloatVal c(-8, 8)
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:234
virtual void finalize(void)
Finalize when Gist exits.
Definition: gist.hpp:61
virtual std::string name(void)
Return name.
Definition: gist.hpp:151
Argument array for variables.
Definition: array.hpp:79
CompareStatus compare(I &i, J &j)
Check whether range iterator i is a subset of j, or whether they are disjoint.
Gecode::IntArgs i({1, 2, 3, 4})
An window for simple text output.
Definition: gist.hh:160
virtual std::string name(void)
Return name.
Definition: gist.hpp:55