Generated on Fri Aug 31 2012 16:21:32 for Gecode by doxygen 1.8.1.2
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  */
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
78  return 0;
79  }
80  forceinline unsigned int
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  */
110  return (0 <= n) ? ME_INT_NONE : ME_INT_FAILED;
111  }
113  ZeroIntView::lq(Space&, double n) {
114  return (0 <= n) ? ME_INT_NONE : ME_INT_FAILED;
115  }
116 
119  return (0 < n) ? ME_INT_NONE : ME_INT_FAILED;
120  }
122  ZeroIntView::le(Space&, double n) {
123  return (0 < n) ? ME_INT_NONE : ME_INT_FAILED;
124  }
125 
128  return (0 >= n) ? ME_INT_NONE : ME_INT_FAILED;
129  }
131  ZeroIntView::gq(Space&, double n) {
132  return (0 >= n) ? ME_INT_NONE : ME_INT_FAILED;
133  }
134 
137  return (0 > n) ? ME_INT_NONE : ME_INT_FAILED;
138  }
140  ZeroIntView::gr(Space&, double n) {
141  return (0 > n) ? ME_INT_NONE : ME_INT_FAILED;
142  }
143 
146  return (0 != n) ? ME_INT_NONE : ME_INT_FAILED;
147  }
149  ZeroIntView::nq(Space&, double n) {
150  return (0 != n) ? ME_INT_NONE : ME_INT_FAILED;
151  }
152 
155  return (0 == n) ? ME_INT_NONE : ME_INT_FAILED;
156  }
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>
171  return i() ? ME_INT_NONE : ME_INT_FAILED;
172  }
173  template<class I>
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>
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>
190  return i() ? ME_INT_NONE : ME_INT_FAILED;
191  }
192  template<class I>
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>
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<>
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 
266 
269  : done(false) {}
270 
271  forceinline bool
273  return !done;
274  }
275  forceinline void
277  done=true;
278  }
279 
280  forceinline int
282  return 0;
283  }
284  forceinline int
286  return 0;
287  }
288  forceinline unsigned int
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