this repo has no description
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2/*
3 * Main authors:
4 * Guido Tack <tack@gecode.org>
5 *
6 * Contributing authors:
7 * Samuel Gagnon <samuel.gagnon92@gmail.com>
8 *
9 * Copyright:
10 * Guido Tack, 2011
11 * Samuel Gagnon, 2018
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
38namespace Gecode { namespace Int {
39
40 /*
41 * Constructors and initialization
42 *
43 */
44 template<class View>
45 forceinline
46 CachedView<View>::CachedView(void) : _size(0) {}
47 template<class View>
48 forceinline
49 CachedView<View>::CachedView(const View& y)
50 : DerivedView<View>(y), _firstRange(nullptr), _lastRange(nullptr),
51 _size(0) {}
52
53
54 /*
55 * Value access
56 *
57 */
58 template<class View>
59 forceinline int
60 CachedView<View>::min(void) const {
61 return x.min();
62 }
63 template<class View>
64 forceinline int
65 CachedView<View>::max(void) const {
66 return x.max();
67 }
68 template<class View>
69 forceinline int
70 CachedView<View>::med(void) const {
71 return x.med();
72 }
73 template<class View>
74 forceinline int
75 CachedView<View>::val(void) const {
76 return x.val();
77 }
78#ifdef GECODE_HAS_CBS
79 template<class View>
80 forceinline int
81 CachedView<View>::baseval(int val) const {
82 return val;
83 }
84#endif
85
86 template<class View>
87 forceinline unsigned int
88 CachedView<View>::width(void) const {
89 return x.width();
90 }
91 template<class View>
92 forceinline unsigned int
93 CachedView<View>::size(void) const {
94 return x.size();
95 }
96 template<class View>
97 forceinline unsigned int
98 CachedView<View>::regret_min(void) const {
99 return x.regret_min();
100 }
101 template<class View>
102 forceinline unsigned int
103 CachedView<View>::regret_max(void) const {
104 return x.regret_max();
105 }
106
107 /*
108 * Domain tests
109 *
110 */
111 template<class View>
112 forceinline bool
113 CachedView<View>::range(void) const {
114 return x.range();
115 }
116 template<class View>
117 forceinline bool
118 CachedView<View>::in(int n) const {
119 return x.in(n);
120 }
121 template<class View>
122 forceinline bool
123 CachedView<View>::in(long long int n) const {
124 return x.in(n);
125 }
126
127
128 /*
129 * Domain update by value
130 *
131 */
132 template<class View>
133 forceinline ModEvent
134 CachedView<View>::lq(Space& home, int n) {
135 return x.lq(home,n);
136 }
137 template<class View>
138 forceinline ModEvent
139 CachedView<View>::lq(Space& home, long long int n) {
140 return x.lq(home,n);
141 }
142 template<class View>
143 forceinline ModEvent
144 CachedView<View>::le(Space& home, int n) {
145 return x.le(home,n);
146 }
147 template<class View>
148 forceinline ModEvent
149 CachedView<View>::le(Space& home, long long int n) {
150 return x.le(home,n);
151 }
152 template<class View>
153 forceinline ModEvent
154 CachedView<View>::gq(Space& home, int n) {
155 return x.gq(home,n);
156 }
157 template<class View>
158 forceinline ModEvent
159 CachedView<View>::gq(Space& home, long long int n) {
160 return x.gq(home,n);
161 }
162 template<class View>
163 forceinline ModEvent
164 CachedView<View>::gr(Space& home, int n) {
165 return x.gr(home,n);
166 }
167 template<class View>
168 forceinline ModEvent
169 CachedView<View>::gr(Space& home, long long int n) {
170 return x.gr(home,n);
171 }
172 template<class View>
173 forceinline ModEvent
174 CachedView<View>::nq(Space& home, int n) {
175 return x.nq(home,n);
176 }
177 template<class View>
178 forceinline ModEvent
179 CachedView<View>::nq(Space& home, long long int n) {
180 return x.nq(home,n);
181 }
182 template<class View>
183 forceinline ModEvent
184 CachedView<View>::eq(Space& home, int n) {
185 return x.eq(home,n);
186 }
187 template<class View>
188 forceinline ModEvent
189 CachedView<View>::eq(Space& home, long long int n) {
190 return x.eq(home,n);
191 }
192
193
194 /*
195 * Iterator-based domain update
196 *
197 */
198 template<class View>
199 template<class I>
200 forceinline ModEvent
201 CachedView<View>::narrow_r(Space& home, I& i, bool depend) {
202 return x.narrow_r(home,i,depend);
203 }
204 template<class View>
205 template<class I>
206 forceinline ModEvent
207 CachedView<View>::inter_r(Space& home, I& i, bool depend) {
208 return x.inter_r(home,i,depend);
209 }
210 template<class View>
211 template<class I>
212 forceinline ModEvent
213 CachedView<View>::minus_r(Space& home, I& i, bool depend) {
214 return x.minus_r(home,i,depend);
215 }
216 template<class View>
217 template<class I>
218 forceinline ModEvent
219 CachedView<View>::narrow_v(Space& home, I& i, bool depend) {
220 return x.narrow_v(home,i,depend);
221 }
222 template<class View>
223 template<class I>
224 forceinline ModEvent
225 CachedView<View>::inter_v(Space& home, I& i, bool depend) {
226 return x.inter_v(home,i,depend);
227 }
228 template<class View>
229 template<class I>
230 forceinline ModEvent
231 CachedView<View>::minus_v(Space& home, I& i, bool depend) {
232 return x.minus_v(home,i,depend);
233 }
234
235
236
237 /*
238 * Propagator modification events
239 *
240 */
241 template<class View>
242 forceinline ModEventDelta
243 CachedView<View>::med(ModEvent me) {
244 return View::med(me);
245 }
246
247
248 /*
249 * Delta information for advisors
250 *
251 */
252 template<class View>
253 forceinline int
254 CachedView<View>::min(const Delta& d) const {
255 return x.min(d);
256 }
257 template<class View>
258 forceinline int
259 CachedView<View>::max(const Delta& d) const {
260 return x.max(d);
261 }
262 template<class View>
263 forceinline unsigned int
264 CachedView<View>::width(const Delta& d) const {
265 return x.width(d);
266 }
267 template<class View>
268 forceinline bool
269 CachedView<View>::any(const Delta& d) const {
270 return x.any(d);
271 }
272
273
274
275 /*
276 * Cloning
277 *
278 */
279 template<class View>
280 void
281 CachedView<View>::update(Space& home, CachedView<View>& y) {
282 DerivedView<View>::update(home,y);
283 if (y._firstRange) {
284 _firstRange = new (home) RangeList(y._firstRange->min(),
285 y._firstRange->max(),nullptr);
286 RangeList* cur = _firstRange;
287
288 for (RangeList* y_cur = y._firstRange->next(); y_cur != nullptr;
289 y_cur = y_cur->next()) {
290 RangeList* next =
291 new (home) RangeList(y_cur->min(),y_cur->max(),nullptr);
292 cur->next(next);
293 cur = next;
294 }
295 _lastRange = cur;
296 _size = y._size;
297 }
298 }
299
300
301 /*
302 * Cache operations
303 *
304 */
305 template<class View>
306 void
307 CachedView<View>::initCache(Space& home, const IntSet& s) {
308 _firstRange = nullptr;
309 for (int i=s.ranges(); i--;) {
310 _firstRange = new (home) RangeList(s.min(i),s.max(i),_firstRange);
311 if (i==s.ranges()-1)
312 _lastRange = _firstRange;
313 }
314 _size = s.size();
315 }
316
317 template<class View>
318 void
319 CachedView<View>::cache(Space& home) {
320 _firstRange->dispose(home,_lastRange);
321 ViewRanges<View> xr(x);
322 _firstRange = new (home) RangeList(xr.min(),xr.max(),nullptr);
323 ++xr;
324 RangeList* cur = _firstRange;
325 for (; xr(); ++xr) {
326 RangeList* next = new (home) RangeList(xr.min(),xr.max(),nullptr);
327 cur->next(next);
328 cur = next;
329 }
330 _lastRange = cur;
331 _size = x.size();
332 }
333
334 template<class View>
335 forceinline bool
336 CachedView<View>::modified(void) const {
337 return x.size() != _size;
338 }
339
340
341 /**
342 * \brief %Range iterator for offset integer views
343 * \ingroup TaskActorIntView
344 */
345 template<class View>
346 class ViewRanges<CachedView<View> >
347 : public ViewRanges<View> {
348 public:
349 /// \name Constructors and initialization
350 //@{
351 /// Default constructor
352 ViewRanges(void);
353 /// Initialize with ranges for view \a x
354 ViewRanges(const CachedView<View>& x);
355 /// Initialize with ranges for view \a x
356 void init(const CachedView<View>& x);
357 //@}
358 };
359
360 template<class View>
361 forceinline
362 ViewRanges<CachedView<View> >::ViewRanges(void) {}
363
364 template<class View>
365 forceinline
366 ViewRanges<CachedView<View> >::ViewRanges(const CachedView<View>& x) {
367 ViewRanges<IntView>::init(x.base());
368 }
369
370 template<class View>
371 forceinline void
372 ViewRanges<CachedView<View> >::init(const CachedView<View>& x) {
373 ViewRanges<View>::init(x.base());
374 }
375
376 template<class View>
377 forceinline
378 ViewDiffRanges<View>::ViewDiffRanges(void) {}
379
380 template<class View>
381 forceinline
382 ViewDiffRanges<View>::ViewDiffRanges(const CachedView<View>& x)
383 : cr(x._firstRange), dr(x.base()) {
384 Super::init(cr,dr);
385 }
386
387 template<class View>
388 forceinline void
389 ViewDiffRanges<View>::init(const CachedView<View>& x) {
390 cr.init(x._firstRange);
391 dr.init(x.base());
392 Super::init(cr,dr);
393 }
394
395 /*
396 * View comparison
397 *
398 */
399 template<class View>
400 forceinline bool
401 operator ==(const CachedView<View>& x, const CachedView<View>& y) {
402 return (x.base() == y.base()) && (x.offset() == y.offset());
403 }
404 template<class View>
405 forceinline bool
406 operator !=(const CachedView<View>& x, const CachedView<View>& y) {
407 return !(x == y);
408 }
409
410}}
411
412// STATISTICS: int-var
413