Generated on Sat Jun 2 2018 07:17:44 for Gecode by doxygen 1.8.13
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  * 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  */
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
74  return 0;
75  }
76  forceinline unsigned int
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  */
106  return (0 <= n) ? ME_INT_NONE : ME_INT_FAILED;
107  }
109  ZeroIntView::lq(Space&, long long int n) {
110  return (0 <= n) ? ME_INT_NONE : ME_INT_FAILED;
111  }
112 
115  return (0 < n) ? ME_INT_NONE : ME_INT_FAILED;
116  }
118  ZeroIntView::le(Space&, long long int n) {
119  return (0 < n) ? ME_INT_NONE : ME_INT_FAILED;
120  }
121 
124  return (0 >= n) ? ME_INT_NONE : ME_INT_FAILED;
125  }
127  ZeroIntView::gq(Space&, long long int n) {
128  return (0 >= n) ? ME_INT_NONE : ME_INT_FAILED;
129  }
130 
133  return (0 > n) ? ME_INT_NONE : ME_INT_FAILED;
134  }
136  ZeroIntView::gr(Space&, long long int n) {
137  return (0 > n) ? ME_INT_NONE : ME_INT_FAILED;
138  }
139 
142  return (0 != n) ? ME_INT_NONE : ME_INT_FAILED;
143  }
145  ZeroIntView::nq(Space&, long long int n) {
146  return (0 != n) ? ME_INT_NONE : ME_INT_FAILED;
147  }
148 
151  return (0 == n) ? ME_INT_NONE : ME_INT_FAILED;
152  }
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>
167  return i() ? ME_INT_NONE : ME_INT_FAILED;
168  }
169  template<class I>
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>
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>
186  return i() ? ME_INT_NONE : ME_INT_FAILED;
187  }
188  template<class I>
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>
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 
229  template<>
231  private:
233  bool done;
234  public:
236 
237  ViewRanges(void);
240  ViewRanges(const ZeroIntView& x);
242  void init(const ZeroIntView& x);
244 
246 
247  bool operator ()(void) const;
250  void operator ++(void);
252 
254 
255  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 
unsigned int width(void) const
Return width of range (distance between minimum and maximum)
int min(void) const
Return minimum of domain.
Definition: zero.hpp:48
bool range(void) const
Test whether domain is a range.
Definition: zero.hpp:87
ModEvent narrow_r(Space &home, I &i, bool depends=true)
Replace domain by ranges described by i.
Definition: zero.hpp:166
ModEvent inter_r(Space &home, I &i, bool depends=true)
Intersect domain with ranges described by i.
Definition: zero.hpp:171
ModEvent gr(Space &home, int n)
Restrict domain values to be greater than n.
Definition: zero.hpp:132
int med(void) const
Return median of domain (greatest element not greater than the median)
Definition: zero.hpp:56
ViewRanges(void)
Default constructor.
int ModEvent
Type for modification events.
Definition: core.hpp:62
ModEvent le(Space &home, int n)
Restrict domain values to be less than n.
Definition: zero.hpp:114
ModEvent gq(Space &home, int n)
Restrict domain values to be greater or equal than n.
Definition: zero.hpp:123
bool any(const Delta &d) const
Test whether arbitrary values got pruned.
Definition: zero.hpp:220
#define forceinline
Definition: config.hpp:185
Computation spaces.
Definition: core.hpp:1701
ZeroIntView(void)
Default constructor.
Definition: zero.hpp:41
Range iterator for integer views.
Definition: view.hpp:54
unsigned int regret_max(void) const
Return regret of domain maximum (distance to next smaller value)
Definition: zero.hpp:77
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:401
Gecode::IntArgs i(4, 1, 2, 3, 4)
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:234
unsigned int size(void) const
Return size (cardinality) of domain.
Definition: zero.hpp:65
ModEvent nq(Space &home, int n)
Restrict domain values to be different from n.
Definition: zero.hpp:141
int min(void) const
Return smallest value of range.
int max(void) const
Return maximum of domain.
Definition: zero.hpp:52
ModEvent minus_r(Space &home, I &i, bool depends=true)
Remove from domain the ranges described by i.
Definition: zero.hpp:178
Zero integer view.
Definition: view.hpp:985
ModEvent eq(Space &home, int n)
Restrict domain values to be equal to n.
Definition: zero.hpp:150
Generic domain change information to be supplied to advisors.
Definition: core.hpp:203
unsigned int regret_min(void) const
Return regret of domain minimum (distance to next larger value)
Definition: zero.hpp:73
bool operator()(void) const
Test whether iterator is still at a range or done.
unsigned int width(void) const
Return width of domain (distance between maximum and minimum)
Definition: zero.hpp:69
void operator++(void)
Move iterator to next range (if possible)
int max(void) const
Return largest value of range.
Post propagator for SetVar x
Definition: set.hh:765
ModEvent lq(Space &home, int n)
Restrict domain values to be less or equal than n.
Definition: zero.hpp:105
ModEvent inter_v(Space &home, I &i, bool depends=true)
Intersect domain with values described by i.
Definition: zero.hpp:190
bool in(int n) const
Test whether n is contained in domain.
Definition: zero.hpp:91
Gecode toplevel namespace
ModEvent minus_v(Space &home, I &i, bool depends=true)
Remove from domain the values described by i.
Definition: zero.hpp:197
const Gecode::ModEvent ME_INT_NONE
Domain operation has not changed domain.
Definition: var-type.hpp:54
int val(void) const
Return assigned value (only if assigned)
Definition: zero.hpp:60
ModEvent narrow_v(Space &home, I &i, bool depends=true)
Replace domain by values described by i.
Definition: zero.hpp:185