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, 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
38namespace Gecode { namespace Int {
39
40 /*
41 * Constructors and initialization
42 *
43 */
44 forceinline
45 MinusView::MinusView(void) {}
46 forceinline
47 MinusView::MinusView(const IntView& y)
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 */
114 forceinline ModEvent
115 MinusView::lq(Space& home, int n) {
116 return x.gq(home,-n);
117 }
118 forceinline ModEvent
119 MinusView::lq(Space& home, long long int n) {
120 return x.gq(home,-n);
121 }
122
123 forceinline ModEvent
124 MinusView::le(Space& home, int n) {
125 return x.gr(home,-n);
126 }
127 forceinline ModEvent
128 MinusView::le(Space& home, long long int n) {
129 return x.gr(home,-n);
130 }
131
132 forceinline ModEvent
133 MinusView::gq(Space& home, int n) {
134 return x.lq(home,-n);
135 }
136 forceinline ModEvent
137 MinusView::gq(Space& home, long long int n) {
138 return x.lq(home,-n);
139 }
140
141 forceinline ModEvent
142 MinusView::gr(Space& home, int n) {
143 return x.le(home,-n);
144 }
145 forceinline ModEvent
146 MinusView::gr(Space& home, long long int n) {
147 return x.le(home,-n);
148 }
149
150 forceinline ModEvent
151 MinusView::nq(Space& home, int n) {
152 return x.nq(home,-n);
153 }
154 forceinline ModEvent
155 MinusView::nq(Space& home, long long int n) {
156 return x.nq(home,-n);
157 }
158
159 forceinline ModEvent
160 MinusView::eq(Space& home, int n) {
161 return x.eq(home,-n);
162 }
163 forceinline ModEvent
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>
174 forceinline ModEvent
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>
181 forceinline ModEvent
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>
188 forceinline ModEvent
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>
195 forceinline ModEvent
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>
202 forceinline ModEvent
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>
209 forceinline ModEvent
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 */
221 forceinline ModEventDelta
222 MinusView::med(ModEvent me) {
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
249 /**
250 * \brief %Range iterator for minus integer views
251 * \ingroup TaskActorIntView
252 */
253 template<>
254 class ViewRanges<MinusView> : public IntVarImpBwd {
255 public:
256 /// \name Constructors and initialization
257 //@{
258 /// Default constructor
259 ViewRanges(void);
260 /// Initialize with ranges for view \a x
261 ViewRanges(const MinusView& x);
262 /// Initialize with ranges for view \a x
263 void init(const MinusView& x);
264 //@}
265
266 /// \name Range access
267 //@{
268 /// Return smallest value of range
269 int min(void) const;
270 /// Return largest value of range
271 int max(void) const;
272 //@}
273 };
274
275 forceinline
276 ViewRanges<MinusView>::ViewRanges(void) {}
277
278 forceinline
279 ViewRanges<MinusView>::ViewRanges(const MinusView& x)
280 : IntVarImpBwd(x.base().varimp()) {}
281
282 forceinline void
283 ViewRanges<MinusView>::init(const MinusView& x) {
284 IntVarImpBwd::init(x.base().varimp());
285 }
286
287 forceinline int
288 ViewRanges<MinusView>::min(void) const {
289 return -IntVarImpBwd::max();
290 }
291 forceinline int
292 ViewRanges<MinusView>::max(void) const {
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