Generated on Thu Jan 16 2025 00:00:00 for Gecode by doxygen 1.14.0
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
36namespace Gecode { namespace Set {
37
38 template<class View>
41
42 template<class View>
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
324 LubRanges(void) {}
328 void init(const CachedView<View>& x);
330 };
331
332 template<class View>
336
337 template<class View>
338 forceinline void
342
347 template<class View>
348 class GlbRanges<CachedView<View> > : public GlbRanges<View> {
349 public:
351
352
353 GlbRanges(void) {}
357 void init(const CachedView<View> & x);
359 };
360
361 template<class View>
365
366 template<class View>
367 forceinline void
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>
397
398 template<class View>
404
405}}
406
407// STATISTICS: set-var
Base-class for advisors.
Definition core.hpp:1294
Generic domain change information to be supplied to advisors.
Definition core.hpp:204
View base(void) const
Return view from which this view is derived.
Definition view.hpp:605
View x
View from which this view is derived.
Definition view.hpp:238
void update(Space &home, DerivedView< View > &y)
Update this view to be a clone of view y.
Definition view.hpp:681
Range iterator for integer sets.
Definition int.hh:292
Integer sets.
Definition int.hh:174
Cached integer view.
Definition view.hpp:1166
Range iterator for computing set difference.
void init(GlbRanges< View > &i, BndSetRanges &j)
Base-class for propagators.
Definition core.hpp:1066
Range iterator for integer sets.
Definition var-imp.hpp:185
ModEvent intersect(Space &home, int i, int j)
Update least upper bound to contain at most all elements between and including i and j.
Definition cached.hpp:141
ModEvent exclude(Space &home, int i, int j)
Restrict least upper bound to not contain all elements between and including i and j.
Definition cached.hpp:153
ModEvent excludeI(Space &home, I &i)
Remove range sequence described by i from least upper bound.
int glbMax(void) const
Return maximum of the greatest lower bound.
Definition cached.hpp:105
ModEvent include(Space &home, int i, int j)
Update greatest lower bound to include all elements between and including i and j.
Definition cached.hpp:147
bool glbAny(const Delta &d) const
Test whether arbitrary values got pruned from glb.
Definition cached.hpp:242
bool glbModified(void) const
Check whether greatest lower bound cache differs from current domain.
Definition cached.hpp:304
bool lubAny(const Delta &d) const
Test whether arbitrary values got pruned from lub.
Definition cached.hpp:260
static void schedule(Space &home, Propagator &p, ModEvent me)
Schedule propagator p with modification event me.
Definition cached.hpp:202
GLBndSet glbCache
The cached greatest lower bound.
Definition view.hpp:957
void initCache(Space &home, const IntSet &glb, const IntSet &lub)
Initialize cache to bounds glb and lub.
Definition cached.hpp:278
unsigned int glbSize(void) const
Return the number of elements in the greatest lower bound.
Definition cached.hpp:49
LUBndSet lubCache
The cached least upper bound.
Definition view.hpp:955
int lubMin(void) const
Return minimum of the least upper bound.
Definition cached.hpp:87
unsigned int cardMax(void) const
Return maximum cardinality.
Definition cached.hpp:81
void cancel(Space &home, Propagator &p, PropCond pc)
Cancel subscription of propagator p with propagation condition pc to view.
Definition cached.hpp:184
static ModEvent modevent(const Delta &d)
Return modification event.
Definition cached.hpp:224
bool contains(int i) const
Test whether i is in the greatest lower bound.
Definition cached.hpp:67
unsigned int cardMin(void) const
Return minimum cardinality.
Definition cached.hpp:75
ModEvent includeI(Space &home, I &i)
Include range sequence described by i in greatest lower bound.
void cacheLub(Space &home)
Update least upper bound cache to current domain.
Definition cached.hpp:297
void cacheGlb(Space &home)
Update greatest lower bound cache to current domain.
Definition cached.hpp:290
static ModEventDelta med(ModEvent)
Translate modification event me to modification event delta for view.
bool lubModified(void) const
Check whether least upper bound cache differs from current domain.
Definition cached.hpp:310
unsigned int unknownSize(void) const
Return the number of unknown elements.
Definition cached.hpp:61
ModEvent intersectI(Space &home, I &iter)
Intersect least upper bound with range sequence described by i.
unsigned int lubSize(void) const
Return the number of elements in the least upper bound.
Definition cached.hpp:55
bool notContains(int i) const
Test whether i is not in the least upper bound.
Definition cached.hpp:71
static ModEvent me(const ModEventDelta &med)
Return modification event for view type in med.
Definition cached.hpp:207
int lubMax(void) const
Return maximum of the least upper bound.
Definition cached.hpp:93
void subscribe(Space &home, Propagator &p, PropCond pc, bool schedule=true)
Subscribe propagator p with propagation condition pc to view.
Definition cached.hpp:177
int glbMin(void) const
Return minimum of the greatest lower bound.
Definition cached.hpp:99
void update(Space &home, CachedView< View > &y)
Update this view to be a clone of view y.
CachedView(void)
Default constructor.
GlbRanges< View > gr
Lower bound iterator.
Definition view.hpp:1141
GlbDiffRanges(const CachedView< View > &x)
Constructor.
Definition cached.hpp:393
BndSetRanges cr
Cached lower bound.
Definition view.hpp:1143
void init(const CachedView< View > &x)
Initialize with ranges for view x.
Definition cached.hpp:368
GlbRanges(void)
Default constructor.
Definition cached.hpp:353
Range iterator for the greatest lower bound.
Definition var-imp.hpp:359
void init(const T &x)
Initialize with greatest lower bound ranges for set variable x.
GlbRanges(void)
Default constructor.
LubRanges< View > lr
Upper bound iterator.
Definition view.hpp:1160
BndSetRanges cr
Cached upper bound.
Definition view.hpp:1158
LubDiffRanges(const CachedView< View > &x)
Constructor.
Definition cached.hpp:400
LubRanges(void)
Default constructor.
Definition cached.hpp:324
void init(const CachedView< View > &x)
Initialize with ranges for view x.
Definition cached.hpp:339
Range iterator for the least upper bound.
Definition var-imp.hpp:317
void init(const T &x)
Initialize with least upper bound ranges for set variable x.
Computation spaces.
Definition core.hpp:1744
int ModEventDelta
Modification event deltas.
Definition core.hpp:89
std::basic_ostream< Char, Traits > & operator<<(std::basic_ostream< Char, Traits > &os, const IdxViewArray< View > &x)
Definition idx-view.hpp:167
bool operator==(const CachedView< View > &x, const CachedView< View > &y)
Definition cached.hpp:401
bool operator!=(const CachedView< View > &x, const CachedView< View > &y)
Definition cached.hpp:406
Finite integer sets.
Definition var-imp.hpp:137
Gecode toplevel namespace
Post propagator for SetVar SetOpType SetVar y
Definition set.hh:773
int PropCond
Type for propagation conditions.
Definition core.hpp:72
Post propagator for SetVar x
Definition set.hh:773
int ModEvent
Type for modification events.
Definition core.hpp:62
#define forceinline
Definition config.hpp:194