Generated on Sat Feb 7 2015 02:01:26 for Gecode by doxygen 1.8.9.1
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: 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  */
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(long long int 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&, long long int 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&, long long int 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&, long long int 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&, long long int 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&, long long int 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&, long long int 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  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 
bool any(const Delta &d) const
Test whether arbitrary values got pruned.
Definition: zero.hpp:220
ModEvent narrow_r(Space &home, I &i, bool depends=true)
Replace domain by ranges described by i.
Definition: zero.hpp:170
bool range(void) const
Test whether domain is a range.
Definition: zero.hpp:91
ModEvent inter_r(Space &home, I &i, bool depends=true)
Intersect domain with ranges described by i.
Definition: zero.hpp:175
ModEvent gr(Space &home, int n)
Restrict domain values to be greater than n.
Definition: zero.hpp:136
ViewRanges(void)
Default constructor.
bool operator()(void) const
Test whether iterator is still at a range or done.
int ModEvent
Type for modification events.
Definition: core.hpp:146
ModEvent le(Space &home, int n)
Restrict domain values to be less than n.
Definition: zero.hpp:118
ModEvent gq(Space &home, int n)
Restrict domain values to be greater or equal than n.
Definition: zero.hpp:127
Computation spaces.
Definition: core.hpp:1362
void init(const View &x)
Initialize with ranges for view x.
ZeroIntView(void)
Default constructor.
Definition: zero.hpp:45
Range iterator for integer views.
Definition: view.hpp:54
bool in(int n) const
Test whether n is contained in domain.
Definition: zero.hpp:95
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 med(void) const
Return median of domain (greatest element not greater than the median)
Definition: zero.hpp:60
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
ModEvent nq(Space &home, int n)
Restrict domain values to be different from n.
Definition: zero.hpp:145
unsigned int size(void) const
Return size (cardinality) of domain.
Definition: zero.hpp:69
int val(void) const
Return assigned value (only if assigned)
Definition: zero.hpp:64
int max(void) const
Return maximum of domain.
Definition: zero.hpp:56
ModEvent minus_r(Space &home, I &i, bool depends=true)
Remove from domain the ranges described by i.
Definition: zero.hpp:182
unsigned int width(void) const
Return width of range (distance between minimum and maximum)
Zero integer view.
Definition: view.hpp:959
ModEvent eq(Space &home, int n)
Restrict domain values to be equal to n.
Definition: zero.hpp:154
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
unsigned int regret_min(void) const
Return regret of domain minimum (distance to next larger value)
Definition: zero.hpp:77
#define forceinline
Definition: config.hpp:132
void operator++(void)
Move iterator to next range (if possible)
unsigned int regret_max(void) const
Return regret of domain maximum (distance to next smaller value)
Definition: zero.hpp:81
int min(void) const
Return minimum of domain.
Definition: zero.hpp:52
ModEvent lq(Space &home, int n)
Restrict domain values to be less or equal than n.
Definition: zero.hpp:109
ModEvent inter_v(Space &home, I &i, bool depends=true)
Intersect domain with values described by i.
Definition: zero.hpp:194
int max(void) const
Return largest value of range.
Gecode toplevel namespace
ModEvent minus_v(Space &home, I &i, bool depends=true)
Remove from domain the values described by i.
Definition: zero.hpp:201
unsigned int width(void) const
Return width of domain (distance between maximum and minimum)
Definition: zero.hpp:73
const Gecode::ModEvent ME_INT_NONE
Domain operation has not changed domain.
Definition: var-type.hpp:54
ModEvent narrow_v(Space &home, I &i, bool depends=true)
Replace domain by values described by i.
Definition: zero.hpp:189