Generated on Sat Feb 7 2015 02:01:18 for Gecode by doxygen 1.8.9.1
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  * Last modified:
10  * $Date: 2012-03-30 05:58:02 +0200 (Fri, 30 Mar 2012) $ by $Author: tack $
11  * $Revision: 12665 $
12  *
13  * This file is part of Gecode, the generic constraint
14  * development environment:
15  * http://www.gecode.org
16  *
17  * Permission is hereby granted, free of charge, to any person obtaining
18  * a copy of this software and associated documentation files (the
19  * "Software"), to deal in the Software without restriction, including
20  * without limitation the rights to use, copy, modify, merge, publish,
21  * distribute, sublicense, and/or sell copies of the Software, and to
22  * permit persons to whom the Software is furnished to do so, subject to
23  * the following conditions:
24  *
25  * The above copyright notice and this permission notice shall be
26  * included in all copies or substantial portions of the Software.
27  *
28  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35  *
36  */
37 
38 namespace Gecode { namespace Gist {
39 
40  template<class S>
42  : TextOutput(name) {}
43 
44  template<class S>
45  void
46  VarComparator<S>::compare(const Space& s0, const Space& s1) {
47  std::ostringstream result;
48  dynamic_cast<const S&>(s0).compare(s1,result);
49  if (result.str() != "") {
50  init();
51  addHtml("<pre>\n");
52  getStream() << result.str() << std::endl;
53  addHtml("</pre><hr />");
54  }
55  }
56 
57  template<class S>
58  std::string
60  return TextOutput::name();
61  }
62 
63  template<class S>
64  void
67  }
68 
69  inline std::string
70  Comparator::compare(std::string x_n, IntVar x, IntVar y) {
71  IntVarRanges xr(x), yr(y);
72  if (!Iter::Ranges::equal(xr,yr)) {
73  std::ostringstream ret;
74  ret << x_n << "=" << x << " -> " << y;
75  return ret.str();
76  }
77  return "";
78  }
79  inline std::string
80  Comparator::compare(std::string x_n, BoolVar x, BoolVar y) {
81  if (! (x.min() == y.min() && x.max() == y.max()) ) {
82  std::ostringstream ret;
83  ret << x_n << "=" << x << " -> " << y;
84  return ret.str();
85  }
86  return "";
87  }
88 #ifdef GECODE_HAS_SET_VARS
89  inline std::string
90  Comparator::compare(std::string x_n, SetVar x, SetVar y) {
91  SetVarGlbRanges xglbr(x), yglbr(y);
92  SetVarLubRanges xlubr(x), ylubr(y);
93  if (! (Iter::Ranges::equal(xglbr,yglbr) &&
94  Iter::Ranges::equal(xlubr,ylubr) &&
95  x.cardMin() == y.cardMin() &&
96  y.cardMax() == y.cardMax()) ) {
97  std::ostringstream ret;
98  ret << x_n << "=" << x << " -> " << y;
99  return ret.str();
100  }
101  return "";
102  }
103 #endif
104 #ifdef GECODE_HAS_FLOAT_VARS
105  inline std::string
106  Comparator::compare(std::string x_n, FloatVar x, FloatVar y) {
107  if (! (x.min() == y.min() && x.max() == y.max()) ) {
108  std::ostringstream ret;
109  ret << x_n << "=" << x << " -> " << y;
110  return ret.str();
111  }
112  return "";
113  }
114 #endif
115  template<class Var>
116  std::string
117  Comparator::compare(std::string x_n, const VarArgArray<Var>& x,
118  const VarArgArray<Var>& y) {
119  if (x.size() != y.size())
120  return "Error: array size mismatch";
121  std::ostringstream ret;
122  bool first = true;
123  for (int i=0; i<x.size(); i++) {
124  std::ostringstream xni;
125  xni << x_n << "[" << i << "]";
126  std::string cmp = compare(xni.str(),x[i],y[i]);
127  if (cmp != "") {
128  if (!first) {
129  ret << ", ";
130  } else {
131  first = false;
132  }
133  ret << cmp;
134  }
135  }
136  return ret.str();
137  }
138 
139  template<class S>
140  Print<S>::Print(const std::string& name)
141  : TextOutput(name) {}
142 
143  template<class S>
144  void
145  Print<S>::inspect(const Space& node) {
146  init();
147  addHtml("<pre>\n");
148  dynamic_cast<const S&>(node).print(getStream());
149  flush();
150  addHtml("</pre><hr />");
151  }
152 
153  template<class S>
154  std::string
156  return TextOutput::name();
157  }
158 
159  template<class S>
160  void
163  }
164 
167 
169  Options::_I::_I(void) : _click(heap,1), n_click(0),
170  _solution(heap,1), n_solution(0),
171  _move(heap,1), n_move(0), _compare(heap,1), n_compare(0) {}
172 
173  forceinline void
175  _click[static_cast<int>(n_click++)] = i;
176  }
177  forceinline void
179  _solution[static_cast<int>(n_solution++)] = i;
180  }
181  forceinline void
183  _move[static_cast<int>(n_move++)] = i;
184  }
185  forceinline void
187  _compare[static_cast<int>(n_compare++)] = c;
188  }
190  Options::_I::click(unsigned int i) const {
191  return (i < n_click) ? _click[i] : NULL;
192  }
194  Options::_I::solution(unsigned int i) const {
195  return (i < n_solution) ? _solution[i] : NULL;
196  }
198  Options::_I::move(unsigned int i) const {
199  return (i < n_move) ? _move[i] : NULL;
200  }
202  Options::_I::compare(unsigned int i) const {
203  return (i < n_compare) ? _compare[i] : NULL;
204  }
205 
206  inline int
207  dfs(Space* root, const Gist::Options& opt) {
208  return explore(root, false, opt);
209  }
210 
211  inline int
212  bab(Space* root, const Gist::Options& opt) {
213  return Gist::explore(root, true, opt);
214  }
215 
216 }}
217 
218 // STATISTICS: gist-any
void click(Inspector *i)
Add inspector that reacts on node double clicks.
Definition: gist.hpp:174
unsigned int cardMax(void) const
Return cardinality maximum.
Definition: set.hpp:85
int size(void) const
Return size of array (number of elements)
Abstract base class for comparators.
Definition: gist.hh:123
virtual std::string name(void)
Name of the inspector.
Definition: gist.cpp:77
bool equal(I &i, J &j)
Check whether range iterators i and j are equal.
virtual void inspect(const Space &node)
Use the print method of the template class S to print a space.
Definition: gist.hpp:145
Computation spaces.
Definition: core.hpp:1362
Abstract base class for inspectors.
Definition: gist.hh:103
_I(void)
Constructor.
Definition: gist.hpp:169
FloatNum max(void) const
Return maximum of domain.
Definition: float.hpp:71
virtual void finalize(void)
Clean up when Gist exits.
Definition: gist.hpp:161
Range iterator for integer variables
Definition: int.hh:452
unsigned int cardMin(void) const
Return cardinality minimum.
Definition: set.hpp:82
void solution(Inspector *i)
Add inspector that reacts on each new solution that is found.
Definition: gist.hpp:178
Heap heap
The single global heap.
Definition: heap.cpp:49
Gecode::FloatVal c(-8, 8)
Gecode::IntArgs i(4, 1, 2, 3, 4)
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
void finalize(void)
Clean up when Gist exits.
Definition: gist.cpp:67
Print(const std::string &name)
Constructor.
Definition: gist.hpp:140
Iterator for the greatest lower bound ranges of a set variable.
Definition: set.hh:272
int max(void) const
Return maximum of domain.
Definition: bool.hpp:75
virtual void compare(const Space &s0, const Space &s1)=0
Call-back function.
Options(void)
Initialize with default values.
Definition: gist.hpp:166
Iterator for the least upper bound ranges of a set variable.
Definition: set.hh:304
Boolean integer variables.
Definition: int.hh:491
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:67
VarComparator(std::string name)
Constructor.
Definition: gist.hpp:41
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:253
Set variables
Definition: set.hh:129
virtual void finalize(void)
Finalize when Gist exits.
Definition: gist.hpp:65
FloatNum min(void) const
Return minimum of domain.
Definition: float.hpp:63
Integer variables.
Definition: int.hh:350
#define forceinline
Definition: config.hpp:132
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
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.
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
int min(void) const
Return minimum of domain.
Definition: bool.hpp:67
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