Generated on Thu Jan 16 2025 00:00:00 for Gecode by doxygen 1.14.0
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 * Contributing authors:
7 * Samuel Gagnon <samuel.gagnon92@gmail.com>
8 *
9 * Copyright:
10 * Christian Schulte, 2002
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
38namespace 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#ifdef GECODE_HAS_CBS
80 forceinline int
81 OffsetView::baseval(int val) const {
82 return val-c;
83 }
84#endif
85
86 forceinline unsigned int
87 OffsetView::width(void) const {
88 return x.width();
89 }
90 forceinline unsigned int
91 OffsetView::size(void) const {
92 return x.size();
93 }
94 forceinline unsigned int
96 return x.regret_min();
97 }
98 forceinline unsigned int
100 return x.regret_max();
101 }
102
103 /*
104 * Domain tests
105 *
106 */
107 forceinline bool
108 OffsetView::range(void) const {
109 return x.range();
110 }
111 forceinline bool
112 OffsetView::in(int n) const {
113 return x.in(n-c);
114 }
115 forceinline bool
116 OffsetView::in(long long int n) const {
117 return x.in(n-c);
118 }
119
120
121
122 /*
123 * Domain update by value
124 *
125 */
127 OffsetView::lq(Space& home, int n) {
128 return x.lq(home,n-c);
129 }
131 OffsetView::lq(Space& home, long long int n) {
132 return x.lq(home,n-c);
133 }
134
136 OffsetView::le(Space& home, int n) {
137 return x.le(home,n-c);
138 }
140 OffsetView::le(Space& home, long long int n) {
141 return x.le(home,n-c);
142 }
143
145 OffsetView::gq(Space& home, int n) {
146 return x.gq(home,n-c);
147 }
149 OffsetView::gq(Space& home, long long int n) {
150 return x.gq(home,n-c);
151 }
152
154 OffsetView::gr(Space& home, int n) {
155 return x.gr(home,n-c);
156 }
158 OffsetView::gr(Space& home, long long int n) {
159 return x.gr(home,n-c);
160 }
161
163 OffsetView::nq(Space& home, int n) {
164 return x.nq(home,n-c);
165 }
167 OffsetView::nq(Space& home, long long int n) {
168 return x.nq(home,n-c);
169 }
170
172 OffsetView::eq(Space& home, int n) {
173 return x.eq(home,n-c);
174 }
176 OffsetView::eq(Space& home, long long int n) {
177 return x.eq(home,n-c);
178 }
179
180
181 /*
182 * Iterator-based domain update
183 *
184 */
185 template<class I>
187 OffsetView::narrow_r(Space& home, I& i, bool depend) {
189 return x.narrow_r(home,oi,depend);
190 }
191 template<class I>
193 OffsetView::inter_r(Space& home, I& i, bool depend) {
195 return x.inter_r(home,oi,depend);
196 }
197 template<class I>
199 OffsetView::minus_r(Space& home, I& i, bool depend) {
201 return x.minus_r(home,oi,depend);
202 }
203 template<class I>
205 OffsetView::narrow_v(Space& home, I& i, bool depend) {
207 return x.narrow_v(home,oi,depend);
208 }
209 template<class I>
211 OffsetView::inter_v(Space& home, I& i, bool depend) {
213 return x.inter_v(home,oi,depend);
214 }
215 template<class I>
217 OffsetView::minus_v(Space& home, I& i, bool depend) {
219 return x.minus_v(home,oi,depend);
220 }
221
222
223
224 /*
225 * Propagator modification events
226 *
227 */
232
233
234 /*
235 * Delta information for advisors
236 *
237 */
238 forceinline int
239 OffsetView::min(const Delta& d) const {
240 return x.min(d)+c;
241 }
242 forceinline int
243 OffsetView::max(const Delta& d) const {
244 return x.max(d)+c;
245 }
246 forceinline unsigned int
247 OffsetView::width(const Delta& d) const {
248 return x.width(d);
249 }
250 forceinline bool
251 OffsetView::any(const Delta& d) const {
252 return x.any(d);
253 }
254
255
256
257 /*
258 * Cloning
259 *
260 */
261 forceinline void
266
267
268 /*
269 * Ordering
270 *
271 */
273 OffsetView::operator <(const OffsetView& y) const {
274 return ((base() < y.base())
275 || ((base() == y.base()) && (offset() < y.offset())));
276 }
277
278
283 template<>
285 : public Iter::Ranges::Offset<ViewRanges<IntView> > {
286 public:
288
289
290 ViewRanges(void);
292 ViewRanges(const OffsetView& x);
294 void init(const OffsetView& x);
296 };
297
300
306
307 forceinline void
312
313 /*
314 * View comparison
315 *
316 */
317 forceinline bool
319 return (x.base() == y.base()) && (x.offset() == y.offset());
320 }
321 forceinline bool
323 return !(x == y);
324 }
325
326}}
327
328// STATISTICS: int-var
329
Generic domain change information to be supplied to advisors.
Definition core.hpp:204
IntView base(void) const
Definition view.hpp:605
static ModEvent me(const ModEventDelta &med)
Definition view.hpp:639
void update(Space &home, DerivedView< View > &y)
Update this view to be a clone of view y.
Definition view.hpp:681
Integer view for integer variables.
Definition view.hpp:129
int med(void) const
Return median of domain (greatest element not greater than the median)
Definition int.hpp:66
Offset integer view.
Definition view.hpp:443
int min(void) const
Return minimum of domain.
Definition offset.hpp:64
ModEvent gr(Space &home, int n)
Restrict domain values to be greater than n.
Definition offset.hpp:154
ModEvent lq(Space &home, int n)
Restrict domain values to be less or equal than n.
Definition offset.hpp:127
int val(void) const
Return assigned value (only if assigned)
Definition offset.hpp:76
void update(Space &home, OffsetView &y)
Update this view to be a clone of view y.
Definition offset.hpp:262
ModEvent inter_r(Space &home, I &i, bool depends=true)
Intersect domain with ranges described by i.
Definition offset.hpp:193
int med(void) const
Return median of domain (greatest element not greater than the median)
Definition offset.hpp:72
unsigned int regret_min(void) const
Return regret of domain minimum (distance to next larger value)
Definition offset.hpp:95
ModEvent narrow_v(Space &home, I &i, bool depends=true)
Replace domain by values described by i.
Definition offset.hpp:205
unsigned int size(void) const
Return size (cardinality) of domain.
Definition offset.hpp:91
unsigned int regret_max(void) const
Return regret of domain maximum (distance to next smaller value)
Definition offset.hpp:99
ModEvent minus_v(Space &home, I &i, bool depends=true)
Remove from domain the values described by i.
Definition offset.hpp:217
int offset(void) const
Return offset.
Definition offset.hpp:56
int max(void) const
Return maximum of domain.
Definition offset.hpp:68
unsigned int width(void) const
Return width of domain (distance between maximum and minimum)
Definition offset.hpp:87
bool any(const Delta &d) const
Test whether arbitrary values got pruned.
Definition offset.hpp:251
OffsetView(void)
Default constructor.
Definition offset.hpp:45
bool in(int n) const
Test whether n is contained in domain.
Definition offset.hpp:112
bool operator<(const OffsetView &y) const
Whether this view comes before view y (arbitray order)
Definition offset.hpp:273
ModEvent minus_r(Space &home, I &i, bool depends=true)
Remove from domain the ranges described by i.
Definition offset.hpp:199
ModEvent gq(Space &home, int n)
Restrict domain values to be greater or equal than n.
Definition offset.hpp:145
ModEvent le(Space &home, int n)
Restrict domain values to be less than n.
Definition offset.hpp:136
ModEvent inter_v(Space &home, I &i, bool depends=true)
Intersect domain with values described by i.
Definition offset.hpp:211
ModEvent nq(Space &home, int n)
Restrict domain values to be different from n.
Definition offset.hpp:163
bool range(void) const
Test whether domain is a range.
Definition offset.hpp:108
ModEvent eq(Space &home, int n)
Restrict domain values to be equal to n.
Definition offset.hpp:172
ModEvent narrow_r(Space &home, I &i, bool depends=true)
Replace domain by ranges described by i.
Definition offset.hpp:187
ViewRanges(void)
Default constructor.
Definition offset.hpp:299
void init(const OffsetView &x)
Initialize with ranges for view x.
Definition offset.hpp:308
void init(const View &x)
Initialize with ranges for view x.
ViewRanges(void)
Default constructor.
Range iterator for pointwise offset (by some constant)
Value iterator for pointwise offset (by some constant)
Computation spaces.
Definition core.hpp:1744
int ModEventDelta
Modification event deltas.
Definition core.hpp:89
Finite domain integers.
bool operator==(const CachedView< View > &x, const CachedView< View > &y)
Definition cached.hpp:401
bool operator!=(const CachedView< View > &x, const CachedView< View > &y)
Definition cached.hpp:406
Gecode toplevel namespace
Post propagator for SetVar SetOpType SetVar y
Definition set.hh:773
Post propagator for SetVar x
Definition set.hh:773
int ModEvent
Type for modification events.
Definition core.hpp:62
#define forceinline
Definition config.hpp:194