Generated on Sat May 25 2013 18:00:35 for Gecode by doxygen 1.8.3.1
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: 2013-02-14 16:29:11 +0100 (Thu, 14 Feb 2013) $ by $Author: schulte $
11  * $Revision: 13292 $
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<>
230  : public Iter::Ranges::ScaleUp<int,unsigned int,ViewRanges<IntView> > {
231  public:
233 
234 
235  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
253  ViewRanges<IntView> xi(x.base());
255  (xi,x.scale());
256  }
257 
258 
263  template<>
265  : public Iter::Ranges::ScaleUp<long long int,unsigned long long int,
266  ViewRanges<IntView> > {
267  public:
269 
270 
271  ViewRanges(void);
273  ViewRanges(const LLongScaleView& x);
275  void init(const LLongScaleView& x);
277  };
278 
283  ViewRanges<IntView> xi(x.base());
284  Iter::Ranges::ScaleUp<long long int,unsigned long long int,
286  }
287  forceinline void
289  ViewRanges<IntView> xi(x.base());
290  Iter::Ranges::ScaleUp<long long int,unsigned long long int,
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