Generated on Fri Oct 19 11:24:59 2018 for Gecode by doxygen 1.6.3

scale.hpp

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Christian Schulte <schulte@gecode.org>
00005  *
00006  *  Contributing authors:
00007  *     Samuel Gagnon <samuel.gagnon92@gmail.com>
00008  *
00009  *  Copyright:
00010  *     Christian Schulte, 2002
00011  *     Samuel Gagnon, 2018
00012  *
00013  *  This file is part of Gecode, the generic constraint
00014  *  development environment:
00015  *     http://www.gecode.org
00016  *
00017  *  Permission is hereby granted, free of charge, to any person obtaining
00018  *  a copy of this software and associated documentation files (the
00019  *  "Software"), to deal in the Software without restriction, including
00020  *  without limitation the rights to use, copy, modify, merge, publish,
00021  *  distribute, sublicense, and/or sell copies of the Software, and to
00022  *  permit persons to whom the Software is furnished to do so, subject to
00023  *  the following conditions:
00024  *
00025  *  The above copyright notice and this permission notice shall be
00026  *  included in all copies or substantial portions of the Software.
00027  *
00028  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00029  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00030  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00031  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00032  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00033  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00034  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00035  *
00036  */
00037 
00038 #include <gecode/int/div.hh>
00039 
00040 namespace Gecode { namespace Int {
00041 
00042   /*
00043    * Constructors and initialization
00044    *
00045    */
00046   template<class Val, class UnsVal>
00047   forceinline
00048   ScaleView<Val,UnsVal>::ScaleView(void) {}
00049 
00050   template<class Val, class UnsVal>
00051   forceinline
00052   ScaleView<Val,UnsVal>::ScaleView(int b, const IntView& y)
00053     : DerivedView<IntView>(y), a(b) {}
00054 
00055 
00056   /*
00057    * Value access
00058    *
00059    */
00060   template<class Val, class UnsVal>
00061   forceinline int
00062   ScaleView<Val,UnsVal>::scale(void) const {
00063     return a;
00064   }
00065   template<class Val, class UnsVal>
00066   forceinline Val
00067   ScaleView<Val,UnsVal>::min(void) const {
00068     return static_cast<Val>(x.min()) * a;
00069   }
00070 
00071   template<class Val, class UnsVal>
00072   forceinline Val
00073   ScaleView<Val,UnsVal>::max(void) const {
00074     return static_cast<Val>(x.max()) * a;
00075   }
00076 
00077   template<class Val, class UnsVal>
00078   forceinline Val
00079   ScaleView<Val,UnsVal>::med(void) const {
00080     return static_cast<Val>(x.med()) * a;
00081   }
00082 
00083   template<class Val, class UnsVal>
00084   forceinline Val
00085   ScaleView<Val,UnsVal>::val(void) const {
00086     return static_cast<Val>(x.val()) * a;
00087   }
00088 #ifdef GECODE_HAS_CBS
00089   template<class Val, class UnsVal>
00090   forceinline Val
00091   ScaleView<Val,UnsVal>::baseval(Val val) const {
00092     return val / a;
00093   }
00094 #endif
00095 
00096   template<class Val, class UnsVal>
00097   forceinline UnsVal
00098   ScaleView<Val,UnsVal>::size(void) const {
00099     return static_cast<UnsVal>(x.size());
00100   }
00101 
00102   template<class Val, class UnsVal>
00103   forceinline UnsVal
00104   ScaleView<Val,UnsVal>::width(void) const {
00105     return static_cast<UnsVal>(x.width()) * a;
00106   }
00107 
00108   template<class Val, class UnsVal>
00109   forceinline UnsVal
00110   ScaleView<Val,UnsVal>::regret_min(void) const {
00111     return static_cast<UnsVal>(x.regret_min()) * a;
00112   }
00113 
00114   template<class Val, class UnsVal>
00115   forceinline UnsVal
00116   ScaleView<Val,UnsVal>::regret_max(void) const {
00117     return static_cast<UnsVal>(x.regret_max()) * a;
00118   }
00119 
00120 
00121   /*
00122    * Domain tests
00123    *
00124    */
00125   template<class Val, class UnsVal>
00126   forceinline bool
00127   ScaleView<Val,UnsVal>::range(void) const {
00128     return x.range();
00129   }
00130   template<class Val, class UnsVal>
00131   forceinline bool
00132   ScaleView<Val,UnsVal>::in(Val n) const {
00133     return ((n % a) == 0) && x.in(n / a);
00134   }
00135 
00136 
00137 
00138 
00139   /*
00140    * Domain update by value
00141    *
00142    */
00143   template<class Val, class UnsVal>
00144   forceinline ModEvent
00145   ScaleView<Val,UnsVal>::lq(Space& home, Val n) {
00146     return (n >= max()) ? ME_INT_NONE :
00147       x.lq(home,floor_div_xp(n,static_cast<Val>(a)));
00148   }
00149 
00150   template<class Val, class UnsVal>
00151   forceinline ModEvent
00152   ScaleView<Val,UnsVal>::le(Space& home, Val n) {
00153     return (n > max()) ? ME_INT_NONE :
00154       x.le(home,floor_div_xp(n,static_cast<Val>(a)));
00155   }
00156 
00157   template<class Val, class UnsVal>
00158   forceinline ModEvent
00159   ScaleView<Val,UnsVal>::gq(Space& home, Val n) {
00160     return (n <= min()) ? ME_INT_NONE :
00161       x.gq(home,ceil_div_xp(n,static_cast<Val>(a)));
00162   }
00163   template<class Val, class UnsVal>
00164   forceinline ModEvent
00165   ScaleView<Val,UnsVal>::gr(Space& home, Val n) {
00166     return (n < min()) ? ME_INT_NONE :
00167       x.gr(home,ceil_div_xp(n,static_cast<Val>(a)));
00168   }
00169 
00170   template<class Val, class UnsVal>
00171   forceinline ModEvent
00172   ScaleView<Val,UnsVal>::nq(Space& home, Val n) {
00173     return ((n % a) == 0) ? x.nq(home,n/a) :  ME_INT_NONE;
00174   }
00175 
00176   template<class Val, class UnsVal>
00177   forceinline ModEvent
00178   ScaleView<Val,UnsVal>::eq(Space& home, Val n) {
00179     return ((n % a) == 0) ? x.eq(home,n/a) : ME_INT_FAILED;
00180   }
00181 
00182 
00183   /*
00184    * Propagator modification events
00185    *
00186    */
00187   template<class Val, class UnsVal>
00188   forceinline ModEventDelta
00189   ScaleView<Val,UnsVal>::med(ModEvent me) {
00190     return IntView::med(me);
00191   }
00192 
00193 
00194 
00195   /*
00196    * Delta information for advisors
00197    *
00198    */
00199   template<class Val, class UnsVal>
00200   forceinline Val
00201   ScaleView<Val,UnsVal>::min(const Delta& d) const {
00202     return static_cast<Val>(x.min(d)) * a;
00203   }
00204   template<class Val, class UnsVal>
00205   forceinline Val
00206   ScaleView<Val,UnsVal>::max(const Delta& d) const {
00207     return static_cast<Val>(x.max(d)) * a;
00208   }
00209   template<class Val, class UnsVal>
00210   forceinline UnsVal
00211   ScaleView<Val,UnsVal>::width(const Delta& d) const {
00212     return static_cast<UnsVal>(x.width(d)) * a;
00213   }
00214   template<class Val, class UnsVal>
00215   forceinline bool
00216   ScaleView<Val,UnsVal>::any(const Delta& d) const {
00217     return x.any(d);
00218   }
00219 
00220 
00221 
00222   /*
00223    * Cloning
00224    *
00225    */
00226   template<class Val, class UnsVal>
00227   forceinline void
00228   ScaleView<Val,UnsVal>::update(Space& home, ScaleView<Val,UnsVal>& y) {
00229     DerivedView<IntView>::update(home,y);
00230     a=y.a;
00231   }
00232 
00233 
00234   /*
00235    * Ordering
00236    *
00237    */
00238   template<class Val, class UnsVal>
00239   forceinline bool
00240   ScaleView<Val,UnsVal>::operator <(const ScaleView<Val,UnsVal>& y) const {
00241     return ((base() < y.base())
00242             || ((base() == y.base()) && (scale() < y.scale())));
00243   }
00244 
00245 
00246 
00247 
00252   template<>
00253   class ViewRanges<IntScaleView>
00254     : public Iter::Ranges::ScaleUp<int,unsigned int,ViewRanges<IntView> > {
00255   public:
00257 
00258 
00259     ViewRanges(void);
00261     ViewRanges(const IntScaleView& x);
00263     void init(const IntScaleView& x);
00265   };
00266 
00267   forceinline
00268   ViewRanges<IntScaleView>::ViewRanges(void) {}
00269   forceinline
00270   ViewRanges<IntScaleView>::ViewRanges(const IntScaleView& x) {
00271     ViewRanges<IntView> xi(x.base());
00272     Iter::Ranges::ScaleUp<int,unsigned int,ViewRanges<IntView> >::init
00273       (xi,x.scale());
00274   }
00275   forceinline void
00276   ViewRanges<IntScaleView>::init(const IntScaleView& x) {
00277     ViewRanges<IntView> xi(x.base());
00278     Iter::Ranges::ScaleUp<int,unsigned int,ViewRanges<IntView> >::init
00279       (xi,x.scale());
00280   }
00281 
00282 
00287   template<>
00288   class ViewRanges<LLongScaleView>
00289     : public Iter::Ranges::ScaleUp<long long int,unsigned long long int,
00290                                    ViewRanges<IntView> > {
00291   public:
00293 
00294 
00295     ViewRanges(void);
00297     ViewRanges(const LLongScaleView& x);
00299     void init(const LLongScaleView& x);
00301   };
00302 
00303   forceinline
00304   ViewRanges<LLongScaleView>::ViewRanges(void) {}
00305   forceinline
00306   ViewRanges<LLongScaleView>::ViewRanges(const LLongScaleView& x) {
00307     ViewRanges<IntView> xi(x.base());
00308     Iter::Ranges::ScaleUp<long long int,unsigned long long int,
00309       ViewRanges<IntView> >::init(xi,x.scale());
00310   }
00311   forceinline void
00312   ViewRanges<LLongScaleView>::init(const LLongScaleView& x) {
00313     ViewRanges<IntView> xi(x.base());
00314     Iter::Ranges::ScaleUp<long long int,unsigned long long int,
00315       ViewRanges<IntView> >::init(xi,x.scale());
00316   }
00317 
00318 
00319   /*
00320    * View comparison
00321    *
00322    */
00323   template<class Val, class UnsVal>
00324   forceinline bool
00325   operator ==(const ScaleView<Val,UnsVal>& x, const ScaleView<Val,UnsVal>& y) {
00326     return (x.base() == y.base()) && (x.scale() == y.scale());
00327   }
00328   template<class Val, class UnsVal>
00329   forceinline bool
00330   operator !=(const ScaleView<Val,UnsVal>& x, const ScaleView<Val,UnsVal>& y) {
00331     return !(x == y);
00332   }
00333 
00334 }}
00335 
00336 // STATISTICS: int-var
00337