main page
modules
namespaces
classes
files
Gecode home
Generated on Sun Aug 26 2012 08:43:10 for Gecode by
doxygen
1.8.1.1
gecode
int
view
constint.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
ConstIntView::ConstIntView
(
void
) {}
46
forceinline
47
ConstIntView::ConstIntView
(
int
n) : x(n) {}
48
49
/*
50
* Value access
51
*
52
*/
53
forceinline
int
54
ConstIntView::min
(
void
)
const
{
55
return
x
;
56
}
57
forceinline
int
58
ConstIntView::max
(
void
)
const
{
59
return
x
;
60
}
61
forceinline
int
62
ConstIntView::med
(
void
)
const
{
63
return
x
;
64
}
65
forceinline
int
66
ConstIntView::val
(
void
)
const
{
67
return
x
;
68
}
69
70
forceinline
unsigned
int
71
ConstIntView::size
(
void
)
const
{
72
return
1;
73
}
74
forceinline
unsigned
int
75
ConstIntView::width
(
void
)
const
{
76
return
1;
77
}
78
forceinline
unsigned
int
79
ConstIntView::regret_min
(
void
)
const
{
80
return
0;
81
}
82
forceinline
unsigned
int
83
ConstIntView::regret_max
(
void
)
const
{
84
return
0;
85
}
86
87
88
/*
89
* Domain tests
90
*
91
*/
92
forceinline
bool
93
ConstIntView::range
(
void
)
const
{
94
return
true
;
95
}
96
forceinline
bool
97
ConstIntView::in
(
int
n)
const
{
98
return
n ==
x
;
99
}
100
forceinline
bool
101
ConstIntView::in
(
double
n)
const
{
102
return
n ==
x
;
103
}
104
105
106
/*
107
* Domain update by value
108
*
109
*/
110
forceinline
ModEvent
111
ConstIntView::lq
(
Space
&,
int
n) {
112
return
(
x
<= n) ?
ME_INT_NONE
:
ME_INT_FAILED
;
113
}
114
forceinline
ModEvent
115
ConstIntView::lq
(
Space
&,
double
n) {
116
return
(
x
<= n) ?
ME_INT_NONE
:
ME_INT_FAILED
;
117
}
118
119
forceinline
ModEvent
120
ConstIntView::le
(
Space
&,
int
n) {
121
return
(
x
< n) ?
ME_INT_NONE
:
ME_INT_FAILED
;
122
}
123
forceinline
ModEvent
124
ConstIntView::le
(
Space
&,
double
n) {
125
return
(
x
< n) ?
ME_INT_NONE
:
ME_INT_FAILED
;
126
}
127
128
forceinline
ModEvent
129
ConstIntView::gq
(
Space
&,
int
n) {
130
return
(
x
>= n) ?
ME_INT_NONE
:
ME_INT_FAILED
;
131
}
132
forceinline
ModEvent
133
ConstIntView::gq
(
Space
&,
double
n) {
134
return
(
x
>= n) ?
ME_INT_NONE
:
ME_INT_FAILED
;
135
}
136
137
forceinline
ModEvent
138
ConstIntView::gr
(
Space
&,
int
n) {
139
return
(
x
> n) ?
ME_INT_NONE
:
ME_INT_FAILED
;
140
}
141
forceinline
ModEvent
142
ConstIntView::gr
(
Space
&,
double
n) {
143
return
(
x
> n) ?
ME_INT_NONE
:
ME_INT_FAILED
;
144
}
145
146
forceinline
ModEvent
147
ConstIntView::nq
(
Space
&,
int
n) {
148
return
(
x
!= n) ?
ME_INT_NONE
:
ME_INT_FAILED
;
149
}
150
forceinline
ModEvent
151
ConstIntView::nq
(
Space
&,
double
n) {
152
return
(
x
!= n) ?
ME_INT_NONE
:
ME_INT_FAILED
;
153
}
154
155
forceinline
ModEvent
156
ConstIntView::eq
(
Space
&,
int
n) {
157
return
(
x
== n) ?
ME_INT_NONE
:
ME_INT_FAILED
;
158
}
159
forceinline
ModEvent
160
ConstIntView::eq
(
Space
&,
double
n) {
161
return
(
x
== n) ?
ME_INT_NONE
:
ME_INT_FAILED
;
162
}
163
164
165
166
/*
167
* Iterator-based domain update
168
*
169
*/
170
template
<
class
I>
171
forceinline
ModEvent
172
ConstIntView::narrow_r
(
Space
&, I&
i
,
bool
) {
173
return
i
() ?
ME_INT_NONE
:
ME_INT_FAILED
;
174
}
175
template
<
class
I>
176
forceinline
ModEvent
177
ConstIntView::inter_r
(
Space
&, I&
i
,
bool
) {
178
while
(
i
() && (i.max() <
x
))
179
++
i
;
180
return
(
i
() && (i.min() <=
x
)) ?
ME_INT_NONE
:
ME_INT_FAILED
;
181
}
182
template
<
class
I>
183
forceinline
ModEvent
184
ConstIntView::minus_r
(
Space
&, I&
i
,
bool
) {
185
while
(
i
() && (i.max() <
x
))
186
++
i
;
187
return
(
i
() && (i.min() <=
x
)) ?
ME_INT_FAILED
:
ME_INT_NONE
;
188
}
189
template
<
class
I>
190
forceinline
ModEvent
191
ConstIntView::narrow_v
(
Space
&, I&
i
,
bool
) {
192
return
i
() ?
ME_INT_NONE
:
ME_INT_FAILED
;
193
}
194
template
<
class
I>
195
forceinline
ModEvent
196
ConstIntView::inter_v
(
Space
&, I&
i
,
bool
) {
197
while
(
i
() && (i.val() <
x
))
198
++
i
;
199
return
(
i
() && (i.val() ==
x
)) ?
ME_INT_NONE
:
ME_INT_FAILED
;
200
}
201
template
<
class
I>
202
forceinline
ModEvent
203
ConstIntView::minus_v
(
Space
&, I&
i
,
bool
) {
204
while
(
i
() && (i.val() <
x
))
205
++
i
;
206
return
(
i
() && (i.val() ==
x
)) ?
ME_INT_FAILED
:
ME_INT_NONE
;
207
}
208
209
210
/*
211
* Delta information for advisors
212
*
213
*/
214
forceinline
int
215
ConstIntView::min
(
const
Delta
&)
const
{
216
return
1;
217
}
218
forceinline
int
219
ConstIntView::max
(
const
Delta
&)
const
{
220
return
0;
221
}
222
forceinline
bool
223
ConstIntView::any
(
const
Delta
&)
const
{
224
return
true
;
225
}
226
227
228
229
/*
230
* Cloning
231
*
232
*/
233
forceinline
void
234
ConstIntView::update
(
Space
& home,
bool
share,
ConstIntView
& y) {
235
ConstView<IntView>::update
(home,share,y);
236
x
= y.
x
;
237
}
238
239
244
template
<>
245
class
ViewRanges
<
ConstIntView
> {
246
private
:
248
int
n;
249
public
:
251
252
253
ViewRanges
(
void
);
255
ViewRanges
(
const
ConstIntView
& x);
257
void
init
(
const
ConstIntView
& x);
259
261
262
263
bool
operator ()
(
void
)
const
;
265
void
operator ++
(
void
);
267
269
270
271
int
min
(
void
)
const
;
273
int
max
(
void
)
const
;
275
unsigned
int
width
(
void
)
const
;
277
};
278
279
forceinline
280
ViewRanges<ConstIntView>::ViewRanges
(
void
) {}
281
282
forceinline
283
ViewRanges<ConstIntView>::ViewRanges
(
const
ConstIntView
& x)
284
: n(x.val()) {}
285
286
forceinline
bool
287
ViewRanges<ConstIntView>::operator ()
(
void
)
const
{
288
return
n <=
Limits::max
;
289
}
290
forceinline
void
291
ViewRanges<ConstIntView>::operator ++
(
void
) {
292
n =
Limits::max
+1;
293
}
294
295
forceinline
int
296
ViewRanges<ConstIntView>::min
(
void
)
const
{
297
return
n;
298
}
299
forceinline
int
300
ViewRanges<ConstIntView>::max
(
void
)
const
{
301
return
n;
302
}
303
forceinline
unsigned
int
304
ViewRanges<ConstIntView>::width
(
void
)
const
{
305
return
1;
306
}
307
308
/*
309
* View comparison
310
*
311
*/
312
forceinline
bool
313
same
(
const
ConstIntView
& x,
const
ConstIntView
& y) {
314
return
x.
min
() == y.
min
();
315
}
316
forceinline
bool
317
before
(
const
ConstIntView
& x,
const
ConstIntView
& y) {
318
return
x.
min
() < y.
min
();
319
}
320
321
}}
322
323
// STATISTICS: int-var
324