Generated on Thu Jan 16 2025 00:00:00 for Gecode by doxygen 1.14.0
gist.hpp
Go to the documentation of this file.
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2/*
3 * Main authors:
4 * Guido Tack <tack@gecode.org>
5 *
6 * Copyright:
7 * Guido Tack, 2006
8 *
9 * This file is part of Gecode, the generic constraint
10 * development environment:
11 * http://www.gecode.org
12 *
13 * Permission is hereby granted, free of charge, to any person obtaining
14 * a copy of this software and associated documentation files (the
15 * "Software"), to deal in the Software without restriction, including
16 * without limitation the rights to use, copy, modify, merge, publish,
17 * distribute, sublicense, and/or sell copies of the Software, and to
18 * permit persons to whom the Software is furnished to do so, subject to
19 * the following conditions:
20 *
21 * The above copyright notice and this permission notice shall be
22 * included in all copies or substantial portions of the Software.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 *
32 */
33
34namespace Gecode { namespace Gist {
35
36 template<class S>
39
40 template<class S>
41 void
42 VarComparator<S>::compare(const Space& s0, const Space& s1) {
43 std::ostringstream result;
44 dynamic_cast<const S&>(s0).compare(s1,result);
45 if (result.str() != "") {
46 init();
47 addHtml("<pre>\n");
48 getStream() << result.str() << std::endl;
49 addHtml("</pre><hr />");
50 }
51 }
52
53 template<class S>
54 std::string
56 return TextOutput::name();
57 }
58
59 template<class S>
60 void
64
65 inline std::string
66 Comparator::compare(std::string x_n, IntVar x, IntVar y) {
67 IntVarRanges xr(x), yr(y);
68 if (!Iter::Ranges::equal(xr,yr)) {
69 std::ostringstream ret;
70 ret << x_n << "=" << x << " -> " << y;
71 return ret.str();
72 }
73 return "";
74 }
75 inline std::string
76 Comparator::compare(std::string x_n, BoolVar x, BoolVar y) {
77 if (! (x.min() == y.min() && x.max() == y.max()) ) {
78 std::ostringstream ret;
79 ret << x_n << "=" << x << " -> " << y;
80 return ret.str();
81 }
82 return "";
83 }
84#ifdef GECODE_HAS_SET_VARS
85 inline std::string
86 Comparator::compare(std::string x_n, SetVar x, SetVar y) {
87 SetVarGlbRanges xglbr(x), yglbr(y);
88 SetVarLubRanges xlubr(x), ylubr(y);
89 if (! (Iter::Ranges::equal(xglbr,yglbr) &&
90 Iter::Ranges::equal(xlubr,ylubr) &&
91 x.cardMin() == y.cardMin() &&
92 y.cardMax() == y.cardMax()) ) {
93 std::ostringstream ret;
94 ret << x_n << "=" << x << " -> " << y;
95 return ret.str();
96 }
97 return "";
98 }
99#endif
100#ifdef GECODE_HAS_FLOAT_VARS
101 inline std::string
103 if (! (x.min() == y.min() && x.max() == y.max()) ) {
104 std::ostringstream ret;
105 ret << x_n << "=" << x << " -> " << y;
106 return ret.str();
107 }
108 return "";
109 }
110#endif
111 template<class Var>
112 std::string
113 Comparator::compare(std::string x_n, const VarArgArray<Var>& x,
114 const VarArgArray<Var>& y) {
115 if (x.size() != y.size())
116 return "Error: array size mismatch";
117 std::ostringstream ret;
118 bool first = true;
119 for (int i=0; i<x.size(); i++) {
120 std::ostringstream xni;
121 xni << x_n << "[" << i << "]";
122 std::string cmp = compare(xni.str(),x[i],y[i]);
123 if (cmp != "") {
124 if (!first) {
125 ret << ", ";
126 } else {
127 first = false;
128 }
129 ret << cmp;
130 }
131 }
132 return ret.str();
133 }
134
135 template<class S>
136 Print<S>::Print(const std::string& name)
137 : TextOutput(name) {}
138
139 template<class S>
140 void
142 init();
143 addHtml("<pre>\n");
144 dynamic_cast<const S&>(node).print(getStream());
145 flush();
146 addHtml("</pre><hr />");
147 }
148
149 template<class S>
150 std::string
152 return TextOutput::name();
153 }
154
155 template<class S>
156 void
160
163
165 Options::_I::_I(void) : _click(heap,1), n_click(0),
166 _solution(heap,1), n_solution(0),
167 _move(heap,1), n_move(0), _compare(heap,1), n_compare(0) {}
168
169 forceinline void
171 _click[static_cast<int>(n_click++)] = i;
172 }
173 forceinline void
175 _solution[static_cast<int>(n_solution++)] = i;
176 }
177 forceinline void
179 _move[static_cast<int>(n_move++)] = i;
180 }
181 forceinline void
183 _compare[static_cast<int>(n_compare++)] = c;
184 }
186 Options::_I::click(unsigned int i) const {
187 return (i < n_click) ? _click[i] : NULL;
188 }
190 Options::_I::solution(unsigned int i) const {
191 return (i < n_solution) ? _solution[i] : NULL;
192 }
194 Options::_I::move(unsigned int i) const {
195 return (i < n_move) ? _move[i] : NULL;
196 }
198 Options::_I::compare(unsigned int i) const {
199 return (i < n_compare) ? _compare[i] : NULL;
200 }
201
202 inline int
203 dfs(Space* root, const Gist::Options& opt) {
204 return explore(root, false, opt);
205 }
206
207 inline int
208 bab(Space* root, const Gist::Options& opt) {
209 return Gist::explore(root, true, opt);
210 }
211
212}}
213
214// STATISTICS: gist-any
Boolean integer variables.
Definition int.hh:515
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
void click(Inspector *i)
Add inspector that reacts on node double clicks.
Definition gist.hpp:170
void move(Inspector *i)
Add inspector that reacts on each move of the cursor.
Definition gist.hpp:178
void compare(Comparator *c)
Add comparator.
Definition gist.hpp:182
_I(void)
Constructor.
Definition gist.hpp:165
void solution(Inspector *i)
Add inspector that reacts on each new solution that is found.
Definition gist.hpp:174
Options for Gist
Definition gist.hh:234
Options(void)
Initialize with default values.
Definition gist.hpp:162
virtual void inspect(const Space &node)
Use the print method of the template class S to print a space.
Definition gist.hpp:141
virtual std::string name(void)
Return name.
Definition gist.hpp:151
virtual void finalize(void)
Clean up when Gist exits.
Definition gist.hpp:157
Print(const std::string &name)
Constructor.
Definition gist.hpp:136
void finalize(void)
Clean up when Gist exits.
Definition gist.cpp:64
void flush(void)
Flush stream.
Definition gist.cpp:90
TextOutput(const std::string &name)
Constructor.
Definition gist.cpp:60
std::ostream & getStream(void)
Get the stream that is used to output text.
Definition gist.cpp:85
virtual std::string name(void)
Name of the inspector.
Definition gist.cpp:74
void init(void)
Initialize the implementation object.
Definition gist.cpp:77
void addHtml(const char *s)
Add html text s to the output.
Definition gist.cpp:95
VarComparator(std::string name)
Constructor.
Definition gist.hpp:37
virtual void compare(const Space &s0, const Space &s1)
Compare s0 to s1.
Definition gist.hpp:42
virtual std::string name(void)
Return name.
Definition gist.hpp:55
virtual void finalize(void)
Finalize when Gist exits.
Definition gist.hpp:61
Range iterator for integer variables
Definition int.hh:476
Integer variables.
Definition int.hh:371
Iterator for the greatest lower bound ranges of a set variable.
Definition set.hh:273
Iterator for the least upper bound ranges of a set variable.
Definition set.hh:305
Set variables
Definition set.hh:127
Computation spaces.
Definition core.hpp:1744
Argument array for variables.
Definition array.hpp:777
Heap heap
The single global heap.
Definition heap.cpp:44
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
The Gecode Interactive Search Tool.
int explore(Space *root, bool bab, const Options &opt)
Create a new stand-alone Gist for root using bab.
Definition gist.cpp:102
bool equal(I &i, J &j)
Check whether range iterators i and j are equal.
void print(std::basic_ostream< Char, Traits > &s, bool assigned, IL &lb, IU &ub, unsigned int cardMin, unsigned int cardMax)
Print set view.
Definition print.hpp:63
Gecode toplevel namespace
Post propagator for SetVar SetOpType SetVar y
Definition set.hh:773
Post propagator for SetVar x
Definition set.hh:773
#define forceinline
Definition config.hpp:194