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 ZeroIntView::ZeroIntView(void) {}
42
43 /*
44 * Value access
45 *
46 */
47 forceinline int
48 ZeroIntView::min(void) const {
49 return 0;
50 }
51 forceinline int
52 ZeroIntView::max(void) const {
53 return 0;
54 }
55 forceinline int
56 ZeroIntView::med(void) const {
57 return 0;
58 }
59 forceinline int
60 ZeroIntView::val(void) const {
61 return 0;
62 }
63
64 forceinline unsigned int
65 ZeroIntView::size(void) const {
66 return 1;
67 }
68 forceinline unsigned int
69 ZeroIntView::width(void) const {
70 return 1;
71 }
72 forceinline unsigned int
73 ZeroIntView::regret_min(void) const {
74 return 0;
75 }
76 forceinline unsigned int
77 ZeroIntView::regret_max(void) const {
78 return 0;
79 }
80
81
82 /*
83 * Domain tests
84 *
85 */
86 forceinline bool
87 ZeroIntView::range(void) const {
88 return true;
89 }
90 forceinline bool
91 ZeroIntView::in(int n) const {
92 return n == 0;
93 }
94 forceinline bool
95 ZeroIntView::in(long long int n) const {
96 return n == 0;
97 }
98
99
100 /*
101 * Domain update by value
102 *
103 */
104 forceinline ModEvent
105 ZeroIntView::lq(Space&, int n) {
106 return (0 <= n) ? ME_INT_NONE : ME_INT_FAILED;
107 }
108 forceinline ModEvent
109 ZeroIntView::lq(Space&, long long int n) {
110 return (0 <= n) ? ME_INT_NONE : ME_INT_FAILED;
111 }
112
113 forceinline ModEvent
114 ZeroIntView::le(Space&, int n) {
115 return (0 < n) ? ME_INT_NONE : ME_INT_FAILED;
116 }
117 forceinline ModEvent
118 ZeroIntView::le(Space&, long long int n) {
119 return (0 < n) ? ME_INT_NONE : ME_INT_FAILED;
120 }
121
122 forceinline ModEvent
123 ZeroIntView::gq(Space&, int n) {
124 return (0 >= n) ? ME_INT_NONE : ME_INT_FAILED;
125 }
126 forceinline ModEvent
127 ZeroIntView::gq(Space&, long long int n) {
128 return (0 >= n) ? ME_INT_NONE : ME_INT_FAILED;
129 }
130
131 forceinline ModEvent
132 ZeroIntView::gr(Space&, int n) {
133 return (0 > n) ? ME_INT_NONE : ME_INT_FAILED;
134 }
135 forceinline ModEvent
136 ZeroIntView::gr(Space&, long long int n) {
137 return (0 > n) ? ME_INT_NONE : ME_INT_FAILED;
138 }
139
140 forceinline ModEvent
141 ZeroIntView::nq(Space&, int n) {
142 return (0 != n) ? ME_INT_NONE : ME_INT_FAILED;
143 }
144 forceinline ModEvent
145 ZeroIntView::nq(Space&, long long int n) {
146 return (0 != n) ? ME_INT_NONE : ME_INT_FAILED;
147 }
148
149 forceinline ModEvent
150 ZeroIntView::eq(Space&, int n) {
151 return (0 == n) ? ME_INT_NONE : ME_INT_FAILED;
152 }
153 forceinline ModEvent
154 ZeroIntView::eq(Space&, long long int n) {
155 return (0 == n) ? ME_INT_NONE : ME_INT_FAILED;
156 }
157
158
159
160 /*
161 * Iterator-based domain update
162 *
163 */
164 template<class I>
165 forceinline ModEvent
166 ZeroIntView::narrow_r(Space&, I& i, bool) {
167 return i() ? ME_INT_NONE : ME_INT_FAILED;
168 }
169 template<class I>
170 forceinline ModEvent
171 ZeroIntView::inter_r(Space&, I& i, bool) {
172 while (i() && (i.max() < 0))
173 ++i;
174 return (i() && (i.min() <= 0)) ? ME_INT_NONE : ME_INT_FAILED;
175 }
176 template<class I>
177 forceinline ModEvent
178 ZeroIntView::minus_r(Space&, I& i, bool) {
179 while (i() && (i.max() < 0))
180 ++i;
181 return (i() && (i.min() <= 0)) ? ME_INT_FAILED : ME_INT_NONE;
182 }
183 template<class I>
184 forceinline ModEvent
185 ZeroIntView::narrow_v(Space&, I& i, bool) {
186 return i() ? ME_INT_NONE : ME_INT_FAILED;
187 }
188 template<class I>
189 forceinline ModEvent
190 ZeroIntView::inter_v(Space&, I& i, bool) {
191 while (i() && (i.val() < 0))
192 ++i;
193 return (i() && (i.val() == 0)) ? ME_INT_NONE : ME_INT_FAILED;
194 }
195 template<class I>
196 forceinline ModEvent
197 ZeroIntView::minus_v(Space&, I& i, bool) {
198 while (i() && (i.val() < 0))
199 ++i;
200 return (i() && (i.val() == 0)) ? ME_INT_FAILED : ME_INT_NONE;
201 }
202
203 /*
204 * Delta information for advisors
205 *
206 */
207 forceinline int
208 ZeroIntView::min(const Delta&) const {
209 return 1;
210 }
211 forceinline int
212 ZeroIntView::max(const Delta&) const {
213 return 0;
214 }
215 forceinline unsigned int
216 ZeroIntView::width(const Delta&) const {
217 return 1U;
218 }
219 forceinline bool
220 ZeroIntView::any(const Delta&) const {
221 return true;
222 }
223
224
225 /**
226 * \brief %Range iterator for constant integer views
227 * \ingroup TaskActorIntView
228 */
229 template<>
230 class ViewRanges<ZeroIntView> {
231 private:
232 /// Whether the iterator is done
233 bool done;
234 public:
235 /// \name Constructors and initialization
236 //@{
237 /// Default constructor
238 ViewRanges(void);
239 /// Initialize with ranges for view \a x
240 ViewRanges(const ZeroIntView& x);
241 /// Initialize with ranges for view \a x
242 void init(const ZeroIntView& x);
243 //@}
244
245 /// \name Iteration control
246 //@{
247 /// Test whether iterator is still at a range or done
248 bool operator ()(void) const;
249 /// Move iterator to next range (if possible)
250 void operator ++(void);
251 //@}
252
253 /// \name Range access
254 //@{
255 /// Return smallest value of range
256 int min(void) const;
257 /// Return largest value of range
258 int max(void) const;
259 /// Return width of ranges (distance between minimum and maximum)
260 unsigned int width(void) const;
261 //@}
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 operator ==(const ZeroIntView&, const ZeroIntView&) {
299 return true;
300 }
301 forceinline bool
302 operator !=(const ZeroIntView&, const ZeroIntView&) {
303 return false;
304 }
305
306}}
307
308// STATISTICS: int-var
309