Generated on Thu Feb 14 2013 20:59:23 for Gecode by doxygen 1.8.3.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: 2011-08-25 18:43:31 +1000 (Thu, 25 Aug 2011) $ by $Author: tack $
11  * $Revision: 12352 $
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  template<class Var>
105  std::string
106  Comparator::compare(std::string x_n, const VarArgArray<Var>& x,
107  const VarArgArray<Var>& y) {
108  if (x.size() != y.size())
109  return "Error: array size mismatch";
110  std::ostringstream ret;
111  bool first = true;
112  for (int i=0; i<x.size(); i++) {
113  std::ostringstream xni;
114  xni << x_n << "[" << i << "]";
115  std::string cmp = compare(xni.str(),x[i],y[i]);
116  if (cmp != "") {
117  if (!first) {
118  ret << ", ";
119  } else {
120  first = false;
121  }
122  ret << cmp;
123  }
124  }
125  return ret.str();
126  }
127 
128  template<class S>
129  Print<S>::Print(const std::string& name)
130  : TextOutput(name) {}
131 
132  template<class S>
133  void
134  Print<S>::inspect(const Space& node) {
135  init();
136  addHtml("<pre>\n");
137  dynamic_cast<const S&>(node).print(getStream());
138  flush();
139  addHtml("</pre><hr />");
140  }
141 
142  template<class S>
143  std::string
145  return TextOutput::name();
146  }
147 
148  template<class S>
149  void
152  }
153 
156 
158  Options::_I::_I(void) : _click(heap,1), n_click(0),
159  _solution(heap,1), n_solution(0),
160  _move(heap,1), n_move(0), _compare(heap,1), n_compare(0) {}
161 
162  forceinline void
164  _click[static_cast<int>(n_click++)] = i;
165  }
166  forceinline void
168  _solution[static_cast<int>(n_solution++)] = i;
169  }
170  forceinline void
172  _move[static_cast<int>(n_move++)] = i;
173  }
174  forceinline void
176  _compare[static_cast<int>(n_compare++)] = c;
177  }
179  Options::_I::click(unsigned int i) const {
180  return (i < n_click) ? _click[i] : NULL;
181  }
183  Options::_I::solution(unsigned int i) const {
184  return (i < n_solution) ? _solution[i] : NULL;
185  }
187  Options::_I::move(unsigned int i) const {
188  return (i < n_move) ? _move[i] : NULL;
189  }
191  Options::_I::compare(unsigned int i) const {
192  return (i < n_compare) ? _compare[i] : NULL;
193  }
194 
195  inline int
196  dfs(Space* root, const Gist::Options& opt) {
197  return explore(root, false, opt);
198  }
199 
200  inline int
201  bab(Space* root, const Gist::Options& opt) {
202  return Gist::explore(root, true, opt);
203  }
204 
205 }}
206 
207 // STATISTICS: gist-any