Generated on Sat Feb 7 2015 02:01:18 for Gecode by doxygen 1.8.9.1
offset.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, 2002
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), c(d) {}
49 
50 
51  /*
52  * Value access
53  *
54  */
55  forceinline int
56  OffsetView::offset(void) const {
57  return c;
58  }
59  forceinline void
61  c = n;
62  }
63  forceinline int
64  OffsetView::min(void) const {
65  return x.min()+c;
66  }
67  forceinline int
68  OffsetView::max(void) const {
69  return x.max()+c;
70  }
71  forceinline int
72  OffsetView::med(void) const {
73  return x.med()+c;
74  }
75  forceinline int
76  OffsetView::val(void) const {
77  return x.val()+c;
78  }
79 
80  forceinline unsigned int
81  OffsetView::width(void) const {
82  return x.width();
83  }
84  forceinline unsigned int
85  OffsetView::size(void) const {
86  return x.size();
87  }
88  forceinline unsigned int
89  OffsetView::regret_min(void) const {
90  return x.regret_min();
91  }
92  forceinline unsigned int
93  OffsetView::regret_max(void) const {
94  return x.regret_max();
95  }
96 
97  /*
98  * Domain tests
99  *
100  */
101  forceinline bool
102  OffsetView::range(void) const {
103  return x.range();
104  }
105  forceinline bool
106  OffsetView::in(int n) const {
107  return x.in(n-c);
108  }
109  forceinline bool
110  OffsetView::in(long long int n) const {
111  return x.in(n-c);
112  }
113 
114 
115 
116  /*
117  * Domain update by value
118  *
119  */
121  OffsetView::lq(Space& home, int n) {
122  return x.lq(home,n-c);
123  }
125  OffsetView::lq(Space& home, long long int n) {
126  return x.lq(home,n-c);
127  }
128 
130  OffsetView::le(Space& home, int n) {
131  return x.le(home,n-c);
132  }
134  OffsetView::le(Space& home, long long int n) {
135  return x.le(home,n-c);
136  }
137 
139  OffsetView::gq(Space& home, int n) {
140  return x.gq(home,n-c);
141  }
143  OffsetView::gq(Space& home, long long int n) {
144  return x.gq(home,n-c);
145  }
146 
148  OffsetView::gr(Space& home, int n) {
149  return x.gr(home,n-c);
150  }
152  OffsetView::gr(Space& home, long long int n) {
153  return x.gr(home,n-c);
154  }
155 
157  OffsetView::nq(Space& home, int n) {
158  return x.nq(home,n-c);
159  }
161  OffsetView::nq(Space& home, long long int n) {
162  return x.nq(home,n-c);
163  }
164 
166  OffsetView::eq(Space& home, int n) {
167  return x.eq(home,n-c);
168  }
170  OffsetView::eq(Space& home, long long int n) {
171  return x.eq(home,n-c);
172  }
173 
174 
175  /*
176  * Iterator-based domain update
177  *
178  */
179  template<class I>
181  OffsetView::narrow_r(Space& home, I& i, bool depend) {
182  Iter::Ranges::Offset<I> oi(i,-c);
183  return x.narrow_r(home,oi,depend);
184  }
185  template<class I>
187  OffsetView::inter_r(Space& home, I& i, bool depend) {
188  Iter::Ranges::Offset<I> oi(i,-c);
189  return x.inter_r(home,oi,depend);
190  }
191  template<class I>
193  OffsetView::minus_r(Space& home, I& i, bool depend) {
194  Iter::Ranges::Offset<I> oi(i,-c);
195  return x.minus_r(home,oi,depend);
196  }
197  template<class I>
199  OffsetView::narrow_v(Space& home, I& i, bool depend) {
200  Iter::Values::Offset<I> oi(i,-c);
201  return x.narrow_v(home,oi,depend);
202  }
203  template<class I>
205  OffsetView::inter_v(Space& home, I& i, bool depend) {
206  Iter::Values::Offset<I> oi(i,-c);
207  return x.inter_v(home,oi,depend);
208  }
209  template<class I>
211  OffsetView::minus_v(Space& home, I& i, bool depend) {
212  Iter::Values::Offset<I> oi(i,-c);
213  return x.minus_v(home,oi,depend);
214  }
215 
216 
217 
218  /*
219  * Propagator modification events
220  *
221  */
224  return IntView::med(me);
225  }
226 
227 
228  /*
229  * Delta information for advisors
230  *
231  */
232  forceinline int
233  OffsetView::min(const Delta& d) const {
234  return x.min(d)+c;
235  }
236  forceinline int
237  OffsetView::max(const Delta& d) const {
238  return x.max(d)+c;
239  }
240  forceinline bool
241  OffsetView::any(const Delta& d) const {
242  return x.any(d);
243  }
244 
245 
246 
247  /*
248  * Cloning
249  *
250  */
251  forceinline void
252  OffsetView::update(Space& home, bool share, OffsetView& y) {
253  DerivedView<IntView>::update(home,share,y);
254  c=y.c;
255  }
256 
257 
262  template<>
264  : public Iter::Ranges::Offset<ViewRanges<IntView> > {
265  public:
267 
268  ViewRanges(void);
271  ViewRanges(const OffsetView& x);
273  void init(const OffsetView& x);
275  };
276 
279 
282  ViewRanges<IntView> xi(x.base());
284  }
285 
286  forceinline void
288  ViewRanges<IntView> xi(x.base());
290  }
291 
292  /*
293  * View comparison
294  *
295  */
296  forceinline bool
297  same(const OffsetView& x, const OffsetView& y) {
298  return same(x.base(),y.base()) && (x.offset() == y.offset());
299  }
300  forceinline bool
301  before(const OffsetView& x, const OffsetView& y) {
302  return before(x.base(),y.base())
303  || (same(x.base(),y.base()) && (x.offset() < y.offset()));
304  }
305 
306 }}
307 
308 // STATISTICS: int-var
309 
int val(void) const
Return assigned value (only if assigned)
Definition: int.hpp:70
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
unsigned int regret_min(void) const
Return regret of domain minimum (distance to next larger value)
Definition: offset.hpp:89
ModEvent gr(Space &home, int n)
Restrict domain values to be greater than n.
Definition: offset.hpp:148
unsigned int width(void) const
Return width of domain (distance between maximum and minimum)
Definition: offset.hpp:81
ModEvent nq(Space &home, int n)
Restrict domain values to be different from n.
Definition: offset.hpp:157
ModEvent eq(Space &home, int n)
Restrict domain values to be equal to n.
Definition: int.hpp:160
bool before(const CachedView< View > &x, const CachedView< View > &y)
Definition: cached.hpp:394
unsigned int regret_max(void) const
Return regret of domain maximum (distance to next smaller value)
Definition: offset.hpp:93
ViewRanges(void)
Default constructor.
ModEvent eq(Space &home, int n)
Restrict domain values to be equal to n.
Definition: offset.hpp:166
int ModEvent
Type for modification events.
Definition: core.hpp:146
Range iterator for integer variable views
Definition: int.hpp:236
int val(void) const
Return assigned value (only if assigned)
Definition: offset.hpp:76
unsigned int regret_max(void) const
Return regret of domain maximum (distance to next smaller value)
Definition: int.hpp:87
ModEvent narrow_r(Space &home, I &i, bool depends=true)
Replace domain by ranges described by i.
Definition: int.hpp:175
ModEvent minus_r(Space &home, I &i, bool depends=true)
Remove from domain the ranges described by i.
Definition: int.hpp:185
int min(void) const
Return minimum of domain.
Definition: offset.hpp:64
Computation spaces.
Definition: core.hpp:1362
void init(const View &x)
Initialize with ranges for view x.
Base-class for derived views.
Definition: view.hpp:208
ModEvent minus_v(Space &home, I &i, bool depends=true)
Remove from domain the values described by i.
Definition: int.hpp:200
Range iterator for integer views.
Definition: view.hpp:54
ModEvent minus_r(Space &home, I &i, bool depends=true)
Remove from domain the ranges described by i.
Definition: offset.hpp:193
Gecode::IntSet d(v, 7)
int max(void) const
Return maximum of domain.
Definition: int.hpp:62
bool in(int n) const
Test whether n is contained in domain.
Definition: offset.hpp:106
bool same(const CachedView< View > &x, const CachedView< View > &y)
Definition: cached.hpp:389
Gecode::FloatVal c(-8, 8)
ModEvent le(Space &home, int n)
Restrict domain values to be less than n.
Definition: int.hpp:124
ModEvent le(Space &home, int n)
Restrict domain values to be less than n.
Definition: offset.hpp:130
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 gq(Space &home, int n)
Restrict domain values to be greater or equal than n.
Definition: offset.hpp:139
int max(void) const
Return maximum of domain.
Definition: offset.hpp:68
ModEvent narrow_v(Space &home, I &i, bool depends=true)
Replace domain by values described by i.
Definition: offset.hpp:199
ModEvent inter_r(Space &home, I &i, bool depends=true)
Intersect domain with ranges described by i.
Definition: offset.hpp:187
ModEvent lq(Space &home, int n)
Restrict domain values to be less or equal than n.
Definition: int.hpp:115
View base(void) const
Return view from which this view is derived.
Definition: view.hpp:526
int offset(void) const
Return offset.
Definition: offset.hpp:56
unsigned int size(void) const
Return size (cardinality) of domain.
Definition: int.hpp:75
int med(void) const
Return median of domain (greatest element not greater than the median)
Definition: offset.hpp:72
OffsetView(void)
Default constructor.
Definition: offset.hpp:45
void update(Space &home, bool share, DerivedView< View > &y)
Update this view to be a clone of view y.
Definition: view.hpp:590
int min(void) const
Return minimum of domain.
Definition: int.hpp:58
unsigned int size(void) const
Return size (cardinality) of domain.
Definition: offset.hpp:85
bool any(const Delta &d) const
Test whether arbitrary values got pruned.
Definition: int.hpp:220
Offset integer view.
Definition: view.hpp:422
ModEvent minus_v(Space &home, I &i, bool depends=true)
Remove from domain the values described by i.
Definition: offset.hpp:211
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
ModEvent inter_v(Space &home, I &i, bool depends=true)
Intersect domain with values described by i.
Definition: offset.hpp:205
bool any(const Delta &d) const
Test whether arbitrary values got pruned.
Definition: offset.hpp:241
ModEvent lq(Space &home, int n)
Restrict domain values to be less or equal than n.
Definition: offset.hpp:121
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 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
ModEvent narrow_r(Space &home, I &i, bool depends=true)
Replace domain by ranges described by i.
Definition: offset.hpp:181
bool range(void) const
Test whether domain is a range.
Definition: int.hpp:97
IntView x
View from which this view is derived.
Definition: view.hpp:216
void update(Space &home, bool share, OffsetView &y)
Update this view to be a clone of view y.
Definition: offset.hpp:252
Gecode toplevel namespace
Value iterator for pointwise offset (by some constant)
Range iterator for pointwise offset (by some constant)
int ModEventDelta
Modification event deltas.
Definition: core.hpp:173
bool range(void) const
Test whether domain is a range.
Definition: offset.hpp:102