Generated on Tue Jan 28 2020 00:00:00 for Gecode by doxygen 1.8.17
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  * Copyright:
7  * Christian Schulte, 2002
8  *
9  * Last modified:
10  * $Date: 2016-04-19 17:19:45 +0200 (Tue, 19 Apr 2016) $ by $Author: schulte $
11  * $Revision: 14967 $
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 
40 namespace Gecode { namespace Int {
41 
42  /*
43  * Constructors and initialization
44  *
45  */
46  template<class Val, class UnsVal>
49 
50  template<class Val, class UnsVal>
53  : DerivedView<IntView>(y), a(b) {}
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 
89  template<class Val, class UnsVal>
90  forceinline UnsVal
92  return static_cast<UnsVal>(x.size());
93  }
94 
95  template<class Val, class UnsVal>
96  forceinline UnsVal
98  return static_cast<UnsVal>(x.width()) * a;
99  }
100 
101  template<class Val, class UnsVal>
102  forceinline UnsVal
104  return static_cast<UnsVal>(x.regret_min()) * a;
105  }
106 
107  template<class Val, class UnsVal>
108  forceinline UnsVal
110  return static_cast<UnsVal>(x.regret_max()) * a;
111  }
112 
113 
114  /*
115  * Domain tests
116  *
117  */
118  template<class Val, class UnsVal>
119  forceinline bool
121  return x.range();
122  }
123  template<class Val, class UnsVal>
124  forceinline bool
126  return ((n % a) == 0) && x.in(n / a);
127  }
128 
129 
130 
131 
132  /*
133  * Domain update by value
134  *
135  */
136  template<class Val, class UnsVal>
139  return (n >= max()) ? ME_INT_NONE :
140  x.lq(home,floor_div_xp(n,static_cast<Val>(a)));
141  }
142 
143  template<class Val, class UnsVal>
146  return (n > max()) ? ME_INT_NONE :
147  x.le(home,floor_div_xp(n,static_cast<Val>(a)));
148  }
149 
150  template<class Val, class UnsVal>
153  return (n <= min()) ? ME_INT_NONE :
154  x.gq(home,ceil_div_xp(n,static_cast<Val>(a)));
155  }
156  template<class Val, class UnsVal>
159  return (n < min()) ? ME_INT_NONE :
160  x.gr(home,ceil_div_xp(n,static_cast<Val>(a)));
161  }
162 
163  template<class Val, class UnsVal>
166  return ((n % a) == 0) ? x.nq(home,n/a) : ME_INT_NONE;
167  }
168 
169  template<class Val, class UnsVal>
172  return ((n % a) == 0) ? x.eq(home,n/a) : ME_INT_FAILED;
173  }
174 
175 
176  /*
177  * Propagator modification events
178  *
179  */
180  template<class Val, class UnsVal>
183  return IntView::med(me);
184  }
185 
186 
187 
188  /*
189  * Delta information for advisors
190  *
191  */
192  template<class Val, class UnsVal>
193  forceinline Val
195  return static_cast<Val>(x.min(d)) * a;
196  }
197  template<class Val, class UnsVal>
198  forceinline Val
200  return static_cast<Val>(x.max(d)) * a;
201  }
202  template<class Val, class UnsVal>
203  forceinline bool
205  return x.any(d);
206  }
207 
208 
209 
210  /*
211  * Cloning
212  *
213  */
214  template<class Val, class UnsVal>
215  forceinline void
218  DerivedView<IntView>::update(home,share,y);
219  a=y.a;
220  }
221 
222 
223 
228  template<>
229  class ViewRanges<IntScaleView>
230  : public Iter::Ranges::ScaleUp<int,unsigned int,ViewRanges<IntView> > {
231  public:
233 
234  ViewRanges(void);
237  ViewRanges(const IntScaleView& x);
239  void init(const IntScaleView& x);
241  };
242 
247  ViewRanges<IntView> xi(x.base());
249  (xi,x.scale());
250  }
251  forceinline void
252  ViewRanges<IntScaleView>::init(const IntScaleView& x) {
253  ViewRanges<IntView> xi(x.base());
255  (xi,x.scale());
256  }
257 
258 
263  template<>
264  class ViewRanges<LLongScaleView>
265  : public Iter::Ranges::ScaleUp<long long int,unsigned long long int,
266  ViewRanges<IntView> > {
267  public:
269 
270  ViewRanges(void);
273  ViewRanges(const LLongScaleView& x);
275  void init(const LLongScaleView& x);
277  };
278 
282  ViewRanges<LLongScaleView>::ViewRanges(const LLongScaleView& x) {
283  ViewRanges<IntView> xi(x.base());
284  Iter::Ranges::ScaleUp<long long int,unsigned long long int,
285  ViewRanges<IntView> >::init(xi,x.scale());
286  }
287  forceinline void
288  ViewRanges<LLongScaleView>::init(const LLongScaleView& x) {
289  ViewRanges<IntView> xi(x.base());
290  Iter::Ranges::ScaleUp<long long int,unsigned long long int,
291  ViewRanges<IntView> >::init(xi,x.scale());
292  }
293 
294 
295  /*
296  * View comparison
297  *
298  */
299  template<class Val, class UnsVal>
300  forceinline bool
302  return same(x.base(),y.base()) && (x.scale() == y.scale());
303  }
304  template<class Val, class UnsVal>
305  forceinline bool
307  return before(x.base(),y.base())
308  || (same(x.base(),y.base()) && (x.scale() < y.scale()));
309  }
310 
311 }}
312 
313 // STATISTICS: int-var
314 
Val max(void) const
Return maximum of domain.
Definition: scale.hpp:73
Post propagator for SetVar x
Definition: set.hh:784
Post propagator for SetVar SetOpType SetVar y
Definition: set.hh:784
#define forceinline
Definition: config.hpp:173
UnsVal size(void) const
Return size (cardinality) of domain.
Definition: scale.hpp:91
void max(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition: arithmetic.cpp:53
const Gecode::ModEvent ME_INT_FAILED
Domain operation has resulted in failure.
Definition: var-type.hpp:52
void init(const View &x)
Initialize with ranges for view x.
ScaleView(void)
Default constructor.
Definition: scale.hpp:48
const Gecode::ModEvent ME_INT_NONE
Domain operation has not changed domain.
Definition: var-type.hpp:54
bool same(const CachedView< View > &x, const CachedView< View > &y)
Definition: cached.hpp:389
int scale(void) const
Return scale factor of scale view.
Definition: scale.hpp:62
bool any(const Delta &d) const
Test whether arbitrary values got pruned.
Definition: scale.hpp:204
Computation spaces.
Definition: core.hpp:1748
IntType floor_div_xp(IntType x, IntType y)
Compute where y is non-negative.
Definition: div.hpp:79
bool in(Val n) const
Test whether n is contained in domain.
Definition: scale.hpp:125
ModEvent lq(Space &home, Val n)
Restrict domain values to be less or equal than n.
Definition: scale.hpp:138
void update(Space &home, bool share, DerivedView< View > &y)
Update this view to be a clone of view y.
Base-class for derived views.
Definition: view.hpp:222
IntType ceil_div_xp(IntType x, IntType y)
Compute where y is non-negative.
Definition: div.hpp:73
Gecode toplevel namespace
Range iterator for integer views.
Definition: view.hpp:54
bool before(const CachedView< View > &x, const CachedView< View > &y)
Definition: cached.hpp:394
Val med(void) const
Return median of domain (greatest element not greater than the median)
Definition: scale.hpp:79
Generic domain change information to be supplied to advisors.
Definition: core.hpp:281
struct Gecode::@579::NNF::@61::@63 a
For atomic nodes.
struct Gecode::@579::NNF::@61::@62 b
For binary nodes (and, or, eqv)
bool range(void) const
Test whether domain is a range.
Definition: scale.hpp:120
Val val(void) const
Return assigned value (only if assigned)
Definition: scale.hpp:85
ViewRanges(void)
Default constructor.
UnsVal regret_max(void) const
Return regret of domain maximum (distance to next smaller value)
Definition: scale.hpp:109
Range iterator for pointwise product with a positive integer.
UnsVal regret_min(void) const
Return regret of domain minimum (distance to next larger value)
Definition: scale.hpp:103
int ModEvent
Type for modification events.
Definition: core.hpp:142
Scale integer view (template)
Definition: view.hpp:671
ModEvent le(Space &home, Val n)
Restrict domain values to be less than n.
Definition: scale.hpp:145
Gecode::IntSet d(v, 7)
ModEvent gr(Space &home, Val n)
Restrict domain values to be greater than n.
Definition: scale.hpp:158
Integer view for integer variables.
Definition: view.hpp:129
void update(Space &home, bool share, ScaleView< Val, UnsVal > &y)
Update this view to be a clone of view y.
Definition: scale.hpp:216
ModEvent nq(Space &home, Val n)
Restrict domain values to be different from n.
Definition: scale.hpp:165
UnsVal width(void) const
Return width of domain (distance between maximum and minimum)
Definition: scale.hpp:97
Range iterator for integer variable views
Definition: int.hpp:236
void min(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition: arithmetic.cpp:71
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
int med(void) const
Return median of domain (greatest element not greater than the median)
Definition: int.hpp:66
int ModEventDelta
Modification event deltas.
Definition: core.hpp:169
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:171
ModEvent gq(Space &home, Val n)
Restrict domain values to be greater or equal than n.
Definition: scale.hpp:152