Generated on Tue Feb 11 2025 17:33:26 for Gecode by doxygen 1.12.0
scale.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
38#include <gecode/int/div.hh>
39
40namespace Gecode { namespace Int {
41
42 /*
43 * Constructors and initialization
44 *
45 */
46 template<class Val, class UnsVal>
49
50 template<class Val, class UnsVal>
54
55
56 /*
57 * Value access
58 *
59 */
60 template<class Val, class UnsVal>
61 forceinline int
63 return a;
64 }
65 template<class Val, class UnsVal>
66 forceinline Val
68 return static_cast<Val>(x.min()) * a;
69 }
70
71 template<class Val, class UnsVal>
72 forceinline Val
74 return static_cast<Val>(x.max()) * a;
75 }
76
77 template<class Val, class UnsVal>
78 forceinline Val
80 return static_cast<Val>(x.med()) * a;
81 }
82
83 template<class Val, class UnsVal>
84 forceinline Val
86 return static_cast<Val>(x.val()) * a;
87 }
88#ifdef GECODE_HAS_CBS
89 template<class Val, class UnsVal>
90 forceinline Val
91 ScaleView<Val,UnsVal>::baseval(Val val) const {
92 return val / a;
93 }
94#endif
95
96 template<class Val, class UnsVal>
97 forceinline UnsVal
99 return static_cast<UnsVal>(x.size());
100 }
101
102 template<class Val, class UnsVal>
103 forceinline UnsVal
105 return static_cast<UnsVal>(x.width()) * a;
106 }
107
108 template<class Val, class UnsVal>
109 forceinline UnsVal
111 return static_cast<UnsVal>(x.regret_min()) * a;
112 }
113
114 template<class Val, class UnsVal>
115 forceinline UnsVal
117 return static_cast<UnsVal>(x.regret_max()) * a;
118 }
119
120
121 /*
122 * Domain tests
123 *
124 */
125 template<class Val, class UnsVal>
126 forceinline bool
128 return x.range();
129 }
130 template<class Val, class UnsVal>
131 forceinline bool
133 return ((n % a) == 0) && x.in(n / a);
134 }
135
136
137
138
139 /*
140 * Domain update by value
141 *
142 */
143 template<class Val, class UnsVal>
146 return (n >= max()) ? ME_INT_NONE :
147 x.lq(home,floor_div_xp(n,static_cast<Val>(a)));
148 }
149
150 template<class Val, class UnsVal>
153 return (n > max()) ? ME_INT_NONE :
154 x.le(home,floor_div_xp(n,static_cast<Val>(a)));
155 }
156
157 template<class Val, class UnsVal>
160 return (n <= min()) ? ME_INT_NONE :
161 x.gq(home,ceil_div_xp(n,static_cast<Val>(a)));
162 }
163 template<class Val, class UnsVal>
166 return (n < min()) ? ME_INT_NONE :
167 x.gr(home,ceil_div_xp(n,static_cast<Val>(a)));
168 }
169
170 template<class Val, class UnsVal>
173 return ((n % a) == 0) ? x.nq(home,n/a) : ME_INT_NONE;
174 }
175
176 template<class Val, class UnsVal>
179 return ((n % a) == 0) ? x.eq(home,n/a) : ME_INT_FAILED;
180 }
181
182
183 /*
184 * Propagator modification events
185 *
186 */
187 template<class Val, class UnsVal>
192
193
194
195 /*
196 * Delta information for advisors
197 *
198 */
199 template<class Val, class UnsVal>
200 forceinline Val
202 return static_cast<Val>(x.min(d)) * a;
203 }
204 template<class Val, class UnsVal>
205 forceinline Val
207 return static_cast<Val>(x.max(d)) * a;
208 }
209 template<class Val, class UnsVal>
210 forceinline UnsVal
212 return static_cast<UnsVal>(x.width(d)) * a;
213 }
214 template<class Val, class UnsVal>
215 forceinline bool
217 return x.any(d);
218 }
219
220
221
222 /*
223 * Cloning
224 *
225 */
226 template<class Val, class UnsVal>
227 forceinline void
232
233
234 /*
235 * Ordering
236 *
237 */
238 template<class Val, class UnsVal>
241 return ((base() < y.base())
242 || ((base() == y.base()) && (scale() < y.scale())));
243 }
244
245
246
247
252 template<>
253 class ViewRanges<IntScaleView>
254 : public Iter::Ranges::ScaleUp<int,unsigned int,ViewRanges<IntView> > {
255 public:
257
258
259 ViewRanges(void);
261 ViewRanges(const IntScaleView& x);
263 void init(const IntScaleView& x);
265 };
266
271 ViewRanges<IntView> xi(x.base());
273 (xi,x.scale());
274 }
275 forceinline void
276 ViewRanges<IntScaleView>::init(const IntScaleView& x) {
277 ViewRanges<IntView> xi(x.base());
279 (xi,x.scale());
280 }
281
282
287 template<>
288 class ViewRanges<LLongScaleView>
289 : public Iter::Ranges::ScaleUp<long long int,unsigned long long int,
290 ViewRanges<IntView> > {
291 public:
293
294
295 ViewRanges(void);
297 ViewRanges(const LLongScaleView& x);
299 void init(const LLongScaleView& x);
301 };
302
307 ViewRanges<IntView> xi(x.base());
308 Iter::Ranges::ScaleUp<long long int,unsigned long long int,
309 ViewRanges<IntView> >::init(xi,x.scale());
310 }
311 forceinline void
312 ViewRanges<LLongScaleView>::init(const LLongScaleView& x) {
313 ViewRanges<IntView> xi(x.base());
314 Iter::Ranges::ScaleUp<long long int,unsigned long long int,
315 ViewRanges<IntView> >::init(xi,x.scale());
316 }
317
318
319 /*
320 * View comparison
321 *
322 */
323 template<class Val, class UnsVal>
324 forceinline bool
326 return (x.base() == y.base()) && (x.scale() == y.scale());
327 }
328 template<class Val, class UnsVal>
329 forceinline bool
331 return !(x == y);
332 }
333
334}}
335
336// STATISTICS: int-var
337
struct Gecode::@603::NNF::@65::@66 b
For binary nodes (and, or, eqv)
int n
Number of negative literals for node type.
struct Gecode::@603::NNF::@65::@67 a
For atomic nodes.
Generic domain change information to be supplied to advisors.
Definition core.hpp:204
Base-class for derived views.
Definition view.hpp:230
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
Scale integer view (template)
Definition view.hpp:704
Val val(void) const
Return assigned value (only if assigned)
Definition scale.hpp:85
ModEvent gq(Space &home, Val n)
Restrict domain values to be greater or equal than n.
Definition scale.hpp:159
int scale(void) const
Return scale factor of scale view.
Definition scale.hpp:62
bool in(Val n) const
Test whether n is contained in domain.
Definition scale.hpp:132
bool range(void) const
Test whether domain is a range.
Definition scale.hpp:127
void update(Space &home, ScaleView< Val, UnsVal > &y)
Update this view to be a clone of view y.
Definition scale.hpp:228
bool any(const Delta &d) const
Test whether arbitrary values got pruned.
Definition scale.hpp:216
ModEvent le(Space &home, Val n)
Restrict domain values to be less than n.
Definition scale.hpp:152
UnsVal regret_max(void) const
Return regret of domain maximum (distance to next smaller value)
Definition scale.hpp:116
UnsVal width(void) const
Return width of domain (distance between maximum and minimum)
Definition scale.hpp:104
Val max(void) const
Return maximum of domain.
Definition scale.hpp:73
Val med(void) const
Return median of domain (greatest element not greater than the median)
Definition scale.hpp:79
ModEvent gr(Space &home, Val n)
Restrict domain values to be greater than n.
Definition scale.hpp:165
bool operator<(const ScaleView< Val, UnsVal > &y) const
Whether this view comes before view y (arbitray order)
Definition scale.hpp:240
Val min(void) const
Return minimum of domain.
Definition scale.hpp:67
ModEvent eq(Space &home, Val n)
Restrict domain values to be equal to n.
Definition scale.hpp:178
ModEvent nq(Space &home, Val n)
Restrict domain values to be different from n.
Definition scale.hpp:172
UnsVal regret_min(void) const
Return regret of domain minimum (distance to next larger value)
Definition scale.hpp:110
ModEvent lq(Space &home, Val n)
Restrict domain values to be less or equal than n.
Definition scale.hpp:145
UnsVal size(void) const
Return size (cardinality) of domain.
Definition scale.hpp:98
ScaleView(void)
Default constructor.
Definition scale.hpp:48
Range iterator for integer views.
Definition view.hpp:54
void init(const View &x)
Initialize with ranges for view x.
ViewRanges(void)
Default constructor.
Range iterator for pointwise product with a positive integer.
Computation spaces.
Definition core.hpp:1742
int ModEventDelta
Modification event deltas.
Definition core.hpp:89
IntType ceil_div_xp(IntType x, IntType y)
Compute where y is non-negative.
Definition div.hpp:69
const Gecode::ModEvent ME_INT_FAILED
Domain operation has resulted in failure.
Definition var-type.hpp:52
IntType floor_div_xp(IntType x, IntType y)
Compute where y is non-negative.
Definition div.hpp:75
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
const Gecode::ModEvent ME_INT_NONE
Domain operation has not changed domain.
Definition var-type.hpp:54
Gecode toplevel namespace
void min(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Post propagator for SetVar SetOpType SetVar y
Definition set.hh:767
void max(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Post propagator for SetVar x
Definition set.hh:767
int ModEvent
Type for modification events.
Definition core.hpp:62
#define forceinline
Definition config.hpp:187