this repo has no description
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 * This file is part of Gecode, the generic constraint
10 * development environment:
11 * http://www.gecode.org
12 *
13 * Permission is hereby granted, free of charge, to any person obtaining
14 * a copy of this software and associated documentation files (the
15 * "Software"), to deal in the Software without restriction, including
16 * without limitation the rights to use, copy, modify, merge, publish,
17 * distribute, sublicense, and/or sell copies of the Software, and to
18 * permit persons to whom the Software is furnished to do so, subject to
19 * the following conditions:
20 *
21 * The above copyright notice and this permission notice shall be
22 * included in all copies or substantial portions of the Software.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 *
32 */
33
34namespace Gecode { namespace Int {
35
36 /*
37 * Constructors and initialization
38 *
39 */
40 forceinline
41 ConstIntView::ConstIntView(void) {}
42 forceinline
43 ConstIntView::ConstIntView(int n) : x(n) {}
44
45 /*
46 * Value access
47 *
48 */
49 forceinline int
50 ConstIntView::min(void) const {
51 return x;
52 }
53 forceinline int
54 ConstIntView::max(void) const {
55 return x;
56 }
57 forceinline int
58 ConstIntView::med(void) const {
59 return x;
60 }
61 forceinline int
62 ConstIntView::val(void) const {
63 return x;
64 }
65
66 forceinline unsigned int
67 ConstIntView::size(void) const {
68 return 1;
69 }
70 forceinline unsigned int
71 ConstIntView::width(void) const {
72 return 1;
73 }
74 forceinline unsigned int
75 ConstIntView::regret_min(void) const {
76 return 0;
77 }
78 forceinline unsigned int
79 ConstIntView::regret_max(void) const {
80 return 0;
81 }
82
83
84 /*
85 * Domain tests
86 *
87 */
88 forceinline bool
89 ConstIntView::range(void) const {
90 return true;
91 }
92 forceinline bool
93 ConstIntView::in(int n) const {
94 return n == x;
95 }
96 forceinline bool
97 ConstIntView::in(long long int n) const {
98 return n == x;
99 }
100
101
102 /*
103 * Domain update by value
104 *
105 */
106 forceinline ModEvent
107 ConstIntView::lq(Space&, int n) {
108 return (x <= n) ? ME_INT_NONE : ME_INT_FAILED;
109 }
110 forceinline ModEvent
111 ConstIntView::lq(Space&, long long int n) {
112 return (x <= n) ? ME_INT_NONE : ME_INT_FAILED;
113 }
114
115 forceinline ModEvent
116 ConstIntView::le(Space&, int n) {
117 return (x < n) ? ME_INT_NONE : ME_INT_FAILED;
118 }
119 forceinline ModEvent
120 ConstIntView::le(Space&, long long int n) {
121 return (x < n) ? ME_INT_NONE : ME_INT_FAILED;
122 }
123
124 forceinline ModEvent
125 ConstIntView::gq(Space&, int n) {
126 return (x >= n) ? ME_INT_NONE : ME_INT_FAILED;
127 }
128 forceinline ModEvent
129 ConstIntView::gq(Space&, long long int n) {
130 return (x >= n) ? ME_INT_NONE : ME_INT_FAILED;
131 }
132
133 forceinline ModEvent
134 ConstIntView::gr(Space&, int n) {
135 return (x > n) ? ME_INT_NONE : ME_INT_FAILED;
136 }
137 forceinline ModEvent
138 ConstIntView::gr(Space&, long long int n) {
139 return (x > n) ? ME_INT_NONE : ME_INT_FAILED;
140 }
141
142 forceinline ModEvent
143 ConstIntView::nq(Space&, int n) {
144 return (x != n) ? ME_INT_NONE : ME_INT_FAILED;
145 }
146 forceinline ModEvent
147 ConstIntView::nq(Space&, long long int n) {
148 return (x != n) ? ME_INT_NONE : ME_INT_FAILED;
149 }
150
151 forceinline ModEvent
152 ConstIntView::eq(Space&, int n) {
153 return (x == n) ? ME_INT_NONE : ME_INT_FAILED;
154 }
155 forceinline ModEvent
156 ConstIntView::eq(Space&, long long int n) {
157 return (x == n) ? ME_INT_NONE : ME_INT_FAILED;
158 }
159
160
161
162 /*
163 * Iterator-based domain update
164 *
165 */
166 template<class I>
167 forceinline ModEvent
168 ConstIntView::narrow_r(Space&, I& i, bool) {
169 return i() ? ME_INT_NONE : ME_INT_FAILED;
170 }
171 template<class I>
172 forceinline ModEvent
173 ConstIntView::inter_r(Space&, I& i, bool) {
174 while (i() && (i.max() < x))
175 ++i;
176 return (i() && (i.min() <= x)) ? ME_INT_NONE : ME_INT_FAILED;
177 }
178 template<class I>
179 forceinline ModEvent
180 ConstIntView::minus_r(Space&, I& i, bool) {
181 while (i() && (i.max() < x))
182 ++i;
183 return (i() && (i.min() <= x)) ? ME_INT_FAILED : ME_INT_NONE;
184 }
185 template<class I>
186 forceinline ModEvent
187 ConstIntView::narrow_v(Space&, I& i, bool) {
188 return i() ? ME_INT_NONE : ME_INT_FAILED;
189 }
190 template<class I>
191 forceinline ModEvent
192 ConstIntView::inter_v(Space&, I& i, bool) {
193 while (i() && (i.val() < x))
194 ++i;
195 return (i() && (i.val() == x)) ? ME_INT_NONE : ME_INT_FAILED;
196 }
197 template<class I>
198 forceinline ModEvent
199 ConstIntView::minus_v(Space&, I& i, bool) {
200 while (i() && (i.val() < x))
201 ++i;
202 return (i() && (i.val() == x)) ? ME_INT_FAILED : ME_INT_NONE;
203 }
204
205
206 /*
207 * Delta information for advisors
208 *
209 */
210 forceinline int
211 ConstIntView::min(const Delta&) const {
212 return 1;
213 }
214 forceinline int
215 ConstIntView::max(const Delta&) const {
216 return 0;
217 }
218 forceinline unsigned int
219 ConstIntView::width(const Delta&) const {
220 return 1U;
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, ConstIntView& y) {
235 ConstView<IntView>::update(home,y);
236 x = y.x;
237 }
238
239
240 /*
241 * Ordering
242 *
243 */
244 forceinline bool
245 ConstIntView::operator <(const ConstIntView& y) const {
246 return min() < y.min();
247 }
248
249
250 /**
251 * \brief %Range iterator for constant integer views
252 * \ingroup TaskActorIntView
253 */
254 template<>
255 class ViewRanges<ConstIntView> {
256 private:
257 /// The single integer to iterate
258 int n;
259 public:
260 /// \name Constructors and initialization
261 //@{
262 /// Default constructor
263 ViewRanges(void);
264 /// Initialize with ranges for view \a x
265 ViewRanges(const ConstIntView& x);
266 /// Initialize with ranges for view \a x
267 void init(const ConstIntView& x);
268 //@}
269
270 /// \name Iteration control
271 //@{
272 /// Test whether iterator is still at a range or done
273 bool operator ()(void) const;
274 /// Move iterator to next range (if possible)
275 void operator ++(void);
276 //@}
277
278 /// \name Range access
279 //@{
280 /// Return smallest value of range
281 int min(void) const;
282 /// Return largest value of range
283 int max(void) const;
284 /// Return width of ranges (distance between minimum and maximum)
285 unsigned int width(void) const;
286 //@}
287 };
288
289 forceinline
290 ViewRanges<ConstIntView>::ViewRanges(void) {}
291
292 forceinline
293 ViewRanges<ConstIntView>::ViewRanges(const ConstIntView& x)
294 : n(x.val()) {}
295
296 forceinline bool
297 ViewRanges<ConstIntView>::operator ()(void) const {
298 return n <= Limits::max;
299 }
300 forceinline void
301 ViewRanges<ConstIntView>::operator ++(void) {
302 n = Limits::max+1;
303 }
304
305 forceinline int
306 ViewRanges<ConstIntView>::min(void) const {
307 return n;
308 }
309 forceinline int
310 ViewRanges<ConstIntView>::max(void) const {
311 return n;
312 }
313 forceinline unsigned int
314 ViewRanges<ConstIntView>::width(void) const {
315 return 1;
316 }
317
318 /*
319 * View comparison
320 *
321 */
322 forceinline bool
323 operator ==(const ConstIntView& x, const ConstIntView& y) {
324 return x.min() == y.min();
325 }
326 forceinline bool
327 operator !=(const ConstIntView& x, const ConstIntView& y) {
328 return !(x == y);
329 }
330
331}}
332
333// STATISTICS: int-var
334