Generated on Tue Feb 11 2025 17:33:26 for Gecode by doxygen 1.12.0
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
79namespace 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
123
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
137
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
148 static std::string compare(std::string x_n, SetVar x, SetVar y);
149#endif
150#ifdef GECODE_HAS_FLOAT_VARS
152 static std::string compare(std::string x_n, FloatVar x, FloatVar y);
153#endif
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;
267 } inspect;
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
NodeType t
Type of node.
int n
Number of negative literals for node type.
Node * x
Pointer to corresponding Boolean expression node.
Boolean integer variables.
Definition int.hh:512
Float variables.
Definition float.hh:870
Abstract base class for comparators.
Definition gist.hh:119
virtual void compare(const Space &s0, const Space &s1)=0
Call-back function.
Abstract base class for inspectors.
Definition gist.hh:99
virtual void inspect(const Space &s)=0
Call-back function.
Helper class storing inspectors.
Definition gist.hh:237
Options for Gist
Definition gist.hh:234
static const Options def
Default options.
Definition gist.hh:269
An inspector for printing simple text output.
Definition gist.hh:188
Window with associated ostream, used for inspecting Gist nodes.
Definition textoutput.hh:42
An window for simple text output.
Definition gist.hh:160
A simple comparator.
Definition gist.hh:211
Integer variables.
Definition int.hh:371
Search engine options
Definition search.hh:746
Set variables
Definition set.hh:127
Computation spaces.
Definition core.hpp:1742
Array with arbitrary number of elements.
Argument array for variables.
Definition array.hpp:774
#define GECODE_GIST_EXPORT
Definition gist.hh:65
int bab(Space *root, const Gist::Options &opt=Gist::Options::def)
Create a new stand-alone Gist for branch-and-bound search of root.
Definition gist.hpp:208
int dfs(Space *root, const Gist::Options &opt=Gist::Options::def)
Create a new stand-alone Gist for root.
Definition gist.hpp:203
int explore(Space *root, bool bab, const Options &opt)
Create a new stand-alone Gist for root using bab.
Definition gist.cpp:102
void stopBranch(Space &home)
A branching that stops exploration.
Definition gist.cpp:127
Gecode toplevel namespace