Generated on Wed Jan 1 2020 10:37:59 for Gecode by doxygen 1.8.16
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  * 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 
34 #include <sstream>
35 
36 namespace Gecode { namespace Set {
37 
38  template<class View>
41 
42  template<class View>
44  CachedView<View>::CachedView(const View& y)
45  : DerivedView<View>(y) {}
46 
47  template<class View>
48  forceinline unsigned int
50  return x.glbSize();
51  }
52 
53  template<class View>
54  forceinline unsigned int
56  return x.lubSize();
57  }
58 
59  template<class View>
60  forceinline unsigned int
62  return x.unknownSize();
63  }
64 
65  template<class View>
66  forceinline bool
67  CachedView<View>::contains(int n) const { return x.contains(n); }
68 
69  template<class View>
70  forceinline bool
71  CachedView<View>::notContains(int n) const { return x.notContains(n); }
72 
73  template<class View>
74  forceinline unsigned int
76  return x.cardMin();
77  }
78 
79  template<class View>
80  forceinline unsigned int
82  return x.cardMax();
83  }
84 
85  template<class View>
86  forceinline int
88  return x.lubMin();
89  }
90 
91  template<class View>
92  forceinline int
94  return x.lubMax();
95  }
96 
97  template<class View>
98  forceinline int
100  return x.glbMin();
101  }
102 
103  template<class View>
104  forceinline int
106  return x.glbMax();
107  }
108 
109  template<class View>
111  CachedView<View>::cardMin(Space& home, unsigned int m) {
112  return x.cardMin(home,m);
113  }
114 
115  template<class View>
117  CachedView<View>::cardMax(Space& home, unsigned int m) {
118  return x.cardMax(home,m);
119  }
120 
121  template<class View>
124  return x.include(home,i);
125  }
126 
127  template<class View>
130  return x.exclude(home,i);
131  }
132 
133  template<class View>
136  return x.intersect(home,i);
137  }
138 
139  template<class View>
141  CachedView<View>::intersect(Space& home, int i, int j) {
142  return x.intersect(home,i,j);
143  }
144 
145  template<class View>
147  CachedView<View>::include(Space& home, int i, int j) {
148  return x.include(home,i,j);
149  }
150 
151  template<class View>
153  CachedView<View>::exclude(Space& home, int i, int j) {
154  return x.exclude(home,i,j);
155  }
156 
157  template<class View>
158  template<class I> ModEvent
160  return x.excludeI(home,iter);
161  }
162 
163  template<class View>
164  template<class I> ModEvent
166  return x.includeI(home,iter);
167  }
168 
169  template<class View>
170  template<class I> ModEvent
172  return x.intersectI(home,iter);
173  }
174 
175  template<class View>
176  forceinline void
178  bool schedule) {
179  x.subscribe(home,p,pc,schedule);
180  }
181 
182  template<class View>
183  forceinline void
185  x.cancel(home,p,pc);
186  }
187 
188  template<class View>
189  forceinline void
191  x.subscribe(home,a);
192  }
193 
194  template<class View>
195  forceinline void
197  x.cancel(home,a);
198  }
199 
200  template<class View>
201  forceinline void
203  return View::schedule(home,p,me);
204  }
205  template<class View>
208  return View::me(med);
209  }
210 
211  template<class View>
214  return View::med(me);
215  }
216 
217  /*
218  * Delta information for advisors
219  *
220  */
221 
222  template<class View>
225  return View::modevent(d);
226  }
227 
228  template<class View>
229  forceinline int
231  return x.glbMin(d);
232  }
233 
234  template<class View>
235  forceinline int
237  return x.glbMax(d);
238  }
239 
240  template<class View>
241  forceinline bool
243  return x.glbAny(d);
244  }
245 
246  template<class View>
247  forceinline int
249  return x.lubMin(d);
250  }
251 
252  template<class View>
253  forceinline int
255  return x.lubMax(d);
256  }
257 
258  template<class View>
259  forceinline bool
261  return x.lubAny(d);
262  }
263 
264  template<class View>
265  forceinline void
267  lubCache.update(home,y.lubCache);
268  glbCache.update(home,y.glbCache);
270  }
271 
272  /*
273  * Cache operations
274  *
275  */
276  template<class View>
277  void
279  const IntSet& glb, const IntSet& lub) {
280  glbCache.init(home);
281  IntSetRanges gr(glb);
282  glbCache.includeI(home,gr);
283  lubCache.init(home);
284  IntSetRanges lr(lub);
285  lubCache.intersectI(home,lr);
286  }
287 
288  template<class View>
289  forceinline void
292  glbCache.includeI(home,gr);
293  }
294 
295  template<class View>
296  forceinline void
299  lubCache.intersectI(home,lr);
300  }
301 
302  template<class View>
303  forceinline bool
305  return glbCache.size() != glbSize();
306  }
307 
308  template<class View>
309  forceinline bool
311  return lubCache.size() != lubSize();
312  }
313 
318  template<class View>
319  class LubRanges<CachedView<View> > : public LubRanges<View> {
320  public:
322 
323  LubRanges(void) {}
326  LubRanges(const CachedView<View>& x);
328  void init(const CachedView<View>& x);
330  };
331 
332  template<class View>
335  : LubRanges<View>(s.base()) {}
336 
337  template<class View>
338  forceinline void
341  }
342 
347  template<class View>
348  class GlbRanges<CachedView<View> > : public GlbRanges<View> {
349  public:
351 
352  GlbRanges(void) {}
355  GlbRanges(const CachedView<View> & x);
357  void init(const CachedView<View> & x);
359  };
360 
361  template<class View>
364  : GlbRanges<View>(s.base()) {}
365 
366  template<class View>
367  forceinline void
370  }
371 
372  template<class Char, class Traits, class View>
373  std::basic_ostream<Char,Traits>&
374  operator <<(std::basic_ostream<Char,Traits>& os,
375  const CachedView<View>& x) {
376  return os << x.base();
377  }
378 
379  template<class View>
380  forceinline bool
382  return x.base() == y.base();
383  }
384 
385  template<class View>
386  forceinline bool
388  return x.base() != y.base();
389  }
390 
391  template<class View>
394  : gr(x.base()), cr(x.glbCache) {
396  }
397 
398  template<class View>
401  : cr(x.lubCache), lr(x.base()) {
403  }
404 
405 }}
406 
407 // STATISTICS: set-var
GlbDiffRanges(const CachedView< View > &x)
Constructor.
Definition: cached.hpp:393
LubRanges< View > lr
Upper bound iterator.
Definition: view.hpp:1160
Post propagator for SetVar x
Definition: set.hh:767
Post propagator for SetVar SetOpType SetVar y
Definition: set.hh:767
ModEvent exclude(Space &home, View &x, int s)
Prune view x to exclude all values from s.
Definition: set-op.hpp:137
int lubMax(void) const
Return maximum element of least upper bound.
Definition: set.hpp:87
void update(Space &home, DerivedView< View > &y)
Update this view to be a clone of view y.
Definition: view.hpp:681
unsigned int size(void) const
Return size (cardinality) of domain.
Definition: cached.hpp:93
LubRanges(void)
Default constructor.
unsigned int cardMin(void) const
Return cardinality minimum.
Definition: set.hpp:78
int lubMin(void) const
Return minimum element of least upper bound.
Definition: set.hpp:84
Computation spaces.
Definition: core.hpp:1742
BndSetRanges cr
Cached upper bound.
Definition: view.hpp:1158
void init(const T &x)
Initialize with least upper bound ranges for set variable x.
Range iterator for integer sets.
Definition: int.hh:292
BndSetRanges cr
Cached lower bound.
Definition: view.hpp:1143
bool operator!=(const CachedView< View > &x, const CachedView< View > &y)
Definition: cached.hpp:387
Base-class for derived views.
Definition: view.hpp:230
Gecode toplevel namespace
Base-class for propagators.
Definition: core.hpp:1064
Integer sets.
Definition: int.hh:174
unsigned int lubSize(void) const
Return number of elements in the least upper bound.
Definition: set.hpp:66
struct Gecode::@602::NNF::@65::@67 a
For atomic nodes.
GlbRanges(void)
Default constructor.
CachedView(void)
Default constructor.
Definition: cached.hpp:46
Generic domain change information to be supplied to advisors.
Definition: core.hpp:204
void init(GlbRanges< View > &i, BndSetRanges &j)
Initialize with iterator i and j.
GlbRanges< View > gr
Lower bound iterator.
Definition: view.hpp:1141
int med(void) const
Return median of domain (greatest element not greater than the median)
Definition: cached.hpp:70
Range iterator for computing set difference.
Definition: ranges-diff.hpp:43
std::basic_ostream< Char, Traits > & operator<<(std::basic_ostream< Char, Traits > &os, const CachedView< View > &x)
Definition: cached.hpp:374
static void schedule(Space &home, Propagator &p, ModEvent me)
Schedule propagator p with modification event me.
Definition: view.hpp:634
unsigned int cardMax(void) const
Return cardinality maximum.
Definition: set.hpp:81
unsigned int unknownSize(void) const
Return number of unknown elements (elements in lub but not in glb)
Definition: set.hpp:69
const double base
Base for geometric restart sequence.
Definition: search.hh:126
int ModEvent
Type for modification events.
Definition: core.hpp:62
bool contains(int i) const
Test whether i is in greatest lower bound.
Definition: set.hpp:72
void subscribe(Space &home, Propagator &p, PropCond pc, bool schedule=true)
Subscribe propagator p with propagation condition pc to view.
Definition: view.hpp:650
static ModEvent me(const ModEventDelta &med)
Return modification event for view type in med.
Definition: view.hpp:639
int PropCond
Type for propagation conditions.
Definition: core.hpp:72
bool operator==(const CachedView< View > &x, const CachedView< View > &y)
Definition: cached.hpp:381
View base(void) const
Return view from which this view is derived.
Definition: view.hpp:605
Gecode::IntSet d(v, 7)
Base-class for advisors.
Definition: core.hpp:1292
unsigned int glbSize(void) const
Return number of elements in the greatest lower bound.
Definition: set.hpp:63
LubDiffRanges(const CachedView< View > &x)
Constructor.
Definition: cached.hpp:400
int glbMin(void) const
Return minimum element of greatest lower bound.
Definition: set.hpp:90
void initCache(Space &home, const IntSet &s)
Initialize cache to set s.
Definition: cached.hpp:307
Cached integer view.
Definition: view.hpp:1166
Range iterator for integer sets.
Definition: var-imp.hpp:185
#define forceinline
Definition: config.hpp:185
int glbMax(void) const
Return maximum of greatest lower bound.
Definition: set.hpp:93
ModEvent include(Space &home, View &x, int s)
Prune view x to only include values from s.
Definition: set-op.hpp:123
void init(const T &x)
Initialize with greatest lower bound ranges for set variable x.
void update(Space &home, CachedView< View > &y)
Update this view to be a clone of view y.
Definition: cached.hpp:281
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:234
void cancel(Space &home, Propagator &p, PropCond pc)
Cancel subscription of propagator p with propagation condition pc to view.
Definition: view.hpp:656
int ModEventDelta
Modification event deltas.
Definition: core.hpp:89
Gecode::IntArgs i({1, 2, 3, 4})
static ModEvent modevent(const Delta &d)
Return modification event.
Definition: view.hpp:676
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:232
bool notContains(int i) const
Test whether i is not in the least upper bound.
Definition: set.hpp:75
FloatVal intersect(const FloatVal &x, const FloatVal &y)
Definition: val.hpp:503