main page
modules
namespaces
classes
files
Gecode home
Generated on Tue Jan 28 2020 00:00:00 for Gecode by
doxygen
1.8.17
gecode
int
view
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: 2016-04-19 17:19:45 +0200 (Tue, 19 Apr 2016) $ by $Author: schulte $
11
* $Revision: 14967 $
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
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(NULL), _lastRange(NULL),
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
79
template
<
class
View>
80
forceinline
unsigned
int
81
CachedView<View>::width
(
void
)
const
{
82
return
x
.width();
83
}
84
template
<
class
View>
85
forceinline
unsigned
int
86
CachedView<View>::size
(
void
)
const
{
87
return
x
.size();
88
}
89
template
<
class
View>
90
forceinline
unsigned
int
91
CachedView<View>::regret_min
(
void
)
const
{
92
return
x
.regret_min();
93
}
94
template
<
class
View>
95
forceinline
unsigned
int
96
CachedView<View>::regret_max
(
void
)
const
{
97
return
x
.regret_max();
98
}
99
100
/*
101
* Domain tests
102
*
103
*/
104
template
<
class
View>
105
forceinline
bool
106
CachedView<View>::range
(
void
)
const
{
107
return
x
.range();
108
}
109
template
<
class
View>
110
forceinline
bool
111
CachedView<View>::in
(
int
n
)
const
{
112
return
x
.in(
n
);
113
}
114
template
<
class
View>
115
forceinline
bool
116
CachedView<View>::in
(
long
long
int
n
)
const
{
117
return
x
.in(
n
);
118
}
119
120
121
/*
122
* Domain update by value
123
*
124
*/
125
template
<
class
View>
126
forceinline
ModEvent
127
CachedView<View>::lq
(
Space
& home,
int
n
) {
128
return
x
.lq(home,
n
);
129
}
130
template
<
class
View>
131
forceinline
ModEvent
132
CachedView<View>::lq
(
Space
& home,
long
long
int
n
) {
133
return
x
.lq(home,
n
);
134
}
135
template
<
class
View>
136
forceinline
ModEvent
137
CachedView<View>::le
(
Space
& home,
int
n
) {
138
return
x
.le(home,
n
);
139
}
140
template
<
class
View>
141
forceinline
ModEvent
142
CachedView<View>::le
(
Space
& home,
long
long
int
n
) {
143
return
x
.le(home,
n
);
144
}
145
template
<
class
View>
146
forceinline
ModEvent
147
CachedView<View>::gq
(
Space
& home,
int
n
) {
148
return
x
.gq(home,
n
);
149
}
150
template
<
class
View>
151
forceinline
ModEvent
152
CachedView<View>::gq
(
Space
& home,
long
long
int
n
) {
153
return
x
.gq(home,
n
);
154
}
155
template
<
class
View>
156
forceinline
ModEvent
157
CachedView<View>::gr
(
Space
& home,
int
n
) {
158
return
x
.gr(home,
n
);
159
}
160
template
<
class
View>
161
forceinline
ModEvent
162
CachedView<View>::gr
(
Space
& home,
long
long
int
n
) {
163
return
x
.gr(home,
n
);
164
}
165
template
<
class
View>
166
forceinline
ModEvent
167
CachedView<View>::nq
(
Space
& home,
int
n
) {
168
return
x
.nq(home,
n
);
169
}
170
template
<
class
View>
171
forceinline
ModEvent
172
CachedView<View>::nq
(
Space
& home,
long
long
int
n
) {
173
return
x
.nq(home,
n
);
174
}
175
template
<
class
View>
176
forceinline
ModEvent
177
CachedView<View>::eq
(
Space
& home,
int
n
) {
178
return
x
.eq(home,
n
);
179
}
180
template
<
class
View>
181
forceinline
ModEvent
182
CachedView<View>::eq
(
Space
& home,
long
long
int
n
) {
183
return
x
.eq(home,
n
);
184
}
185
186
187
/*
188
* Iterator-based domain update
189
*
190
*/
191
template
<
class
View>
192
template
<
class
I>
193
forceinline
ModEvent
194
CachedView<View>::narrow_r
(
Space
& home, I&
i
,
bool
depend) {
195
return
x
.narrow_r(home,
i
,depend);
196
}
197
template
<
class
View>
198
template
<
class
I>
199
forceinline
ModEvent
200
CachedView<View>::inter_r
(
Space
& home, I&
i
,
bool
depend) {
201
return
x
.inter_r(home,
i
,depend);
202
}
203
template
<
class
View>
204
template
<
class
I>
205
forceinline
ModEvent
206
CachedView<View>::minus_r
(
Space
& home, I&
i
,
bool
depend) {
207
return
x
.minus_r(home,
i
,depend);
208
}
209
template
<
class
View>
210
template
<
class
I>
211
forceinline
ModEvent
212
CachedView<View>::narrow_v
(
Space
& home, I&
i
,
bool
depend) {
213
return
x
.narrow_v(home,
i
,depend);
214
}
215
template
<
class
View>
216
template
<
class
I>
217
forceinline
ModEvent
218
CachedView<View>::inter_v
(
Space
& home, I&
i
,
bool
depend) {
219
return
x
.inter_v(home,
i
,depend);
220
}
221
template
<
class
View>
222
template
<
class
I>
223
forceinline
ModEvent
224
CachedView<View>::minus_v
(
Space
& home, I&
i
,
bool
depend) {
225
return
x
.minus_v(home,
i
,depend);
226
}
227
228
229
230
/*
231
* Propagator modification events
232
*
233
*/
234
template
<
class
View>
235
forceinline
ModEventDelta
236
CachedView<View>::med
(
ModEvent
me) {
237
return
View::med(me);
238
}
239
240
241
/*
242
* Delta information for advisors
243
*
244
*/
245
template
<
class
View>
246
forceinline
int
247
CachedView<View>::min
(
const
Delta
&
d
)
const
{
248
return
x
.min(
d
);
249
}
250
template
<
class
View>
251
forceinline
int
252
CachedView<View>::max
(
const
Delta
&
d
)
const
{
253
return
x
.max(
d
);
254
}
255
template
<
class
View>
256
forceinline
bool
257
CachedView<View>::any
(
const
Delta
&
d
)
const
{
258
return
x
.any(
d
);
259
}
260
261
262
263
/*
264
* Cloning
265
*
266
*/
267
template
<
class
View>
268
void
269
CachedView<View>::update
(
Space
& home,
bool
share,
CachedView<View>
&
y
) {
270
DerivedView<View>::update
(home,share,
y
);
271
if
(
y
._firstRange) {
272
_firstRange =
new
(home)
RangeList
(
y
._firstRange->min(),
273
y
._firstRange->max(),NULL);
274
RangeList
* cur = _firstRange;
275
276
for
(
RangeList
* y_cur =
y
._firstRange->next(); y_cur != NULL;
277
y_cur = y_cur->next()) {
278
RangeList
* next =
279
new
(home)
RangeList
(y_cur->min(),y_cur->max(),NULL);
280
cur->
next
(next);
281
cur = next;
282
}
283
_lastRange = cur;
284
_size =
y
._size;
285
}
286
}
287
288
/*
289
* Cache operations
290
*
291
*/
292
293
template
<
class
View>
294
void
295
CachedView<View>::initCache
(
Space
& home,
const
IntSet
& s) {
296
_firstRange = NULL;
297
for
(
int
i
=s.
ranges
();
i
--;) {
298
_firstRange =
new
(home)
RangeList
(s.
min
(
i
),s.
max
(
i
),_firstRange);
299
if
(
i
==s.
ranges
()-1)
300
_lastRange = _firstRange;
301
}
302
_size = s.
size
();
303
}
304
305
template
<
class
View>
306
void
307
CachedView<View>::cache
(
Space
& home) {
308
_firstRange->dispose(home,_lastRange);
309
ViewRanges<View>
xr(
x
);
310
_firstRange =
new
(home)
RangeList
(xr.
min
(),xr.
max
(),NULL);
311
++xr;
312
RangeList
* cur = _firstRange;
313
for
(; xr(); ++xr) {
314
RangeList
* next =
new
(home)
RangeList
(xr.
min
(),xr.
max
(),NULL);
315
cur->
next
(next);
316
cur = next;
317
}
318
_lastRange = cur;
319
_size =
x
.size();
320
}
321
322
template
<
class
View>
323
forceinline
bool
324
CachedView<View>::modified
(
void
)
const
{
325
return
x
.size() != _size;
326
}
327
328
333
template
<
class
View>
334
class
ViewRanges
<
CachedView
<View> >
335
:
public
ViewRanges
<View> {
336
public
:
338
339
ViewRanges
(
void
);
342
ViewRanges
(
const
CachedView<View>
&
x
);
344
void
init(
const
CachedView<View>
&
x
);
346
};
347
348
template
<
class
View>
349
forceinline
350
ViewRanges<CachedView<View>
>
::ViewRanges
(
void
) {}
351
352
template
<
class
View>
353
forceinline
354
ViewRanges<CachedView<View>
>
::ViewRanges
(
const
CachedView<View>
&
x
) {
355
ViewRanges<IntView>::init
(
x
.base());
356
}
357
358
template
<
class
View>
359
forceinline
void
360
ViewRanges<CachedView<View>
>::init(
const
CachedView<View>
&
x
) {
361
ViewRanges<View>::init
(
x
.base());
362
}
363
364
template
<
class
View>
365
forceinline
366
ViewDiffRanges<View>::ViewDiffRanges
(
void
) {}
367
368
template
<
class
View>
369
forceinline
370
ViewDiffRanges<View>::ViewDiffRanges
(
const
CachedView<View>
&
x
)
371
: cr(
x
._firstRange), dr(
x
.
base
()) {
372
Super::init
(
cr
,
dr
);
373
}
374
375
template
<
class
View>
376
forceinline
void
377
ViewDiffRanges<View>::init
(
const
CachedView<View>
&
x
) {
378
cr.init(
x
._firstRange);
379
dr.init(
x
.base());
380
Super::init(cr,dr);
381
}
382
383
/*
384
* View comparison
385
*
386
*/
387
template
<
class
View>
388
forceinline
bool
389
same
(
const
CachedView<View>
&
x
,
const
CachedView<View>
&
y
) {
390
return
same
(
x
.base(),
y
.base()) && (
x
.offset() ==
y
.offset());
391
}
392
template
<
class
View>
393
forceinline
bool
394
before
(
const
CachedView<View>
&
x
,
const
CachedView<View>
&
y
) {
395
return
before
(
x
.base(),
y
.base())
396
|| (
same
(
x
.base(),
y
.base()) && (
x
.offset() <
y
.offset()));
397
}
398
399
}}
400
401
// STATISTICS: int-var
402
Gecode::x
Post propagator for SetVar x
Definition:
set.hh:784
Gecode::y
Post propagator for SetVar SetOpType SetVar y
Definition:
set.hh:784
Gecode::IntSet::min
int min(int i) const
Return minimum of range at position i.
Definition:
int-set-1.hpp:115
forceinline
#define forceinline
Definition:
config.hpp:173
Gecode::IntSet::max
int max(int i) const
Return maximum of range at position i.
Definition:
int-set-1.hpp:121
Gecode::Int::ViewRanges::min
int min(void) const
Return smallest value of range.
Gecode::Iter::Ranges::size
unsigned int size(I &i)
Size of all ranges of range iterator i.
Definition:
ranges-operations.hpp:78
Test::Int::Basic::i
Gecode::IntArgs i(4, 1, 2, 3, 4)
Gecode::Int::same
bool same(const CachedView< View > &x, const CachedView< View > &y)
Definition:
cached.hpp:389
Gecode::Float::Limits::min
const FloatNum min
Smallest allowed float value.
Definition:
float.hh:850
Gecode::range
void range(Home home, const IntVarArgs &x, SetVar y, SetVar z)
Post constraint .
Definition:
minimodel.hh:1901
Gecode::Space
Computation spaces.
Definition:
core.hpp:1748
Gecode::Int::ViewDiffRanges::init
void init(const CachedView< View > &x)
Initialize with ranges for view x.
Definition:
cached.hpp:377
Gecode::Int::ViewDiffRanges::dr
ViewRanges< View > dr
Current domain iterator.
Definition:
view.hpp:1296
Gecode::IntSet::size
unsigned int size(void) const
Return size (cardinality) of set.
Definition:
int-set-1.hpp:161
Gecode::DerivedView
Base-class for derived views.
Definition:
view.hpp:222
Gecode
Gecode toplevel namespace
Gecode::Int::ViewRanges
Range iterator for integer views.
Definition:
view.hpp:54
Gecode::IntSet
Integer sets.
Definition:
int.hh:174
Gecode::Int::before
bool before(const CachedView< View > &x, const CachedView< View > &y)
Definition:
cached.hpp:394
x
Node * x
Pointer to corresponding Boolean expression node.
Definition:
bool-expr.cpp:253
Gecode::Int::CachedView::CachedView
CachedView(void)
Default constructor.
Definition:
cached.hpp:46
Gecode::Delta
Generic domain change information to be supplied to advisors.
Definition:
core.hpp:281
Gecode::Int::ViewDiffRanges::cr
Iter::Ranges::RangeList cr
Cached domain iterator.
Definition:
view.hpp:1294
Gecode::Iter::Ranges::Diff::init
void init(I &i, J &j)
Initialize with iterator i and j.
Definition:
ranges-diff.hpp:129
Gecode::Search::Config::base
const double base
Base for geometric restart sequence.
Definition:
search.hh:122
Gecode::ModEvent
int ModEvent
Type for modification events.
Definition:
core.hpp:142
Gecode::Int::ViewDiffRanges
Range iterator for cached integer views
Definition:
view.hpp:1094
Gecode::Float::Arithmetic::any
bool any(const View &x)
Test whether x is neither positive nor negative.
Definition:
mult.hpp:57
Test::Int::Distinct::d
Gecode::IntSet d(v, 7)
Gecode::Int::CachedView
Cached integer view.
Definition:
view.hpp:1107
Gecode::Int::ViewRanges::max
int max(void) const
Return largest value of range.
Gecode::RangeList::next
RangeList * next(void) const
Return next element.
Definition:
range-list.hpp:145
n
int n
Number of negative literals for node type.
Definition:
bool-expr.cpp:238
Gecode::RangeList
Lists of ranges (intervals)
Definition:
range-list.hpp:53
Gecode::ModEventDelta
int ModEventDelta
Modification event deltas.
Definition:
core.hpp:169
Gecode::Float::Limits::max
const FloatNum max
Largest allowed float value.
Definition:
float.hh:848
Gecode::IntSet::ranges
int ranges(void) const
Return number of ranges of the specification.
Definition:
int-set-1.hpp:134