main page
modules
namespaces
classes
files
Gecode home
Generated on Sat May 25 2013 18:00:35 for Gecode by
doxygen
1.8.3.1
gecode
int
view
minus.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, 2003
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
MinusView::MinusView
(
void
) {}
46
forceinline
47
MinusView::MinusView
(
const
IntView
& y)
48
:
DerivedView
<
IntView
>(y) {}
49
50
51
/*
52
* Value access
53
*
54
*/
55
forceinline
int
56
MinusView::min
(
void
)
const
{
57
return
-
x
.
max
();
58
}
59
forceinline
int
60
MinusView::max
(
void
)
const
{
61
return
-
x
.
min
();
62
}
63
forceinline
int
64
MinusView::val
(
void
)
const
{
65
return
-
x
.
val
();
66
}
67
68
forceinline
unsigned
int
69
MinusView::width
(
void
)
const
{
70
return
x
.
width
();
71
}
72
forceinline
unsigned
int
73
MinusView::size
(
void
)
const
{
74
return
x
.
size
();
75
}
76
forceinline
unsigned
int
77
MinusView::regret_min
(
void
)
const
{
78
return
x
.
regret_max
();
79
}
80
forceinline
unsigned
int
81
MinusView::regret_max
(
void
)
const
{
82
return
x
.
regret_min
();
83
}
84
85
86
/*
87
* Domain tests
88
*
89
*/
90
forceinline
bool
91
MinusView::range
(
void
)
const
{
92
return
x
.
range
();
93
}
94
forceinline
bool
95
MinusView::in
(
int
n
)
const
{
96
return
x
.
in
(-n);
97
}
98
forceinline
bool
99
MinusView::in
(
long
long
int
n
)
const
{
100
return
x
.
in
(-n);
101
}
102
103
104
/*
105
* Domain update by value
106
*
107
*/
108
forceinline
ModEvent
109
MinusView::lq
(
Space
& home,
int
n
) {
110
return
x
.
gq
(home,-n);
111
}
112
forceinline
ModEvent
113
MinusView::lq
(
Space
& home,
long
long
int
n
) {
114
return
x
.
gq
(home,-n);
115
}
116
117
forceinline
ModEvent
118
MinusView::le
(
Space
& home,
int
n
) {
119
return
x
.
gr
(home,-n);
120
}
121
forceinline
ModEvent
122
MinusView::le
(
Space
& home,
long
long
int
n
) {
123
return
x
.
gr
(home,-n);
124
}
125
126
forceinline
ModEvent
127
MinusView::gq
(
Space
& home,
int
n
) {
128
return
x
.
lq
(home,-n);
129
}
130
forceinline
ModEvent
131
MinusView::gq
(
Space
& home,
long
long
int
n
) {
132
return
x
.
lq
(home,-n);
133
}
134
135
forceinline
ModEvent
136
MinusView::gr
(
Space
& home,
int
n
) {
137
return
x
.
le
(home,-n);
138
}
139
forceinline
ModEvent
140
MinusView::gr
(
Space
& home,
long
long
int
n
) {
141
return
x
.
le
(home,-n);
142
}
143
144
forceinline
ModEvent
145
MinusView::nq
(
Space
& home,
int
n
) {
146
return
x
.
nq
(home,-n);
147
}
148
forceinline
ModEvent
149
MinusView::nq
(
Space
& home,
long
long
int
n
) {
150
return
x
.
nq
(home,-n);
151
}
152
153
forceinline
ModEvent
154
MinusView::eq
(
Space
& home,
int
n
) {
155
return
x
.
eq
(home,-n);
156
}
157
forceinline
ModEvent
158
MinusView::eq
(
Space
& home,
long
long
int
n
) {
159
return
x
.
eq
(home,-n);
160
}
161
162
163
/*
164
* Iterator-based domain update
165
*
166
*/
167
template
<
class
I>
168
forceinline
ModEvent
169
MinusView::narrow_r
(
Space
& home, I&
i
,
bool
) {
170
Region
r
(home);
171
Iter::Ranges::Minus
mi(r,i);
172
return
x
.
narrow_r
(home,mi,
false
);
173
}
174
template
<
class
I>
175
forceinline
ModEvent
176
MinusView::inter_r
(
Space
& home, I&
i
,
bool
) {
177
Region
r
(home);
178
Iter::Ranges::Minus
mi(r,i);
179
return
x
.
inter_r
(home,mi,
false
);
180
}
181
template
<
class
I>
182
forceinline
ModEvent
183
MinusView::minus_r
(
Space
& home, I&
i
,
bool
) {
184
Region
r
(home);
185
Iter::Ranges::Minus
mi(r,i);
186
return
x
.
minus_r
(home,mi,
false
);
187
}
188
template
<
class
I>
189
forceinline
ModEvent
190
MinusView::narrow_v
(
Space
& home, I&
i
,
bool
) {
191
Region
r
(home);
192
Iter::Values::Minus
mi(r,i);
193
return
x
.
narrow_v
(home,mi,
false
);
194
}
195
template
<
class
I>
196
forceinline
ModEvent
197
MinusView::inter_v
(
Space
& home, I&
i
,
bool
) {
198
Region
r
(home);
199
Iter::Values::Minus
mi(r,i);
200
return
x
.
inter_v
(home,mi,
false
);
201
}
202
template
<
class
I>
203
forceinline
ModEvent
204
MinusView::minus_v
(
Space
& home, I&
i
,
bool
) {
205
Region
r
(home);
206
Iter::Values::Minus
mi(r,i);
207
return
x
.
minus_v
(home,mi,
false
);
208
}
209
210
211
/*
212
* Propagator modification events
213
*
214
*/
215
forceinline
ModEventDelta
216
MinusView::med
(
ModEvent
me) {
217
return
IntView::med
(me);
218
}
219
220
221
/*
222
* Delta information for advisors
223
*
224
*/
225
forceinline
int
226
MinusView::min
(
const
Delta
&
d
)
const
{
227
return
-
x
.
max
(d);
228
}
229
forceinline
int
230
MinusView::max
(
const
Delta
&
d
)
const
{
231
return
-
x
.
min
(d);
232
}
233
forceinline
bool
234
MinusView::any
(
const
Delta
&
d
)
const
{
235
return
x
.
any
(d);
236
}
237
238
243
template
<>
244
class
ViewRanges
<
MinusView
> :
public
IntVarImpBwd
{
245
public
:
247
248
249
ViewRanges
(
void
);
251
ViewRanges
(
const
MinusView
&
x
);
253
void
init
(
const
MinusView
& x);
255
257
258
259
int
min
(
void
)
const
;
261
int
max
(
void
)
const
;
263
};
264
265
forceinline
266
ViewRanges<MinusView>::ViewRanges
(
void
) {}
267
268
forceinline
269
ViewRanges<MinusView>::ViewRanges
(
const
MinusView
&
x
)
270
:
IntVarImpBwd
(x.base().varimp()) {}
271
272
forceinline
void
273
ViewRanges<MinusView>::init
(
const
MinusView
&
x
) {
274
IntVarImpBwd::init
(x.
base
().
varimp
());
275
}
276
277
forceinline
int
278
ViewRanges<MinusView>::min
(
void
)
const
{
279
return
-
IntVarImpBwd::max
();
280
}
281
forceinline
int
282
ViewRanges<MinusView>::max
(
void
)
const
{
283
return
-
IntVarImpBwd::min
();
284
}
285
286
inline
int
287
MinusView::med
(
void
)
const
{
288
if
(
x
.
range
())
289
return
(
min
()+
max
())/2 - ((
min
()+
max
())%2 < 0 ? 1 : 0);
290
291
unsigned
int
i
=
x
.
size
() / 2;
292
if
(
size
() % 2 == 0)
293
i--;
294
ViewRanges<MinusView>
r
(*
this
);
295
while
(i >= r.
width
()) {
296
i -= r.
width
();
297
++
r
;
298
}
299
return
r.
min
() +
static_cast<
int
>
(
i
);
300
}
301
302
}}
303
304
// STATISTICS: int-var
305