Generated on Sat Feb 7 2015 02:01:26 for Gecode by doxygen 1.8.9.1
cached.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, 2011
8  *
9  * Last modified:
10  * $Date: 2011-07-13 21:27:53 +0200 (Wed, 13 Jul 2011) $ by $Author: tack $
11  * $Revision: 12201 $
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 #include <sstream>
39 
40 namespace Gecode { namespace Set {
41 
42  template<class View>
45 
46  template<class View>
48  CachedView<View>::CachedView(const View& y)
49  : DerivedView<View>(y) {}
50 
51  template<class View>
52  forceinline unsigned int
54  return x.glbSize();
55  }
56 
57  template<class View>
58  forceinline unsigned int
60  return x.lubSize();
61  }
62 
63  template<class View>
64  forceinline unsigned int
66  return x.unknownSize();
67  }
68 
69  template<class View>
70  forceinline bool
71  CachedView<View>::contains(int n) const { return x.contains(n); }
72 
73  template<class View>
74  forceinline bool
75  CachedView<View>::notContains(int n) const { return x.notContains(n); }
76 
77  template<class View>
78  forceinline unsigned int
79  CachedView<View>::cardMin(void) const {
80  return x.cardMin();
81  }
82 
83  template<class View>
84  forceinline unsigned int
85  CachedView<View>::cardMax(void) const {
86  return x.cardMax();
87  }
88 
89  template<class View>
90  forceinline int
91  CachedView<View>::lubMin(void) const {
92  return x.lubMin();
93  }
94 
95  template<class View>
96  forceinline int
97  CachedView<View>::lubMax(void) const {
98  return x.lubMax();
99  }
100 
101  template<class View>
102  forceinline int
103  CachedView<View>::glbMin(void) const {
104  return x.glbMin();
105  }
106 
107  template<class View>
108  forceinline int
109  CachedView<View>::glbMax(void) const {
110  return x.glbMax();
111  }
112 
113  template<class View>
115  CachedView<View>::cardMin(Space& home, unsigned int m) {
116  return x.cardMin(home,m);
117  }
118 
119  template<class View>
121  CachedView<View>::cardMax(Space& home, unsigned int m) {
122  return x.cardMax(home,m);
123  }
124 
125  template<class View>
128  return x.include(home,i);
129  }
130 
131  template<class View>
134  return x.exclude(home,i);
135  }
136 
137  template<class View>
140  return x.intersect(home,i);
141  }
142 
143  template<class View>
145  CachedView<View>::intersect(Space& home, int i, int j) {
146  return x.intersect(home,i,j);
147  }
148 
149  template<class View>
151  CachedView<View>::include(Space& home, int i, int j) {
152  return x.include(home,i,j);
153  }
154 
155  template<class View>
157  CachedView<View>::exclude(Space& home, int i, int j) {
158  return x.exclude(home,i,j);
159  }
160 
161  template<class View>
162  template<class I> ModEvent
164  return x.excludeI(home,iter);
165  }
166 
167  template<class View>
168  template<class I> ModEvent
170  return x.includeI(home,iter);
171  }
172 
173  template<class View>
174  template<class I> ModEvent
176  return x.intersectI(home,iter);
177  }
178 
179  template<class View>
180  forceinline void
182  bool schedule) {
183  x.subscribe(home,p,pc,schedule);
184  }
185 
186  template<class View>
187  forceinline void
189  x.cancel(home,p,pc);
190  }
191 
192  template<class View>
193  forceinline void
195  x.subscribe(home,a);
196  }
197 
198  template<class View>
199  forceinline void
201  x.cancel(home,a);
202  }
203 
204  template<class View>
205  forceinline void
207  return View::schedule(home,p,me);
208  }
209  template<class View>
212  return View::me(med);
213  }
214 
215  template<class View>
218  return View::med(me);
219  }
220 
221  /*
222  * Delta information for advisors
223  *
224  */
225 
226  template<class View>
229  return View::modevent(d);
230  }
231 
232  template<class View>
233  forceinline int
234  CachedView<View>::glbMin(const Delta& d) const {
235  return x.glbMin(d);
236  }
237 
238  template<class View>
239  forceinline int
240  CachedView<View>::glbMax(const Delta& d) const {
241  return x.glbMax(d);
242  }
243 
244  template<class View>
245  forceinline bool
246  CachedView<View>::glbAny(const Delta& d) const {
247  return x.glbAny(d);
248  }
249 
250  template<class View>
251  forceinline int
252  CachedView<View>::lubMin(const Delta& d) const {
253  return x.lubMin(d);
254  }
255 
256  template<class View>
257  forceinline int
258  CachedView<View>::lubMax(const Delta& d) const {
259  return x.lubMax(d);
260  }
261 
262  template<class View>
263  forceinline bool
264  CachedView<View>::lubAny(const Delta& d) const {
265  return x.lubAny(d);
266  }
267 
268  template<class View>
269  forceinline void
270  CachedView<View>::update(Space& home, bool share, CachedView<View>& y) {
271  lubCache.update(home,y.lubCache);
272  glbCache.update(home,y.glbCache);
273  DerivedView<View>::update(home,share,y);
274  }
275 
276  /*
277  * Cache operations
278  *
279  */
280  template<class View>
281  void
283  const IntSet& glb, const IntSet& lub) {
284  glbCache.init(home);
285  IntSetRanges gr(glb);
286  glbCache.includeI(home,gr);
287  lubCache.init(home);
288  IntSetRanges lr(lub);
289  lubCache.intersectI(home,lr);
290  }
291 
292  template<class View>
293  forceinline void
296  glbCache.includeI(home,gr);
297  }
298 
299  template<class View>
300  forceinline void
303  lubCache.intersectI(home,lr);
304  }
305 
306  template<class View>
307  forceinline bool
309  return glbCache.size() != glbSize();
310  }
311 
312  template<class View>
313  forceinline bool
315  return lubCache.size() != lubSize();
316  }
317 
322  template<class View>
323  class LubRanges<CachedView<View> > : public LubRanges<View> {
324  public:
326 
327  LubRanges(void) {}
330  LubRanges(const CachedView<View>& x);
332  void init(const CachedView<View>& x);
334  };
335 
336  template<class View>
339  : LubRanges<View>(s.base()) {}
340 
341  template<class View>
342  forceinline void
345  }
346 
351  template<class View>
352  class GlbRanges<CachedView<View> > : public GlbRanges<View> {
353  public:
355 
356  GlbRanges(void) {}
359  GlbRanges(const CachedView<View> & x);
361  void init(const CachedView<View> & x);
363  };
364 
365  template<class View>
368  : GlbRanges<View>(s.base()) {}
369 
370  template<class View>
371  forceinline void
374  }
375 
376  template<class Char, class Traits, class View>
377  std::basic_ostream<Char,Traits>&
378  operator <<(std::basic_ostream<Char,Traits>& os,
379  const CachedView<View>& x) {
380  return os << x.base();
381  }
382 
383  template<class View>
386  : gr(x.base()), cr(x.glbCache) {
388  }
389 
390  template<class View>
393  : cr(x.lubCache), lr(x.base()) {
395  }
396 
397 }}
398 
399 // STATISTICS: set-var
static ModEvent modevent(const Delta &d)
Return modification event.
Definition: view.hpp:585
Range iterator for integer sets.
Definition: int.hh:271
static void schedule(Space &home, Propagator &p, ModEvent me)
Schedule propagator p with modification event me.
Definition: view.hpp:548
int ModEvent
Type for modification events.
Definition: core.hpp:146
void cancel(Space &home, Propagator &p, PropCond pc)
Cancel subscription of propagator p with propagation condition pc to view.
Definition: view.hpp:570
Base-class for propagators.
Definition: core.hpp:755
Base-class for advisors.
Definition: core.hpp:926
BndSetRanges cr
Cached lower bound.
Definition: view.hpp:1105
Computation spaces.
Definition: core.hpp:1362
Base-class for derived views.
Definition: view.hpp:208
ModEvent exclude(Space &home, View &x, int s)
Prune view x to exclude all values from s.
Definition: set-op.hpp:141
Gecode::IntSet d(v, 7)
int med(void) const
Return median of domain (greatest element not greater than the median)
Definition: cached.hpp:70
GlbDiffRanges(const CachedView< View > &x)
Constructor.
Definition: cached.hpp:385
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:236
Gecode::IntArgs i(4, 1, 2, 3, 4)
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
FloatVal intersect(const FloatVal &x, const FloatVal &y)
Definition: val.hpp:507
View base(void) const
Return view from which this view is derived.
Definition: view.hpp:526
int PropCond
Type for propagation conditions.
Definition: core.hpp:156
void update(Space &home, bool share, DerivedView< View > &y)
Update this view to be a clone of view y.
Definition: view.hpp:590
Range iterator for integer sets.
Definition: var-imp.hpp:189
CachedView(void)
Default constructor.
Definition: cached.hpp:46
Integer sets.
Definition: int.hh:171
void update(Space &home, bool share, CachedView< View > &y)
Update this view to be a clone of view y.
Definition: cached.hpp:269
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:253
Generic domain change information to be supplied to advisors.
Definition: core.hpp:275
unsigned int size(void) const
Return size (cardinality) of domain.
Definition: cached.hpp:86
ModEvent include(Space &home, View &x, int s)
Prune view x to only include values from s.
Definition: set-op.hpp:127
GlbRanges(void)
Default constructor.
#define forceinline
Definition: config.hpp:132
void init(const T &x)
Initialize with least upper bound ranges for set variable x.
Cached integer view.
Definition: view.hpp:1107
void subscribe(Space &home, Propagator &p, PropCond pc, bool schedule=true)
Subscribe propagator p with propagation condition pc to view.
Definition: view.hpp:564
static ModEvent me(const ModEventDelta &med)
Return modification event for view type in med.
Definition: view.hpp:553
Gecode toplevel namespace
LubRanges< View > lr
Upper bound iterator.
Definition: view.hpp:1122
Range iterator for computing set difference.
Definition: ranges-diff.hpp:47
LubDiffRanges(const CachedView< View > &x)
Constructor.
Definition: cached.hpp:392
LubRanges(void)
Default constructor.
void init(GlbRanges< View > &i, BndSetRanges &j)
Initialize with iterator i and j.
GlbRanges< View > gr
Lower bound iterator.
Definition: view.hpp:1103
int ModEventDelta
Modification event deltas.
Definition: core.hpp:173
void initCache(Space &home, const IntSet &s)
Initialize cache to set s.
Definition: cached.hpp:295
struct Gecode::@518::NNF::@57::@59 a
For atomic nodes.
void init(const T &x)
Initialize with greatest lower bound ranges for set variable x.
BndSetRanges cr
Cached upper bound.
Definition: view.hpp:1120