main page
modules
namespaces
classes
files
Gecode home
Generated on Fri Aug 31 2012 16:21:32 for Gecode by
doxygen
1.8.1.2
gecode
int
view
zero.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: 2010-07-29 01:35:33 +1000 (Thu, 29 Jul 2010) $ by $Author: schulte $
11
* $Revision: 11294 $
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
ZeroIntView::ZeroIntView
(
void
) {}
46
47
/*
48
* Value access
49
*
50
*/
51
forceinline
int
52
ZeroIntView::min
(
void
)
const
{
53
return
0;
54
}
55
forceinline
int
56
ZeroIntView::max
(
void
)
const
{
57
return
0;
58
}
59
forceinline
int
60
ZeroIntView::med
(
void
)
const
{
61
return
0;
62
}
63
forceinline
int
64
ZeroIntView::val
(
void
)
const
{
65
return
0;
66
}
67
68
forceinline
unsigned
int
69
ZeroIntView::size
(
void
)
const
{
70
return
1;
71
}
72
forceinline
unsigned
int
73
ZeroIntView::width
(
void
)
const
{
74
return
1;
75
}
76
forceinline
unsigned
int
77
ZeroIntView::regret_min
(
void
)
const
{
78
return
0;
79
}
80
forceinline
unsigned
int
81
ZeroIntView::regret_max
(
void
)
const
{
82
return
0;
83
}
84
85
86
/*
87
* Domain tests
88
*
89
*/
90
forceinline
bool
91
ZeroIntView::range
(
void
)
const
{
92
return
true
;
93
}
94
forceinline
bool
95
ZeroIntView::in
(
int
n)
const
{
96
return
n == 0;
97
}
98
forceinline
bool
99
ZeroIntView::in
(
double
n)
const
{
100
return
n == 0;
101
}
102
103
104
/*
105
* Domain update by value
106
*
107
*/
108
forceinline
ModEvent
109
ZeroIntView::lq
(
Space
&,
int
n) {
110
return
(0 <= n) ?
ME_INT_NONE
:
ME_INT_FAILED
;
111
}
112
forceinline
ModEvent
113
ZeroIntView::lq
(
Space
&,
double
n) {
114
return
(0 <= n) ?
ME_INT_NONE
:
ME_INT_FAILED
;
115
}
116
117
forceinline
ModEvent
118
ZeroIntView::le
(
Space
&,
int
n) {
119
return
(0 < n) ?
ME_INT_NONE
:
ME_INT_FAILED
;
120
}
121
forceinline
ModEvent
122
ZeroIntView::le
(
Space
&,
double
n) {
123
return
(0 < n) ?
ME_INT_NONE
:
ME_INT_FAILED
;
124
}
125
126
forceinline
ModEvent
127
ZeroIntView::gq
(
Space
&,
int
n) {
128
return
(0 >= n) ?
ME_INT_NONE
:
ME_INT_FAILED
;
129
}
130
forceinline
ModEvent
131
ZeroIntView::gq
(
Space
&,
double
n) {
132
return
(0 >= n) ?
ME_INT_NONE
:
ME_INT_FAILED
;
133
}
134
135
forceinline
ModEvent
136
ZeroIntView::gr
(
Space
&,
int
n) {
137
return
(0 > n) ?
ME_INT_NONE
:
ME_INT_FAILED
;
138
}
139
forceinline
ModEvent
140
ZeroIntView::gr
(
Space
&,
double
n) {
141
return
(0 > n) ?
ME_INT_NONE
:
ME_INT_FAILED
;
142
}
143
144
forceinline
ModEvent
145
ZeroIntView::nq
(
Space
&,
int
n) {
146
return
(0 != n) ?
ME_INT_NONE
:
ME_INT_FAILED
;
147
}
148
forceinline
ModEvent
149
ZeroIntView::nq
(
Space
&,
double
n) {
150
return
(0 != n) ?
ME_INT_NONE
:
ME_INT_FAILED
;
151
}
152
153
forceinline
ModEvent
154
ZeroIntView::eq
(
Space
&,
int
n) {
155
return
(0 == n) ?
ME_INT_NONE
:
ME_INT_FAILED
;
156
}
157
forceinline
ModEvent
158
ZeroIntView::eq
(
Space
&,
double
n) {
159
return
(0 == n) ?
ME_INT_NONE
:
ME_INT_FAILED
;
160
}
161
162
163
164
/*
165
* Iterator-based domain update
166
*
167
*/
168
template
<
class
I>
169
forceinline
ModEvent
170
ZeroIntView::narrow_r
(
Space
&, I&
i
,
bool
) {
171
return
i
() ?
ME_INT_NONE
:
ME_INT_FAILED
;
172
}
173
template
<
class
I>
174
forceinline
ModEvent
175
ZeroIntView::inter_r
(
Space
&, I&
i
,
bool
) {
176
while
(
i
() && (i.max() < 0))
177
++
i
;
178
return
(
i
() && (i.min() <= 0)) ?
ME_INT_NONE
:
ME_INT_FAILED
;
179
}
180
template
<
class
I>
181
forceinline
ModEvent
182
ZeroIntView::minus_r
(
Space
&, I&
i
,
bool
) {
183
while
(
i
() && (i.max() < 0))
184
++
i
;
185
return
(
i
() && (i.min() <= 0)) ?
ME_INT_FAILED
:
ME_INT_NONE
;
186
}
187
template
<
class
I>
188
forceinline
ModEvent
189
ZeroIntView::narrow_v
(
Space
&, I&
i
,
bool
) {
190
return
i
() ?
ME_INT_NONE
:
ME_INT_FAILED
;
191
}
192
template
<
class
I>
193
forceinline
ModEvent
194
ZeroIntView::inter_v
(
Space
&, I&
i
,
bool
) {
195
while
(
i
() && (i.val() < 0))
196
++
i
;
197
return
(
i
() && (i.val() == 0)) ?
ME_INT_NONE
:
ME_INT_FAILED
;
198
}
199
template
<
class
I>
200
forceinline
ModEvent
201
ZeroIntView::minus_v
(
Space
&, I&
i
,
bool
) {
202
while
(
i
() && (i.val() < 0))
203
++
i
;
204
return
(
i
() && (i.val() == 0)) ?
ME_INT_FAILED
:
ME_INT_NONE
;
205
}
206
207
/*
208
* Delta information for advisors
209
*
210
*/
211
forceinline
int
212
ZeroIntView::min
(
const
Delta
&)
const
{
213
return
1;
214
}
215
forceinline
int
216
ZeroIntView::max
(
const
Delta
&)
const
{
217
return
0;
218
}
219
forceinline
bool
220
ZeroIntView::any
(
const
Delta
&)
const
{
221
return
true
;
222
}
223
224
229
template
<>
230
class
ViewRanges
<
ZeroIntView
> {
231
private
:
233
bool
done;
234
public
:
236
237
238
ViewRanges
(
void
);
240
ViewRanges
(
const
ZeroIntView
& x);
242
void
init
(
const
ZeroIntView
& x);
244
246
247
248
bool
operator ()
(
void
)
const
;
250
void
operator ++
(
void
);
252
254
255
256
int
min
(
void
)
const
;
258
int
max
(
void
)
const
;
260
unsigned
int
width
(
void
)
const
;
262
};
263
264
forceinline
265
ViewRanges<ZeroIntView>::ViewRanges
(
void
) {}
266
267
forceinline
268
ViewRanges<ZeroIntView>::ViewRanges
(
const
ZeroIntView
&)
269
: done(false) {}
270
271
forceinline
bool
272
ViewRanges<ZeroIntView>::operator ()
(
void
)
const
{
273
return
!done;
274
}
275
forceinline
void
276
ViewRanges<ZeroIntView>::operator ++
(
void
) {
277
done=
true
;
278
}
279
280
forceinline
int
281
ViewRanges<ZeroIntView>::min
(
void
)
const
{
282
return
0;
283
}
284
forceinline
int
285
ViewRanges<ZeroIntView>::max
(
void
)
const
{
286
return
0;
287
}
288
forceinline
unsigned
int
289
ViewRanges<ZeroIntView>::width
(
void
)
const
{
290
return
1;
291
}
292
293
/*
294
* View comparison
295
*
296
*/
297
forceinline
bool
298
same
(
const
ZeroIntView
&,
const
ZeroIntView
&) {
299
return
true
;
300
}
301
302
}}
303
304
// STATISTICS: int-var
305