this repo has no description
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 */
44 forceinline
45 OffsetView::OffsetView(void) {}
46 forceinline
47 OffsetView::OffsetView(const IntView& y, int d)
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
60 OffsetView::offset(int n) {
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
95 OffsetView::regret_min(void) const {
96 return x.regret_min();
97 }
98 forceinline unsigned int
99 OffsetView::regret_max(void) const {
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 */
126 forceinline ModEvent
127 OffsetView::lq(Space& home, int n) {
128 return x.lq(home,n-c);
129 }
130 forceinline ModEvent
131 OffsetView::lq(Space& home, long long int n) {
132 return x.lq(home,n-c);
133 }
134
135 forceinline ModEvent
136 OffsetView::le(Space& home, int n) {
137 return x.le(home,n-c);
138 }
139 forceinline ModEvent
140 OffsetView::le(Space& home, long long int n) {
141 return x.le(home,n-c);
142 }
143
144 forceinline ModEvent
145 OffsetView::gq(Space& home, int n) {
146 return x.gq(home,n-c);
147 }
148 forceinline ModEvent
149 OffsetView::gq(Space& home, long long int n) {
150 return x.gq(home,n-c);
151 }
152
153 forceinline ModEvent
154 OffsetView::gr(Space& home, int n) {
155 return x.gr(home,n-c);
156 }
157 forceinline ModEvent
158 OffsetView::gr(Space& home, long long int n) {
159 return x.gr(home,n-c);
160 }
161
162 forceinline ModEvent
163 OffsetView::nq(Space& home, int n) {
164 return x.nq(home,n-c);
165 }
166 forceinline ModEvent
167 OffsetView::nq(Space& home, long long int n) {
168 return x.nq(home,n-c);
169 }
170
171 forceinline ModEvent
172 OffsetView::eq(Space& home, int n) {
173 return x.eq(home,n-c);
174 }
175 forceinline ModEvent
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>
186 forceinline ModEvent
187 OffsetView::narrow_r(Space& home, I& i, bool depend) {
188 Iter::Ranges::Offset<I> oi(i,-c);
189 return x.narrow_r(home,oi,depend);
190 }
191 template<class I>
192 forceinline ModEvent
193 OffsetView::inter_r(Space& home, I& i, bool depend) {
194 Iter::Ranges::Offset<I> oi(i,-c);
195 return x.inter_r(home,oi,depend);
196 }
197 template<class I>
198 forceinline ModEvent
199 OffsetView::minus_r(Space& home, I& i, bool depend) {
200 Iter::Ranges::Offset<I> oi(i,-c);
201 return x.minus_r(home,oi,depend);
202 }
203 template<class I>
204 forceinline ModEvent
205 OffsetView::narrow_v(Space& home, I& i, bool depend) {
206 Iter::Values::Offset<I> oi(i,-c);
207 return x.narrow_v(home,oi,depend);
208 }
209 template<class I>
210 forceinline ModEvent
211 OffsetView::inter_v(Space& home, I& i, bool depend) {
212 Iter::Values::Offset<I> oi(i,-c);
213 return x.inter_v(home,oi,depend);
214 }
215 template<class I>
216 forceinline ModEvent
217 OffsetView::minus_v(Space& home, I& i, bool depend) {
218 Iter::Values::Offset<I> oi(i,-c);
219 return x.minus_v(home,oi,depend);
220 }
221
222
223
224 /*
225 * Propagator modification events
226 *
227 */
228 forceinline ModEventDelta
229 OffsetView::med(ModEvent me) {
230 return IntView::med(me);
231 }
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
262 OffsetView::update(Space& home, OffsetView& y) {
263 DerivedView<IntView>::update(home,y);
264 c=y.c;
265 }
266
267
268 /*
269 * Ordering
270 *
271 */
272 forceinline bool
273 OffsetView::operator <(const OffsetView& y) const {
274 return ((base() < y.base())
275 || ((base() == y.base()) && (offset() < y.offset())));
276 }
277
278
279 /**
280 * \brief %Range iterator for offset integer views
281 * \ingroup TaskActorIntView
282 */
283 template<>
284 class ViewRanges<OffsetView>
285 : public Iter::Ranges::Offset<ViewRanges<IntView> > {
286 public:
287 /// \name Constructors and initialization
288 //@{
289 /// Default constructor
290 ViewRanges(void);
291 /// Initialize with ranges for view \a x
292 ViewRanges(const OffsetView& x);
293 /// Initialize with ranges for view \a x
294 void init(const OffsetView& x);
295 //@}
296 };
297
298 forceinline
299 ViewRanges<OffsetView>::ViewRanges(void) {}
300
301 forceinline
302 ViewRanges<OffsetView>::ViewRanges(const OffsetView& x) {
303 ViewRanges<IntView> xi(x.base());
304 Iter::Ranges::Offset<ViewRanges<IntView> >::init(xi,x.offset());
305 }
306
307 forceinline void
308 ViewRanges<OffsetView>::init(const OffsetView& x) {
309 ViewRanges<IntView> xi(x.base());
310 Iter::Ranges::Offset<ViewRanges<IntView> >::init(xi,x.offset());
311 }
312
313 /*
314 * View comparison
315 *
316 */
317 forceinline bool
318 operator ==(const OffsetView& x, const OffsetView& y) {
319 return (x.base() == y.base()) && (x.offset() == y.offset());
320 }
321 forceinline bool
322 operator !=(const OffsetView& x, const OffsetView& y) {
323 return !(x == y);
324 }
325
326}}
327
328// STATISTICS: int-var
329