Generated on Sat Jun 2 2018 07:17:44 for Gecode by doxygen 1.8.13
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 
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 #ifdef GECODE_HAS_CBS
89  template<class Val, class UnsVal>
90  forceinline Val
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>
190  return IntView::med(me);
191  }
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
230  a=y.a;
231  }
232 
233 
234 
239  template<>
241  : public Iter::Ranges::ScaleUp<int,unsigned int,ViewRanges<IntView> > {
242  public:
244 
245  ViewRanges(void);
248  ViewRanges(const IntScaleView& x);
250  void init(const IntScaleView& x);
252  };
253 
258  ViewRanges<IntView> xi(x.base());
260  (xi,x.scale());
261  }
262  forceinline void
264  ViewRanges<IntView> xi(x.base());
266  (xi,x.scale());
267  }
268 
269 
274  template<>
276  : public Iter::Ranges::ScaleUp<long long int,unsigned long long int,
277  ViewRanges<IntView> > {
278  public:
280 
281  ViewRanges(void);
284  ViewRanges(const LLongScaleView& x);
286  void init(const LLongScaleView& x);
288  };
289 
294  ViewRanges<IntView> xi(x.base());
295  Iter::Ranges::ScaleUp<long long int,unsigned long long int,
296  ViewRanges<IntView> >::init(xi,x.scale());
297  }
298  forceinline void
300  ViewRanges<IntView> xi(x.base());
301  Iter::Ranges::ScaleUp<long long int,unsigned long long int,
302  ViewRanges<IntView> >::init(xi,x.scale());
303  }
304 
305 
306  /*
307  * View comparison
308  *
309  */
310  template<class Val, class UnsVal>
311  forceinline bool
313  return same(x.base(),y.base()) && (x.scale() == y.scale());
314  }
315  template<class Val, class UnsVal>
316  forceinline bool
318  return before(x.base(),y.base())
319  || (same(x.base(),y.base()) && (x.scale() < y.scale()));
320  }
321 
322 }}
323 
324 // STATISTICS: int-var
325 
Scale integer view (template)
Definition: view.hpp:689
ModEvent nq(Space &home, int n)
Restrict domain values to be different from n.
Definition: int.hpp:157
ModEvent gr(Space &home, int n)
Restrict domain values to be greater than n.
Definition: int.hpp:148
int val(void) const
Return assigned value (only if assigned)
Definition: int.hpp:70
View base(void) const
Return view from which this view is derived.
Definition: view.hpp:587
Val max(void) const
Return maximum of domain.
Definition: scale.hpp:73
ModEvent eq(Space &home, int n)
Restrict domain values to be equal to n.
Definition: int.hpp:166
int a
Scale factor.
Definition: view.hpp:693
ViewRanges(void)
Default constructor.
int ModEvent
Type for modification events.
Definition: core.hpp:62
unsigned int size(void) const
Return size (cardinality) of domain.
Definition: int.hpp:81
unsigned int regret_max(void) const
Return regret of domain maximum (distance to next smaller value)
Definition: int.hpp:93
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:216
Range iterator for integer variable views
Definition: int.hpp:246
ScaleView(void)
Default constructor.
Definition: scale.hpp:48
#define forceinline
Definition: config.hpp:185
Computation spaces.
Definition: core.hpp:1701
void init(const View &x)
Initialize with ranges for view x.
Base-class for derived views.
Definition: view.hpp:230
Range iterator for integer views.
Definition: view.hpp:54
bool in(Val n) const
Test whether n is contained in domain.
Definition: scale.hpp:132
Gecode::IntSet d(v, 7)
const Gecode::ModEvent ME_INT_FAILED
Domain operation has resulted in failure.
Definition: var-type.hpp:52
bool in(int n) const
Test whether n is contained in domain.
Definition: int.hpp:107
ModEvent le(Space &home, int n)
Restrict domain values to be less than n.
Definition: int.hpp:130
unsigned int regret_min(void) const
Return regret of domain minimum (distance to next larger value)
Definition: int.hpp:89
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:234
Val med(void) const
Return median of domain (greatest element not greater than the median)
Definition: scale.hpp:79
void update(Space &home, DerivedView< View > &y)
Update this view to be a clone of view y.
Definition: view.hpp:663
ModEvent lq(Space &home, int n)
Restrict domain values to be less or equal than n.
Definition: int.hpp:121
int med(void) const
Return median of domain (greatest element not greater than the median)
Definition: int.hpp:66
ModEvent lq(Space &home, Val n)
Restrict domain values to be less or equal than n.
Definition: scale.hpp:145
bool range(void) const
Test whether domain is a range.
Definition: scale.hpp:127
Val val(void) const
Return assigned value (only if assigned)
Definition: scale.hpp:85
Range iterator for pointwise product with a positive integer.
int min(void) const
Return minimum of domain.
Definition: int.hpp:58
IntType floor_div_xp(IntType x, IntType y)
Compute where y is non-negative.
Definition: div.hpp:75
IntType ceil_div_xp(IntType x, IntType y)
Compute where y is non-negative.
Definition: div.hpp:69
bool same(const ScaleView< Val, UnsVal > &x, const ScaleView< Val, UnsVal > &y)
Test whether views x and y are the same.
Definition: scale.hpp:312
bool range(void) const
Test whether domain is a range.
Definition: int.hpp:103
UnsVal regret_max(void) const
Return regret of domain maximum (distance to next smaller value)
Definition: scale.hpp:116
ModEvent le(Space &home, Val n)
Restrict domain values to be less than n.
Definition: scale.hpp:152
unsigned int width(void) const
Return width of domain (distance between maximum and minimum)
Definition: int.hpp:85
void update(Space &home, ScaleView< Val, UnsVal > &y)
Update this view to be a clone of view y.
Definition: scale.hpp:228
UnsVal regret_min(void) const
Return regret of domain minimum (distance to next larger value)
Definition: scale.hpp:110
struct Gecode::@585::NNF::@62::@63 b
For binary nodes (and, or, eqv)
Integer view for integer variables.
Definition: view.hpp:129
bool any(const Delta &d) const
Test whether arbitrary values got pruned.
Definition: int.hpp:230
Post propagator for SetVar SetOpType SetVar y
Definition: set.hh:765
Generic domain change information to be supplied to advisors.
Definition: core.hpp:203
struct Gecode::@585::NNF::@62::@64 a
For atomic nodes.
ModEvent gr(Space &home, Val n)
Restrict domain values to be greater than n.
Definition: scale.hpp:165
ModEvent gq(Space &home, int n)
Restrict domain values to be greater or equal than n.
Definition: int.hpp:139
static ModEvent me(const ModEventDelta &med)
Return modification event for view type in med.
Definition: view.hpp:621
IntView x
View from which this view is derived.
Definition: view.hpp:238
UnsVal width(void) const
Return width of domain (distance between maximum and minimum)
Definition: scale.hpp:104
bool before(const ScaleView< Val, UnsVal > &x, const ScaleView< Val, UnsVal > &y)
Test whether view x comes before y (arbitrary order)
Definition: scale.hpp:317
Gecode toplevel namespace
int max(void) const
Return maximum of domain.
Definition: int.hpp:62
Val min(void) const
Return minimum of domain.
Definition: scale.hpp:67
ModEvent nq(Space &home, Val n)
Restrict domain values to be different from n.
Definition: scale.hpp:172
int ModEventDelta
Modification event deltas.
Definition: core.hpp:89
UnsVal size(void) const
Return size (cardinality) of domain.
Definition: scale.hpp:98
const Gecode::ModEvent ME_INT_NONE
Domain operation has not changed domain.
Definition: var-type.hpp:54
ModEvent eq(Space &home, Val n)
Restrict domain values to be equal to n.
Definition: scale.hpp:178
ModEvent gq(Space &home, Val n)
Restrict domain values to be greater or equal than n.
Definition: scale.hpp:159