Generated on Sat Feb 7 2015 02:01:18 for Gecode by doxygen 1.8.9.1
minus.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  : DerivedView<IntView>(y) {}
49 
50 
51  /*
52  * Value access
53  *
54  */
55  forceinline int
56  MinusView::min(void) const {
57  return -x.max();
58  }
59  forceinline int
60  MinusView::max(void) const {
61  return -x.min();
62  }
63  forceinline int
64  MinusView::val(void) const {
65  return -x.val();
66  }
67 
68  forceinline unsigned int
69  MinusView::width(void) const {
70  return x.width();
71  }
72  forceinline unsigned int
73  MinusView::size(void) const {
74  return x.size();
75  }
76  forceinline unsigned int
77  MinusView::regret_min(void) const {
78  return x.regret_max();
79  }
80  forceinline unsigned int
81  MinusView::regret_max(void) const {
82  return x.regret_min();
83  }
84 
85 
86  /*
87  * Domain tests
88  *
89  */
90  forceinline bool
91  MinusView::range(void) const {
92  return x.range();
93  }
94  forceinline bool
95  MinusView::in(int n) const {
96  return x.in(-n);
97  }
98  forceinline bool
99  MinusView::in(long long int n) const {
100  return x.in(-n);
101  }
102 
103 
104  /*
105  * Domain update by value
106  *
107  */
109  MinusView::lq(Space& home, int n) {
110  return x.gq(home,-n);
111  }
113  MinusView::lq(Space& home, long long int n) {
114  return x.gq(home,-n);
115  }
116 
118  MinusView::le(Space& home, int n) {
119  return x.gr(home,-n);
120  }
122  MinusView::le(Space& home, long long int n) {
123  return x.gr(home,-n);
124  }
125 
127  MinusView::gq(Space& home, int n) {
128  return x.lq(home,-n);
129  }
131  MinusView::gq(Space& home, long long int n) {
132  return x.lq(home,-n);
133  }
134 
136  MinusView::gr(Space& home, int n) {
137  return x.le(home,-n);
138  }
140  MinusView::gr(Space& home, long long int n) {
141  return x.le(home,-n);
142  }
143 
145  MinusView::nq(Space& home, int n) {
146  return x.nq(home,-n);
147  }
149  MinusView::nq(Space& home, long long int n) {
150  return x.nq(home,-n);
151  }
152 
154  MinusView::eq(Space& home, int n) {
155  return x.eq(home,-n);
156  }
158  MinusView::eq(Space& home, long long int n) {
159  return x.eq(home,-n);
160  }
161 
162 
163  /*
164  * Iterator-based domain update
165  *
166  */
167  template<class I>
169  MinusView::narrow_r(Space& home, I& i, bool) {
170  Region r(home);
171  Iter::Ranges::Minus mi(r,i);
172  return x.narrow_r(home,mi,false);
173  }
174  template<class I>
176  MinusView::inter_r(Space& home, I& i, bool) {
177  Region r(home);
178  Iter::Ranges::Minus mi(r,i);
179  return x.inter_r(home,mi,false);
180  }
181  template<class I>
183  MinusView::minus_r(Space& home, I& i, bool) {
184  Region r(home);
185  Iter::Ranges::Minus mi(r,i);
186  return x.minus_r(home,mi,false);
187  }
188  template<class I>
190  MinusView::narrow_v(Space& home, I& i, bool) {
191  Region r(home);
192  Iter::Values::Minus mi(r,i);
193  return x.narrow_v(home,mi,false);
194  }
195  template<class I>
197  MinusView::inter_v(Space& home, I& i, bool) {
198  Region r(home);
199  Iter::Values::Minus mi(r,i);
200  return x.inter_v(home,mi,false);
201  }
202  template<class I>
204  MinusView::minus_v(Space& home, I& i, bool) {
205  Region r(home);
206  Iter::Values::Minus mi(r,i);
207  return x.minus_v(home,mi,false);
208  }
209 
210 
211  /*
212  * Propagator modification events
213  *
214  */
217  return IntView::med(me);
218  }
219 
220 
221  /*
222  * Delta information for advisors
223  *
224  */
225  forceinline int
226  MinusView::min(const Delta& d) const {
227  return -x.max(d);
228  }
229  forceinline int
230  MinusView::max(const Delta& d) const {
231  return -x.min(d);
232  }
233  forceinline bool
234  MinusView::any(const Delta& d) const {
235  return x.any(d);
236  }
237 
238 
243  template<>
245  public:
247 
248  ViewRanges(void);
251  ViewRanges(const MinusView& x);
253  void init(const MinusView& x);
255 
257 
258  int min(void) const;
261  int max(void) const;
263  };
264 
267 
270  : IntVarImpBwd(x.base().varimp()) {}
271 
272  forceinline void
275  }
276 
277  forceinline int
279  return -IntVarImpBwd::max();
280  }
281  forceinline int
283  return -IntVarImpBwd::min();
284  }
285 
286  inline int
287  MinusView::med(void) const {
288  if (x.range())
289  return (min()+max())/2 - ((min()+max())%2 < 0 ? 1 : 0);
290 
291  unsigned int i = x.size() / 2;
292  if (size() % 2 == 0)
293  i--;
294  ViewRanges<MinusView> r(*this);
295  while (i >= r.width()) {
296  i -= r.width();
297  ++r;
298  }
299  return r.min() + static_cast<int>(i);
300  }
301 
302 }}
303 
304 // STATISTICS: int-var
305 
int val(void) const
Return assigned value (only if assigned)
Definition: int.hpp:70
ModEvent inter_v(Space &home, I &i, bool depends=true)
Intersect domain with values described by i.
Definition: minus.hpp:197
ModEvent inter_r(Space &home, I &i, bool depends=true)
Intersect domain with ranges described by i.
Definition: int.hpp:180
ModEvent nq(Space &home, int n)
Restrict domain values to be different from n.
Definition: int.hpp:151
ModEvent gr(Space &home, int n)
Restrict domain values to be greater than n.
Definition: int.hpp:142
VarImpType * varimp(void) const
Return variable implementation of view.
Definition: view.hpp:433
ModEvent eq(Space &home, int n)
Restrict domain values to be equal to n.
Definition: int.hpp:160
int min(void) const
Return smallest value of range.
Definition: int.hpp:484
ViewRanges(void)
Default constructor.
int ModEvent
Type for modification events.
Definition: core.hpp:146
ModEvent nq(Space &home, int n)
Restrict domain values to be different from n.
Definition: minus.hpp:145
unsigned int regret_max(void) const
Return regret of domain maximum (distance to next smaller value)
Definition: int.hpp:87
Handle to region.
Definition: region.hpp:61
ModEvent narrow_r(Space &home, I &i, bool depends=true)
Replace domain by ranges described by i.
Definition: int.hpp:175
int min(void) const
Return smallest value of range.
Definition: minus.hpp:278
bool in(int n) const
Test whether n is contained in domain.
Definition: minus.hpp:95
ModEvent minus_r(Space &home, I &i, bool depends=true)
Remove from domain the ranges described by i.
Definition: int.hpp:185
Computation spaces.
Definition: core.hpp:1362
void init(const View &x)
Initialize with ranges for view x.
Value iterator for pointwise minus of a value iterator.
int val(void) const
Return assigned value (only if assigned)
Definition: minus.hpp:64
Base-class for derived views.
Definition: view.hpp:208
void init(const IntVarImp *x)
Initialize with ranges from variable implementation x.
Definition: int.hpp:470
unsigned int size(void) const
Return size (cardinality) of domain.
Definition: minus.hpp:73
ModEvent minus_v(Space &home, I &i, bool depends=true)
Remove from domain the values described by i.
Definition: int.hpp:200
ModEvent narrow_r(Space &home, I &i, bool depends=true)
Replace domain by ranges described by i.
Definition: minus.hpp:169
Range iterator for integer views.
Definition: view.hpp:54
unsigned int regret_min(void) const
Return regret of domain minimum (distance to next larger value)
Definition: minus.hpp:77
Gecode::IntSet d(v, 7)
bool any(const Delta &d) const
Test whether arbitrary values got pruned.
Definition: minus.hpp:234
int max(void) const
Return maximum of domain.
Definition: int.hpp:62
ModEvent eq(Space &home, int n)
Restrict domain values to be equal to n.
Definition: minus.hpp:154
ModEvent le(Space &home, int n)
Restrict domain values to be less than n.
Definition: int.hpp:124
int min(void) const
Return smallest value of range.
ModEvent narrow_v(Space &home, I &i, bool depends=true)
Replace domain by values described by i.
Definition: minus.hpp:190
Gecode::IntArgs i(4, 1, 2, 3, 4)
bool in(int n) const
Test whether n is contained in domain.
Definition: int.hpp:101
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
unsigned int regret_min(void) const
Return regret of domain minimum (distance to next larger value)
Definition: int.hpp:83
ModEvent narrow_v(Space &home, I &i, bool depends=true)
Replace domain by values described by i.
Definition: int.hpp:190
ModEvent inter_r(Space &home, I &i, bool depends=true)
Intersect domain with ranges described by i.
Definition: minus.hpp:176
int max(void) const
Return maximum of domain.
Definition: minus.hpp:60
ModEvent lq(Space &home, int n)
Restrict domain values to be less or equal than n.
Definition: int.hpp:115
NNF * r
Right subtree.
Definition: bool-expr.cpp:246
View base(void) const
Return view from which this view is derived.
Definition: view.hpp:526
unsigned int size(void) const
Return size (cardinality) of domain.
Definition: int.hpp:75
ModEvent minus_v(Space &home, I &i, bool depends=true)
Remove from domain the values described by i.
Definition: minus.hpp:204
int min(void) const
Return minimum of domain.
Definition: int.hpp:58
Backward iterator for ranges of integer variable implementations.
Definition: var-imp.hpp:430
bool any(const Delta &d) const
Test whether arbitrary values got pruned.
Definition: int.hpp:220
unsigned int regret_max(void) const
Return regret of domain maximum (distance to next smaller value)
Definition: minus.hpp:81
Range iterator for pointwise minus of a range iterator.
ModEvent inter_v(Space &home, I &i, bool depends=true)
Intersect domain with values described by i.
Definition: int.hpp:195
Integer view for integer variables.
Definition: view.hpp:129
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
Minus integer view.
Definition: view.hpp:276
unsigned int width(void) const
Return width of domain (distance between maximum and minimum)
Definition: int.hpp:79
#define forceinline
Definition: config.hpp:132
ModEvent gr(Space &home, int n)
Restrict domain values to be greater than n.
Definition: minus.hpp:136
ModEvent minus_r(Space &home, I &i, bool depends=true)
Remove from domain the ranges described by i.
Definition: minus.hpp:183
unsigned int width(void) const
Return width of range (distance between minimum and maximum)
Definition: int.hpp:492
ModEvent gq(Space &home, int n)
Restrict domain values to be greater or equal than n.
Definition: int.hpp:133
int med(void) const
Return median of domain (greatest element not greater than the median)
Definition: int.hpp:66
bool range(void) const
Test whether domain is a range.
Definition: int.hpp:97
int med(void) const
Return median of domain.
Definition: minus.hpp:287
IntView x
View from which this view is derived.
Definition: view.hpp:216
bool range(void) const
Test whether domain is a range.
Definition: minus.hpp:91
int min(void) const
Return minimum of domain.
Definition: minus.hpp:56
ModEvent le(Space &home, int n)
Restrict domain values to be less than n.
Definition: minus.hpp:118
int max(void) const
Return largest value of range.
Gecode toplevel namespace
ModEvent lq(Space &home, int n)
Restrict domain values to be less or equal than n.
Definition: minus.hpp:109
int max(void) const
Return largest value of range.
Definition: int.hpp:488
int ModEventDelta
Modification event deltas.
Definition: core.hpp:173
ModEvent gq(Space &home, int n)
Restrict domain values to be greater or equal than n.
Definition: minus.hpp:127
unsigned int width(void) const
Return width of domain (distance between maximum and minimum)
Definition: minus.hpp:69
Range iterator for minus integer views
Definition: minus.hpp:244
MinusView(void)
Default constructor.
Definition: minus.hpp:45