Generated on Sun Aug 9 2020 05:34:08 for Gecode by doxygen 1.8.18
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  * Contributing authors:
7  * Samuel Gagnon <samuel.gagnon92@gmail.com>
8  *
9  * Copyright:
10  * Christian Schulte, 2003
11  * Samuel Gagnon, 2018
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 #ifdef GECODE_HAS_CBS
68  forceinline int
69  MinusView::baseval(int val) const {
70  return -val;
71  }
72 #endif
73 
74  forceinline unsigned int
75  MinusView::width(void) const {
76  return x.width();
77  }
78  forceinline unsigned int
79  MinusView::size(void) const {
80  return x.size();
81  }
82  forceinline unsigned int
83  MinusView::regret_min(void) const {
84  return x.regret_max();
85  }
86  forceinline unsigned int
87  MinusView::regret_max(void) const {
88  return x.regret_min();
89  }
90 
91 
92  /*
93  * Domain tests
94  *
95  */
96  forceinline bool
97  MinusView::range(void) const {
98  return x.range();
99  }
100  forceinline bool
101  MinusView::in(int n) const {
102  return x.in(-n);
103  }
104  forceinline bool
105  MinusView::in(long long int n) const {
106  return x.in(-n);
107  }
108 
109 
110  /*
111  * Domain update by value
112  *
113  */
115  MinusView::lq(Space& home, int n) {
116  return x.gq(home,-n);
117  }
119  MinusView::lq(Space& home, long long int n) {
120  return x.gq(home,-n);
121  }
122 
124  MinusView::le(Space& home, int n) {
125  return x.gr(home,-n);
126  }
128  MinusView::le(Space& home, long long int n) {
129  return x.gr(home,-n);
130  }
131 
133  MinusView::gq(Space& home, int n) {
134  return x.lq(home,-n);
135  }
137  MinusView::gq(Space& home, long long int n) {
138  return x.lq(home,-n);
139  }
140 
142  MinusView::gr(Space& home, int n) {
143  return x.le(home,-n);
144  }
146  MinusView::gr(Space& home, long long int n) {
147  return x.le(home,-n);
148  }
149 
151  MinusView::nq(Space& home, int n) {
152  return x.nq(home,-n);
153  }
155  MinusView::nq(Space& home, long long int n) {
156  return x.nq(home,-n);
157  }
158 
160  MinusView::eq(Space& home, int n) {
161  return x.eq(home,-n);
162  }
164  MinusView::eq(Space& home, long long int n) {
165  return x.eq(home,-n);
166  }
167 
168 
169  /*
170  * Iterator-based domain update
171  *
172  */
173  template<class I>
175  MinusView::narrow_r(Space& home, I& i, bool) {
176  Region r;
177  Iter::Ranges::Minus mi(r,i);
178  return x.narrow_r(home,mi,false);
179  }
180  template<class I>
182  MinusView::inter_r(Space& home, I& i, bool) {
183  Region r;
184  Iter::Ranges::Minus mi(r,i);
185  return x.inter_r(home,mi,false);
186  }
187  template<class I>
189  MinusView::minus_r(Space& home, I& i, bool) {
190  Region r;
191  Iter::Ranges::Minus mi(r,i);
192  return x.minus_r(home,mi,false);
193  }
194  template<class I>
196  MinusView::narrow_v(Space& home, I& i, bool) {
197  Region r;
198  Iter::Values::Minus mi(r,i);
199  return x.narrow_v(home,mi,false);
200  }
201  template<class I>
203  MinusView::inter_v(Space& home, I& i, bool) {
204  Region r;
205  Iter::Values::Minus mi(r,i);
206  return x.inter_v(home,mi,false);
207  }
208  template<class I>
210  MinusView::minus_v(Space& home, I& i, bool) {
211  Region r;
212  Iter::Values::Minus mi(r,i);
213  return x.minus_v(home,mi,false);
214  }
215 
216 
217  /*
218  * Propagator modification events
219  *
220  */
223  return IntView::med(me);
224  }
225 
226 
227  /*
228  * Delta information for advisors
229  *
230  */
231  forceinline int
232  MinusView::min(const Delta& d) const {
233  return -x.max(d);
234  }
235  forceinline int
236  MinusView::max(const Delta& d) const {
237  return -x.min(d);
238  }
239  forceinline unsigned int
240  MinusView::width(const Delta& d) const {
241  return x.width(d);
242  }
243  forceinline bool
244  MinusView::any(const Delta& d) const {
245  return x.any(d);
246  }
247 
248 
253  template<>
255  public:
257 
258  ViewRanges(void);
261  ViewRanges(const MinusView& x);
263  void init(const MinusView& x);
265 
267 
268  int min(void) const;
271  int max(void) const;
273  };
274 
277 
280  : IntVarImpBwd(x.base().varimp()) {}
281 
282  forceinline void
284  IntVarImpBwd::init(x.base().varimp());
285  }
286 
287  forceinline int
289  return -IntVarImpBwd::max();
290  }
291  forceinline int
293  return -IntVarImpBwd::min();
294  }
295 
296  inline int
297  MinusView::med(void) const {
298  if (x.range())
299  return (min()+max())/2 - ((min()+max())%2 < 0 ? 1 : 0);
300 
301  unsigned int i = x.size() / 2;
302  if (size() % 2 == 0)
303  i--;
304  ViewRanges<MinusView> r(*this);
305  while (i >= r.width()) {
306  i -= r.width();
307  ++r;
308  }
309  return r.min() + static_cast<int>(i);
310  }
311 
312  /*
313  * View comparison
314  *
315  */
316  forceinline bool
317  operator ==(const MinusView& x, const MinusView& y) {
318  return x.base() == y.base();
319  }
320  forceinline bool
321  operator !=(const MinusView& x, const MinusView& y) {
322  return !(x == y);
323  }
324 
325 }}
326 
327 // STATISTICS: int-var
328 
Post propagator for SetVar x
Definition: set.hh:767
Post propagator for SetVar SetOpType SetVar y
Definition: set.hh:767
int max(void) const
Return maximum of domain.
Definition: minus.hpp:60
MinusView(void)
Default constructor.
Definition: minus.hpp:45
ModEvent narrow_v(Space &home, I &i, bool depends=true)
Replace domain by values described by i.
Definition: minus.hpp:196
ModEvent inter_v(Space &home, I &i, bool depends=true)
Intersect domain with values described by i.
Definition: minus.hpp:203
void init(const View &x)
Initialize with ranges for view x.
int min(void) const
Return minimum of domain.
Definition: int.hpp:58
int min(void) const
Return smallest value of range.
Minus integer view.
Definition: view.hpp:282
Backward iterator for ranges of integer variable implementations.
Definition: var-imp.hpp:435
ModEvent narrow_r(Space &home, I &i, bool depends=true)
Replace domain by ranges described by i.
Definition: minus.hpp:175
ModEvent minus_v(Space &home, I &i, bool depends=true)
Remove from domain the values described by i.
Definition: int.hpp:206
Computation spaces.
Definition: core.hpp:1742
Value iterator for pointwise minus of a value iterator.
unsigned int regret_min(void) const
Return regret of domain minimum (distance to next larger value)
Definition: minus.hpp:83
unsigned int size(void) const
Return size (cardinality) of domain.
Definition: minus.hpp:79
Base-class for derived views.
Definition: view.hpp:230
Gecode toplevel namespace
void init(const IntVarImp *x)
Initialize with ranges from variable implementation x.
Definition: int.hpp:470
int max(void) const
Return maximum of domain.
Definition: int.hpp:62
Range iterator for integer views.
Definition: view.hpp:54
ModEvent inter_r(Space &home, I &i, bool depends=true)
Intersect domain with ranges described by i.
Definition: int.hpp:186
ModEvent inter_r(Space &home, I &i, bool depends=true)
Intersect domain with ranges described by i.
Definition: minus.hpp:182
int val(void) const
Return assigned value (only if assigned)
Definition: int.hpp:70
unsigned int width(void) const
Return width of domain (distance between maximum and minimum)
Definition: minus.hpp:75
Generic domain change information to be supplied to advisors.
Definition: core.hpp:204
VarImp * varimp(void) const
Return variable implementation of variable.
Definition: var.hpp:96
unsigned int size(void) const
Return size (cardinality) of domain.
Definition: int.hpp:81
ModEvent nq(Space &home, int n)
Restrict domain values to be different from n.
Definition: minus.hpp:151
ModEvent minus_r(Space &home, I &i, bool depends=true)
Remove from domain the ranges described by i.
Definition: minus.hpp:189
Handle to region.
Definition: region.hpp:55
ModEvent inter_v(Space &home, I &i, bool depends=true)
Intersect domain with values described by i.
Definition: int.hpp:201
unsigned int regret_min(void) const
Return regret of domain minimum (distance to next larger value)
Definition: int.hpp:89
bool range(void) const
Test whether domain is a range.
Definition: minus.hpp:97
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition: set.hh:767
ViewRanges(void)
Default constructor.
ModEvent nq(Space &home, int n)
Restrict domain values to be different from n.
Definition: int.hpp:157
Range iterator for pointwise minus of a range iterator.
ModEvent minus_v(Space &home, I &i, bool depends=true)
Remove from domain the values described by i.
Definition: minus.hpp:210
const double base
Base for geometric restart sequence.
Definition: search.hh:126
unsigned int regret_max(void) const
Return regret of domain maximum (distance to next smaller value)
Definition: int.hpp:93
bool in(int n) const
Test whether n is contained in domain.
Definition: minus.hpp:101
ModEvent le(Space &home, int n)
Restrict domain values to be less than n.
Definition: minus.hpp:124
bool in(int n) const
Test whether n is contained in domain.
Definition: int.hpp:107
int ModEvent
Type for modification events.
Definition: core.hpp:62
ModEvent eq(Space &home, int n)
Restrict domain values to be equal to n.
Definition: minus.hpp:160
static ModEvent me(const ModEventDelta &med)
Return modification event for view type in med.
Definition: view.hpp:639
int max(void) const
Return largest value of range.
Definition: int.hpp:488
IntView x
View from which this view is derived.
Definition: view.hpp:238
bool any(const Delta &d) const
Test whether arbitrary values got pruned.
Definition: minus.hpp:244
ModEvent narrow_r(Space &home, I &i, bool depends=true)
Replace domain by ranges described by i.
Definition: int.hpp:181
Gecode::IntSet d(v, 7)
ModEvent gr(Space &home, int n)
Restrict domain values to be greater than n.
Definition: int.hpp:148
int val(void) const
Return assigned value (only if assigned)
Definition: minus.hpp:64
Integer view for integer variables.
Definition: view.hpp:129
int max(void) const
Return largest value of range.
unsigned int width(void) const
Return width of domain (distance between maximum and minimum)
Definition: int.hpp:85
#define forceinline
Definition: config.hpp:185
ModEvent gq(Space &home, int n)
Restrict domain values to be greater or equal than n.
Definition: minus.hpp:133
ModEvent gr(Space &home, int n)
Restrict domain values to be greater than n.
Definition: minus.hpp:142
ModEvent lq(Space &home, int n)
Restrict domain values to be less or equal than n.
Definition: int.hpp:121
int min(void) const
Return minimum of domain.
Definition: minus.hpp:56
ModEvent narrow_v(Space &home, I &i, bool depends=true)
Replace domain by values described by i.
Definition: int.hpp:196
ModEvent gq(Space &home, int n)
Restrict domain values to be greater or equal than n.
Definition: int.hpp:139
int med(void) const
Return median of domain.
Definition: minus.hpp:297
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:234
Range iterator for minus integer views
Definition: minus.hpp:254
int med(void) const
Return median of domain (greatest element not greater than the median)
Definition: int.hpp:66
ModEvent minus_r(Space &home, I &i, bool depends=true)
Remove from domain the ranges described by i.
Definition: int.hpp:191
int ModEventDelta
Modification event deltas.
Definition: core.hpp:89
bool operator!=(const CachedView< View > &x, const CachedView< View > &y)
Definition: cached.hpp:406
bool any(const Delta &d) const
Test whether arbitrary values got pruned.
Definition: int.hpp:230
Gecode::IntArgs i({1, 2, 3, 4})
int min(void) const
Return smallest value of range.
Definition: int.hpp:484
bool range(void) const
Test whether domain is a range.
Definition: int.hpp:103
bool operator==(const CachedView< View > &x, const CachedView< View > &y)
Definition: cached.hpp:401
ModEvent le(Space &home, int n)
Restrict domain values to be less than n.
Definition: int.hpp:130
unsigned int regret_max(void) const
Return regret of domain maximum (distance to next smaller value)
Definition: minus.hpp:87
ModEvent eq(Space &home, int n)
Restrict domain values to be equal to n.
Definition: int.hpp:166
ModEvent lq(Space &home, int n)
Restrict domain values to be less or equal than n.
Definition: minus.hpp:115