Generated on Sat Feb 7 2015 02:01:26 for Gecode by doxygen 1.8.9.1
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: 2013-02-14 16:29:11 +0100 (Thu, 14 Feb 2013) $ by $Author: schulte $
11  * $Revision: 13292 $
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  */
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
80  return 0;
81  }
82  forceinline unsigned int
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(long long int n) const {
102  return n == x;
103  }
104 
105 
106  /*
107  * Domain update by value
108  *
109  */
112  return (x <= n) ? ME_INT_NONE : ME_INT_FAILED;
113  }
115  ConstIntView::lq(Space&, long long int n) {
116  return (x <= n) ? ME_INT_NONE : ME_INT_FAILED;
117  }
118 
121  return (x < n) ? ME_INT_NONE : ME_INT_FAILED;
122  }
124  ConstIntView::le(Space&, long long int n) {
125  return (x < n) ? ME_INT_NONE : ME_INT_FAILED;
126  }
127 
130  return (x >= n) ? ME_INT_NONE : ME_INT_FAILED;
131  }
133  ConstIntView::gq(Space&, long long int n) {
134  return (x >= n) ? ME_INT_NONE : ME_INT_FAILED;
135  }
136 
139  return (x > n) ? ME_INT_NONE : ME_INT_FAILED;
140  }
142  ConstIntView::gr(Space&, long long int n) {
143  return (x > n) ? ME_INT_NONE : ME_INT_FAILED;
144  }
145 
148  return (x != n) ? ME_INT_NONE : ME_INT_FAILED;
149  }
151  ConstIntView::nq(Space&, long long int n) {
152  return (x != n) ? ME_INT_NONE : ME_INT_FAILED;
153  }
154 
157  return (x == n) ? ME_INT_NONE : ME_INT_FAILED;
158  }
160  ConstIntView::eq(Space&, long long int 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>
173  return i() ? ME_INT_NONE : ME_INT_FAILED;
174  }
175  template<class I>
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>
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>
192  return i() ? ME_INT_NONE : ME_INT_FAILED;
193  }
194  template<class I>
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>
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<>
246  private:
248  int n;
249  public:
251 
252  ViewRanges(void);
255  ViewRanges(const ConstIntView& x);
257  void init(const ConstIntView& x);
259 
261 
262  bool operator ()(void) const;
265  void operator ++(void);
267 
269 
270  int min(void) const;
273  int max(void) const;
275  unsigned int width(void) const;
277  };
278 
281 
284  : n(x.val()) {}
285 
286  forceinline bool
288  return n <= Limits::max;
289  }
290  forceinline void
292  n = Limits::max+1;
293  }
294 
295  forceinline int
297  return n;
298  }
299  forceinline int
301  return n;
302  }
303  forceinline unsigned int
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 
ModEvent inter_v(Space &home, I &i, bool depends=true)
Intersect domain with values described by i.
Definition: constint.hpp:196
unsigned int width(void) const
Return width of domain (distance between maximum and minimum)
Definition: constint.hpp:75
bool before(const CachedView< View > &x, const CachedView< View > &y)
Definition: cached.hpp:394
ViewRanges(void)
Default constructor.
bool operator()(void) const
Test whether iterator is still at a range or done.
void update(Space &home, bool share, ConstView &y)
Update this view to be a clone of view y.
Definition: view.hpp:411
int ModEvent
Type for modification events.
Definition: core.hpp:146
ModEvent lq(Space &home, int n)
Restrict domain values to be less or equal than n.
Definition: constint.hpp:111
ConstIntView(void)
Default constructor.
Definition: constint.hpp:45
ModEvent nq(Space &home, int n)
Restrict domain values to be different from n.
Definition: constint.hpp:147
bool in(int n) const
Test whether n is contained in domain.
Definition: constint.hpp:97
ModEvent narrow_r(Space &home, I &i, bool depends=true)
Replace domain by ranges described by i.
Definition: constint.hpp:172
const int max
Largest allowed integer value.
Definition: int.hh:113
ModEvent minus_r(Space &home, I &i, bool depends=true)
Remove from domain the ranges described by i.
Definition: constint.hpp:184
Computation spaces.
Definition: core.hpp:1362
ModEvent le(Space &home, int n)
Restrict domain values to be less than n.
Definition: constint.hpp:120
void init(const View &x)
Initialize with ranges for view x.
Range iterator for integer views.
Definition: view.hpp:54
int max(void) const
Return maximum of domain.
Definition: constint.hpp:58
const Gecode::ModEvent ME_INT_FAILED
Domain operation has resulted in failure.
Definition: var-type.hpp:52
bool same(const CachedView< View > &x, const CachedView< View > &y)
Definition: cached.hpp:389
int min(void) const
Return smallest value of range.
Gecode::IntArgs i(4, 1, 2, 3, 4)
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
int val(void) const
Return assigned value (only if assigned)
Definition: constint.hpp:66
ModEvent narrow_v(Space &home, I &i, bool depends=true)
Replace domain by values described by i.
Definition: constint.hpp:191
ModEvent inter_r(Space &home, I &i, bool depends=true)
Intersect domain with ranges described by i.
Definition: constint.hpp:177
void update(Space &home, bool share, ConstIntView &y)
Update this view to be a clone of view y.
Definition: constint.hpp:234
ModEvent gq(Space &home, int n)
Restrict domain values to be greater or equal than n.
Definition: constint.hpp:129
ModEvent eq(Space &home, int n)
Restrict domain values to be equal to n.
Definition: constint.hpp:156
unsigned int width(void) const
Return width of range (distance between minimum and maximum)
Constant integer view.
Definition: view.hpp:804
int min(void) const
Return minimum of domain.
Definition: constint.hpp:54
ModEvent minus_v(Space &home, I &i, bool depends=true)
Remove from domain the values described by i.
Definition: constint.hpp:203
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:253
Generic domain change information to be supplied to advisors.
Definition: core.hpp:275
int med(void) const
Return median of domain (greatest element not greater than the median)
Definition: constint.hpp:62
ModEvent gr(Space &home, int n)
Restrict domain values to be greater than n.
Definition: constint.hpp:138
unsigned int regret_min(void) const
Return regret of domain minimum (distance to next larger value)
Definition: constint.hpp:79
#define forceinline
Definition: config.hpp:132
void operator++(void)
Move iterator to next range (if possible)
int max(void) const
Return largest value of range.
Gecode toplevel namespace
bool any(const Delta &d) const
Test whether arbitrary values got pruned.
Definition: constint.hpp:223
unsigned int size(void) const
Return size (cardinality) of domain.
Definition: constint.hpp:71
bool range(void) const
Test whether domain is a range.
Definition: constint.hpp:93
const Gecode::ModEvent ME_INT_NONE
Domain operation has not changed domain.
Definition: var-type.hpp:54
unsigned int regret_max(void) const
Return regret of domain maximum (distance to next smaller value)
Definition: constint.hpp:83