main page
modules
namespaces
classes
files
Gecode home
Generated on Sat Nov 9 2013 19:18:27 for Gecode by
doxygen
1.8.4
gecode
int
view
offset.hpp
Go to the documentation of this file.
1
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2
/*
3
* Main authors:
4
* Christian Schulte <schulte@gecode.org>
5
*
6
* Copyright:
7
* Christian Schulte, 2002
8
*
9
* Last modified:
10
* $Date: 2013-02-14 16:29:11 +0100 (Thu, 14 Feb 2013) $ by $Author: schulte $
11
* $Revision: 13292 $
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
forceinline
45
OffsetView::OffsetView
(
void
) {}
46
forceinline
47
OffsetView::OffsetView
(
const
IntView
& y,
int
d
)
48
:
DerivedView
<
IntView
>(y),
c
(d) {}
49
50
51
/*
52
* Value access
53
*
54
*/
55
forceinline
int
56
OffsetView::offset
(
void
)
const
{
57
return
c
;
58
}
59
forceinline
void
60
OffsetView::offset
(
int
n
) {
61
c
=
n
;
62
}
63
forceinline
int
64
OffsetView::min
(
void
)
const
{
65
return
x
.
min
()+
c
;
66
}
67
forceinline
int
68
OffsetView::max
(
void
)
const
{
69
return
x
.
max
()+
c
;
70
}
71
forceinline
int
72
OffsetView::med
(
void
)
const
{
73
return
x
.
med
()+
c
;
74
}
75
forceinline
int
76
OffsetView::val
(
void
)
const
{
77
return
x
.
val
()+
c
;
78
}
79
80
forceinline
unsigned
int
81
OffsetView::width
(
void
)
const
{
82
return
x
.
width
();
83
}
84
forceinline
unsigned
int
85
OffsetView::size
(
void
)
const
{
86
return
x
.
size
();
87
}
88
forceinline
unsigned
int
89
OffsetView::regret_min
(
void
)
const
{
90
return
x
.
regret_min
();
91
}
92
forceinline
unsigned
int
93
OffsetView::regret_max
(
void
)
const
{
94
return
x
.
regret_max
();
95
}
96
97
/*
98
* Domain tests
99
*
100
*/
101
forceinline
bool
102
OffsetView::range
(
void
)
const
{
103
return
x
.
range
();
104
}
105
forceinline
bool
106
OffsetView::in
(
int
n
)
const
{
107
return
x
.
in
(n-
c
);
108
}
109
forceinline
bool
110
OffsetView::in
(
long
long
int
n
)
const
{
111
return
x
.
in
(n-
c
);
112
}
113
114
115
116
/*
117
* Domain update by value
118
*
119
*/
120
forceinline
ModEvent
121
OffsetView::lq
(
Space
& home,
int
n
) {
122
return
x
.
lq
(home,n-
c
);
123
}
124
forceinline
ModEvent
125
OffsetView::lq
(
Space
& home,
long
long
int
n
) {
126
return
x
.
lq
(home,n-
c
);
127
}
128
129
forceinline
ModEvent
130
OffsetView::le
(
Space
& home,
int
n
) {
131
return
x
.
le
(home,n-
c
);
132
}
133
forceinline
ModEvent
134
OffsetView::le
(
Space
& home,
long
long
int
n
) {
135
return
x
.
le
(home,n-
c
);
136
}
137
138
forceinline
ModEvent
139
OffsetView::gq
(
Space
& home,
int
n
) {
140
return
x
.
gq
(home,n-
c
);
141
}
142
forceinline
ModEvent
143
OffsetView::gq
(
Space
& home,
long
long
int
n
) {
144
return
x
.
gq
(home,n-
c
);
145
}
146
147
forceinline
ModEvent
148
OffsetView::gr
(
Space
& home,
int
n
) {
149
return
x
.
gr
(home,n-
c
);
150
}
151
forceinline
ModEvent
152
OffsetView::gr
(
Space
& home,
long
long
int
n
) {
153
return
x
.
gr
(home,n-
c
);
154
}
155
156
forceinline
ModEvent
157
OffsetView::nq
(
Space
& home,
int
n
) {
158
return
x
.
nq
(home,n-
c
);
159
}
160
forceinline
ModEvent
161
OffsetView::nq
(
Space
& home,
long
long
int
n
) {
162
return
x
.
nq
(home,n-
c
);
163
}
164
165
forceinline
ModEvent
166
OffsetView::eq
(
Space
& home,
int
n
) {
167
return
x
.
eq
(home,n-
c
);
168
}
169
forceinline
ModEvent
170
OffsetView::eq
(
Space
& home,
long
long
int
n
) {
171
return
x
.
eq
(home,n-
c
);
172
}
173
174
175
/*
176
* Iterator-based domain update
177
*
178
*/
179
template
<
class
I>
180
forceinline
ModEvent
181
OffsetView::narrow_r
(
Space
& home, I&
i
,
bool
depend) {
182
Iter::Ranges::Offset<I>
oi(i,-
c
);
183
return
x
.
narrow_r
(home,oi,depend);
184
}
185
template
<
class
I>
186
forceinline
ModEvent
187
OffsetView::inter_r
(
Space
& home, I&
i
,
bool
depend) {
188
Iter::Ranges::Offset<I>
oi(i,-
c
);
189
return
x
.
inter_r
(home,oi,depend);
190
}
191
template
<
class
I>
192
forceinline
ModEvent
193
OffsetView::minus_r
(
Space
& home, I&
i
,
bool
depend) {
194
Iter::Ranges::Offset<I>
oi(i,-
c
);
195
return
x
.
minus_r
(home,oi,depend);
196
}
197
template
<
class
I>
198
forceinline
ModEvent
199
OffsetView::narrow_v
(
Space
& home, I&
i
,
bool
depend) {
200
Iter::Values::Offset<I>
oi(i,-
c
);
201
return
x
.
narrow_v
(home,oi,depend);
202
}
203
template
<
class
I>
204
forceinline
ModEvent
205
OffsetView::inter_v
(
Space
& home, I&
i
,
bool
depend) {
206
Iter::Values::Offset<I>
oi(i,-
c
);
207
return
x
.
inter_v
(home,oi,depend);
208
}
209
template
<
class
I>
210
forceinline
ModEvent
211
OffsetView::minus_v
(
Space
& home, I&
i
,
bool
depend) {
212
Iter::Values::Offset<I>
oi(i,-
c
);
213
return
x
.
minus_v
(home,oi,depend);
214
}
215
216
217
218
/*
219
* Propagator modification events
220
*
221
*/
222
forceinline
ModEventDelta
223
OffsetView::med
(
ModEvent
me) {
224
return
IntView::med
(me);
225
}
226
227
228
/*
229
* Delta information for advisors
230
*
231
*/
232
forceinline
int
233
OffsetView::min
(
const
Delta
&
d
)
const
{
234
return
x
.
min
(d)+
c
;
235
}
236
forceinline
int
237
OffsetView::max
(
const
Delta
&
d
)
const
{
238
return
x
.
max
(d)+
c
;
239
}
240
forceinline
bool
241
OffsetView::any
(
const
Delta
&
d
)
const
{
242
return
x
.
any
(d);
243
}
244
245
246
247
/*
248
* Cloning
249
*
250
*/
251
forceinline
void
252
OffsetView::update
(
Space
& home,
bool
share,
OffsetView
& y) {
253
DerivedView<IntView>::update
(home,share,y);
254
c
=y.
c
;
255
}
256
257
262
template
<>
263
class
ViewRanges
<
OffsetView
>
264
:
public
Iter::Ranges::Offset
<ViewRanges<IntView> > {
265
public
:
267
268
ViewRanges
(
void
);
271
ViewRanges
(
const
OffsetView
&
x
);
273
void
init
(
const
OffsetView
& x);
275
};
276
277
forceinline
278
ViewRanges<OffsetView>::ViewRanges
(
void
) {}
279
280
forceinline
281
ViewRanges<OffsetView>::ViewRanges
(
const
OffsetView
&
x
) {
282
ViewRanges<IntView>
xi(x.
base
());
283
Iter::Ranges::Offset<ViewRanges<IntView>
>
::init
(xi,x.
offset
());
284
}
285
286
forceinline
void
287
ViewRanges<OffsetView>::init
(
const
OffsetView
&
x
) {
288
ViewRanges<IntView>
xi(x.
base
());
289
Iter::Ranges::Offset<ViewRanges<IntView>
>
::init
(xi,x.
offset
());
290
}
291
292
/*
293
* View comparison
294
*
295
*/
296
forceinline
bool
297
same
(
const
OffsetView
&
x
,
const
OffsetView
& y) {
298
return
same
(x.
base
(),y.
base
()) && (x.
offset
() == y.
offset
());
299
}
300
forceinline
bool
301
before
(
const
OffsetView
&
x
,
const
OffsetView
& y) {
302
return
before
(x.
base
(),y.
base
())
303
|| (
same
(x.
base
(),y.
base
()) && (x.
offset
() < y.
offset
()));
304
}
305
306
}}
307
308
// STATISTICS: int-var
309