main page
modules
namespaces
classes
files
Gecode home
Generated on Sat Aug 25 2012 03:32:51 for Gecode by
doxygen
1.8.1.2
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: 2010-10-07 07:42:28 +1100 (Thu, 07 Oct 2010) $ by $Author: schulte $
11
* $Revision: 11464 $
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
(
double
n)
const
{
111
return
x
.
in
(n-
c
);
112
}
113
114
115
/*
116
* Domain update by value
117
*
118
*/
119
forceinline
ModEvent
120
OffsetView::lq
(
Space
& home,
int
n) {
121
return
x
.
lq
(home,n-
c
);
122
}
123
forceinline
ModEvent
124
OffsetView::lq
(
Space
& home,
double
n) {
125
return
x
.
lq
(home,n-
c
);
126
}
127
forceinline
ModEvent
128
OffsetView::le
(
Space
& home,
int
n) {
129
return
x
.
le
(home,n-
c
);
130
}
131
forceinline
ModEvent
132
OffsetView::le
(
Space
& home,
double
n) {
133
return
x
.
le
(home,n-
c
);
134
}
135
forceinline
ModEvent
136
OffsetView::gq
(
Space
& home,
int
n) {
137
return
x
.
gq
(home,n-
c
);
138
}
139
forceinline
ModEvent
140
OffsetView::gq
(
Space
& home,
double
n) {
141
return
x
.
gq
(home,n-
c
);
142
}
143
forceinline
ModEvent
144
OffsetView::gr
(
Space
& home,
int
n) {
145
return
x
.
gr
(home,n-
c
);
146
}
147
forceinline
ModEvent
148
OffsetView::gr
(
Space
& home,
double
n) {
149
return
x
.
gr
(home,n-
c
);
150
}
151
forceinline
ModEvent
152
OffsetView::nq
(
Space
& home,
int
n) {
153
return
x
.
nq
(home,n-
c
);
154
}
155
forceinline
ModEvent
156
OffsetView::nq
(
Space
& home,
double
n) {
157
return
x
.
nq
(home,n-
c
);
158
}
159
forceinline
ModEvent
160
OffsetView::eq
(
Space
& home,
int
n) {
161
return
x
.
eq
(home,n-
c
);
162
}
163
forceinline
ModEvent
164
OffsetView::eq
(
Space
& home,
double
n) {
165
return
x
.
eq
(home,n-
c
);
166
}
167
168
169
/*
170
* Iterator-based domain update
171
*
172
*/
173
template
<
class
I>
174
forceinline
ModEvent
175
OffsetView::narrow_r
(
Space
& home, I&
i
,
bool
depend) {
176
Iter::Ranges::Offset<I>
oi(i,-
c
);
177
return
x
.
narrow_r
(home,oi,depend);
178
}
179
template
<
class
I>
180
forceinline
ModEvent
181
OffsetView::inter_r
(
Space
& home, I&
i
,
bool
depend) {
182
Iter::Ranges::Offset<I>
oi(i,-
c
);
183
return
x
.
inter_r
(home,oi,depend);
184
}
185
template
<
class
I>
186
forceinline
ModEvent
187
OffsetView::minus_r
(
Space
& home, I&
i
,
bool
depend) {
188
Iter::Ranges::Offset<I>
oi(i,-
c
);
189
return
x
.
minus_r
(home,oi,depend);
190
}
191
template
<
class
I>
192
forceinline
ModEvent
193
OffsetView::narrow_v
(
Space
& home, I&
i
,
bool
depend) {
194
Iter::Values::Offset<I>
oi(i,-
c
);
195
return
x
.
narrow_v
(home,oi,depend);
196
}
197
template
<
class
I>
198
forceinline
ModEvent
199
OffsetView::inter_v
(
Space
& home, I&
i
,
bool
depend) {
200
Iter::Values::Offset<I>
oi(i,-
c
);
201
return
x
.
inter_v
(home,oi,depend);
202
}
203
template
<
class
I>
204
forceinline
ModEvent
205
OffsetView::minus_v
(
Space
& home, I&
i
,
bool
depend) {
206
Iter::Values::Offset<I>
oi(i,-
c
);
207
return
x
.
minus_v
(home,oi,depend);
208
}
209
210
211
212
/*
213
* Propagator modification events
214
*
215
*/
216
forceinline
ModEventDelta
217
OffsetView::med
(
ModEvent
me) {
218
return
IntView::med
(me);
219
}
220
221
222
/*
223
* Delta information for advisors
224
*
225
*/
226
forceinline
int
227
OffsetView::min
(
const
Delta
&
d
)
const
{
228
return
x
.
min
(d)+
c
;
229
}
230
forceinline
int
231
OffsetView::max
(
const
Delta
&
d
)
const
{
232
return
x
.
max
(d)+
c
;
233
}
234
forceinline
bool
235
OffsetView::any
(
const
Delta
&
d
)
const
{
236
return
x
.
any
(d);
237
}
238
239
240
241
/*
242
* Cloning
243
*
244
*/
245
forceinline
void
246
OffsetView::update
(
Space
& home,
bool
share,
OffsetView
& y) {
247
DerivedView<IntView>::update
(home,share,y);
248
c
=y.
c
;
249
}
250
251
256
template
<>
257
class
ViewRanges
<
OffsetView
>
258
:
public
Iter::Ranges::Offset
<ViewRanges<IntView> > {
259
public
:
261
262
263
ViewRanges
(
void
);
265
ViewRanges
(
const
OffsetView
& x);
267
void
init
(
const
OffsetView
& x);
269
};
270
271
forceinline
272
ViewRanges<OffsetView>::ViewRanges
(
void
) {}
273
274
forceinline
275
ViewRanges<OffsetView>::ViewRanges
(
const
OffsetView
& x) {
276
ViewRanges<IntView>
xi(x.
base
());
277
Iter::Ranges::Offset<ViewRanges<IntView>
>
::init
(xi,x.
offset
());
278
}
279
280
forceinline
void
281
ViewRanges<OffsetView>::init
(
const
OffsetView
& x) {
282
ViewRanges<IntView>
xi(x.
base
());
283
Iter::Ranges::Offset<ViewRanges<IntView>
>
::init
(xi,x.
offset
());
284
}
285
286
/*
287
* View comparison
288
*
289
*/
290
forceinline
bool
291
same
(
const
OffsetView
& x,
const
OffsetView
& y) {
292
return
same
(x.
base
(),y.
base
()) && (x.
offset
() == y.
offset
());
293
}
294
forceinline
bool
295
before
(
const
OffsetView
& x,
const
OffsetView
& y) {
296
return
before
(x.
base
(),y.
base
())
297
|| (
same
(x.
base
(),y.
base
()) && (x.
offset
() < y.
offset
()));
298
}
299
300
}}
301
302
// STATISTICS: int-var
303