Generated on Wed Jan 1 2020 10:37:59 for Gecode by doxygen 1.8.16
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  * 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 
34 namespace Gecode { namespace Int {
35 
36  /*
37  * Constructors and initialization
38  *
39  */
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
76  return 0;
77  }
78  forceinline unsigned int
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  */
108  return (x <= n) ? ME_INT_NONE : ME_INT_FAILED;
109  }
111  ConstIntView::lq(Space&, long long int n) {
112  return (x <= n) ? ME_INT_NONE : ME_INT_FAILED;
113  }
114 
117  return (x < n) ? ME_INT_NONE : ME_INT_FAILED;
118  }
120  ConstIntView::le(Space&, long long int n) {
121  return (x < n) ? ME_INT_NONE : ME_INT_FAILED;
122  }
123 
126  return (x >= n) ? ME_INT_NONE : ME_INT_FAILED;
127  }
129  ConstIntView::gq(Space&, long long int n) {
130  return (x >= n) ? ME_INT_NONE : ME_INT_FAILED;
131  }
132 
135  return (x > n) ? ME_INT_NONE : ME_INT_FAILED;
136  }
138  ConstIntView::gr(Space&, long long int n) {
139  return (x > n) ? ME_INT_NONE : ME_INT_FAILED;
140  }
141 
144  return (x != n) ? ME_INT_NONE : ME_INT_FAILED;
145  }
147  ConstIntView::nq(Space&, long long int n) {
148  return (x != n) ? ME_INT_NONE : ME_INT_FAILED;
149  }
150 
153  return (x == n) ? ME_INT_NONE : ME_INT_FAILED;
154  }
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>
169  return i() ? ME_INT_NONE : ME_INT_FAILED;
170  }
171  template<class I>
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>
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>
188  return i() ? ME_INT_NONE : ME_INT_FAILED;
189  }
190  template<class I>
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>
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
236  x = y.x;
237  }
238 
239 
240  /*
241  * Ordering
242  *
243  */
244  forceinline bool
246  return min() < y.min();
247  }
248 
249 
254  template<>
256  private:
258  int n;
259  public:
261 
262  ViewRanges(void);
265  ViewRanges(const ConstIntView& x);
267  void init(const ConstIntView& x);
269 
271 
272  bool operator ()(void) const;
275  void operator ++(void);
277 
279 
280  int min(void) const;
283  int max(void) const;
285  unsigned int width(void) const;
287  };
288 
291 
294  : n(x.val()) {}
295 
296  forceinline bool
298  return n <= Limits::max;
299  }
300  forceinline void
302  n = Limits::max+1;
303  }
304 
305  forceinline int
307  return n;
308  }
309  forceinline int
311  return n;
312  }
313  forceinline unsigned int
315  return 1;
316  }
317 
318  /*
319  * View comparison
320  *
321  */
322  forceinline bool
324  return x.min() == y.min();
325  }
326  forceinline bool
328  return !(x == y);
329  }
330 
331 }}
332 
333 // STATISTICS: int-var
334 
Post propagator for SetVar x
Definition: set.hh:767
unsigned int width(void) const
Return width of range (distance between minimum and maximum)
Post propagator for SetVar SetOpType SetVar y
Definition: set.hh:767
Constant integer view.
Definition: view.hpp:851
const Gecode::ModEvent ME_INT_FAILED
Domain operation has resulted in failure.
Definition: var-type.hpp:52
int min(void) const
Return minimum of domain.
Definition: constint.hpp:50
void init(const View &x)
Initialize with ranges for view x.
int min(void) const
Return smallest value of range.
void operator++(void)
Move iterator to next range (if possible)
bool operator<(const ConstIntView &y) const
Whether this view comes before view y (arbitray order)
Definition: constint.hpp:245
const Gecode::ModEvent ME_INT_NONE
Domain operation has not changed domain.
Definition: var-type.hpp:54
int x
Definition: view.hpp:853
ConstIntView(void)
Default constructor.
Definition: constint.hpp:41
int max(void) const
Return maximum of domain.
Definition: constint.hpp:54
ModEvent nq(Space &home, int n)
Restrict domain values to be different from n.
Definition: constint.hpp:143
bool in(int n) const
Test whether n is contained in domain.
Definition: constint.hpp:93
ModEvent narrow_r(Space &home, I &i, bool depends=true)
Replace domain by ranges described by i.
Definition: constint.hpp:168
Computation spaces.
Definition: core.hpp:1742
void update(Space &home, ConstIntView &y)
Update this view to be a clone of view y.
Definition: constint.hpp:234
bool any(const Delta &d) const
Test whether arbitrary values got pruned.
Definition: constint.hpp:223
ModEvent lq(Space &home, int n)
Restrict domain values to be less or equal than n.
Definition: constint.hpp:107
bool range(void) const
Test whether domain is a range.
Definition: constint.hpp:89
int val(void) const
Return assigned value (only if assigned)
Definition: constint.hpp:62
ModEvent le(Space &home, int n)
Restrict domain values to be less than n.
Definition: constint.hpp:116
ModEvent minus_r(Space &home, I &i, bool depends=true)
Remove from domain the ranges described by i.
Definition: constint.hpp:180
Gecode toplevel namespace
VarImp * x
Pointer to variable implementation.
Definition: var.hpp:50
Range iterator for integer views.
Definition: view.hpp:54
Generic domain change information to be supplied to advisors.
Definition: core.hpp:204
unsigned int width(void) const
Return width of domain (distance between maximum and minimum)
Definition: constint.hpp:71
ModEvent gq(Space &home, int n)
Restrict domain values to be greater or equal than n.
Definition: constint.hpp:125
ModEvent narrow_v(Space &home, I &i, bool depends=true)
Replace domain by values described by i.
Definition: constint.hpp:187
unsigned int regret_min(void) const
Return regret of domain minimum (distance to next larger value)
Definition: constint.hpp:75
ViewRanges(void)
Default constructor.
ModEvent inter_r(Space &home, I &i, bool depends=true)
Intersect domain with ranges described by i.
Definition: constint.hpp:173
void update(Space &home, ConstView &y)
Update this view to be a clone of view y.
Definition: view.hpp:461
ModEvent eq(Space &home, int n)
Restrict domain values to be equal to n.
Definition: constint.hpp:152
const int max
Largest allowed integer value.
Definition: int.hh:116
ModEvent minus_v(Space &home, I &i, bool depends=true)
Remove from domain the values described by i.
Definition: constint.hpp:199
int med(void) const
Return median of domain (greatest element not greater than the median)
Definition: constint.hpp:58
ModEvent gr(Space &home, int n)
Restrict domain values to be greater than n.
Definition: constint.hpp:134
int ModEvent
Type for modification events.
Definition: core.hpp:62
bool operator()(void) const
Test whether iterator is still at a range or done.
int max(void) const
Return largest value of range.
#define forceinline
Definition: config.hpp:185
unsigned int regret_max(void) const
Return regret of domain maximum (distance to next smaller value)
Definition: constint.hpp:79
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:234
bool operator!=(const CachedView< View > &x, const CachedView< View > &y)
Definition: cached.hpp:406
Gecode::IntArgs i({1, 2, 3, 4})
bool operator==(const CachedView< View > &x, const CachedView< View > &y)
Definition: cached.hpp:401
ModEvent inter_v(Space &home, I &i, bool depends=true)
Intersect domain with values described by i.
Definition: constint.hpp:192
unsigned int size(void) const
Return size (cardinality) of domain.
Definition: constint.hpp:67