Generated on Tue Apr 18 10:21:44 2017 for Gecode by doxygen 1.6.3

minus.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  *  Copyright:
00007  *     Christian Schulte, 2003
00008  *
00009  *  Last modified:
00010  *     $Date: 2013-02-14 16:29:11 +0100 (Thu, 14 Feb 2013) $ by $Author: schulte $
00011  *     $Revision: 13292 $
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 namespace Gecode { namespace Int {
00039 
00040   /*
00041    * Constructors and initialization
00042    *
00043    */
00044   forceinline
00045   MinusView::MinusView(void) {}
00046   forceinline
00047   MinusView::MinusView(const IntView& y)
00048     : DerivedView<IntView>(y) {}
00049 
00050 
00051   /*
00052    * Value access
00053    *
00054    */
00055   forceinline int
00056   MinusView::min(void) const {
00057     return -x.max();
00058   }
00059   forceinline int
00060   MinusView::max(void) const {
00061     return -x.min();
00062   }
00063   forceinline int
00064   MinusView::val(void) const {
00065     return -x.val();
00066   }
00067 
00068   forceinline unsigned int
00069   MinusView::width(void) const {
00070     return x.width();
00071   }
00072   forceinline unsigned int
00073   MinusView::size(void) const {
00074     return x.size();
00075   }
00076   forceinline unsigned int
00077   MinusView::regret_min(void) const {
00078     return x.regret_max();
00079   }
00080   forceinline unsigned int
00081   MinusView::regret_max(void) const {
00082     return x.regret_min();
00083   }
00084 
00085 
00086   /*
00087    * Domain tests
00088    *
00089    */
00090   forceinline bool
00091   MinusView::range(void) const {
00092     return x.range();
00093   }
00094   forceinline bool
00095   MinusView::in(int n) const {
00096     return x.in(-n);
00097   }
00098   forceinline bool
00099   MinusView::in(long long int n) const {
00100     return x.in(-n);
00101   }
00102 
00103 
00104   /*
00105    * Domain update by value
00106    *
00107    */
00108   forceinline ModEvent
00109   MinusView::lq(Space& home, int n) {
00110     return x.gq(home,-n);
00111   }
00112   forceinline ModEvent
00113   MinusView::lq(Space& home, long long int n) {
00114     return x.gq(home,-n);
00115   }
00116 
00117   forceinline ModEvent
00118   MinusView::le(Space& home, int n) {
00119     return x.gr(home,-n);
00120   }
00121   forceinline ModEvent
00122   MinusView::le(Space& home, long long int n) {
00123     return x.gr(home,-n);
00124   }
00125 
00126   forceinline ModEvent
00127   MinusView::gq(Space& home, int n) {
00128     return x.lq(home,-n);
00129   }
00130   forceinline ModEvent
00131   MinusView::gq(Space& home, long long int n) {
00132     return x.lq(home,-n);
00133   }
00134 
00135   forceinline ModEvent
00136   MinusView::gr(Space& home, int n) {
00137     return x.le(home,-n);
00138   }
00139   forceinline ModEvent
00140   MinusView::gr(Space& home, long long int n) {
00141     return x.le(home,-n);
00142   }
00143 
00144   forceinline ModEvent
00145   MinusView::nq(Space& home, int n) {
00146     return x.nq(home,-n);
00147   }
00148   forceinline ModEvent
00149   MinusView::nq(Space& home, long long int n) {
00150     return x.nq(home,-n);
00151   }
00152 
00153   forceinline ModEvent
00154   MinusView::eq(Space& home, int n) {
00155     return x.eq(home,-n);
00156   }
00157   forceinline ModEvent
00158   MinusView::eq(Space& home, long long int n) {
00159     return x.eq(home,-n);
00160   }
00161 
00162 
00163   /*
00164    * Iterator-based domain update
00165    *
00166    */
00167   template<class I>
00168   forceinline ModEvent
00169   MinusView::narrow_r(Space& home, I& i, bool) {
00170     Region r(home);
00171     Iter::Ranges::Minus mi(r,i);
00172     return x.narrow_r(home,mi,false);
00173   }
00174   template<class I>
00175   forceinline ModEvent
00176   MinusView::inter_r(Space& home, I& i, bool) {
00177     Region r(home);
00178     Iter::Ranges::Minus mi(r,i);
00179     return x.inter_r(home,mi,false);
00180   }
00181   template<class I>
00182   forceinline ModEvent
00183   MinusView::minus_r(Space& home, I& i, bool) {
00184     Region r(home);
00185     Iter::Ranges::Minus mi(r,i);
00186     return x.minus_r(home,mi,false);
00187   }
00188   template<class I>
00189   forceinline ModEvent
00190   MinusView::narrow_v(Space& home, I& i, bool) {
00191     Region r(home);
00192     Iter::Values::Minus mi(r,i);
00193     return x.narrow_v(home,mi,false);
00194   }
00195   template<class I>
00196   forceinline ModEvent
00197   MinusView::inter_v(Space& home, I& i, bool) {
00198     Region r(home);
00199     Iter::Values::Minus mi(r,i);
00200     return x.inter_v(home,mi,false);
00201   }
00202   template<class I>
00203   forceinline ModEvent
00204   MinusView::minus_v(Space& home, I& i, bool) {
00205     Region r(home);
00206     Iter::Values::Minus mi(r,i);
00207     return x.minus_v(home,mi,false);
00208   }
00209 
00210 
00211   /*
00212    * Propagator modification events
00213    *
00214    */
00215   forceinline ModEventDelta
00216   MinusView::med(ModEvent me) {
00217     return IntView::med(me);
00218   }
00219 
00220 
00221   /*
00222    * Delta information for advisors
00223    *
00224    */
00225   forceinline int
00226   MinusView::min(const Delta& d) const {
00227     return -x.max(d);
00228   }
00229   forceinline int
00230   MinusView::max(const Delta& d) const {
00231     return -x.min(d);
00232   }
00233   forceinline bool
00234   MinusView::any(const Delta& d) const {
00235     return x.any(d);
00236   }
00237 
00238 
00243   template<>
00244   class ViewRanges<MinusView> : public IntVarImpBwd {
00245   public:
00247 
00248 
00249     ViewRanges(void);
00251     ViewRanges(const MinusView& x);
00253     void init(const MinusView& x);
00255 
00257 
00258 
00259     int min(void) const;
00261     int max(void) const;
00263   };
00264 
00265   forceinline
00266   ViewRanges<MinusView>::ViewRanges(void) {}
00267 
00268   forceinline
00269   ViewRanges<MinusView>::ViewRanges(const MinusView& x)
00270     : IntVarImpBwd(x.base().varimp()) {}
00271 
00272   forceinline void
00273   ViewRanges<MinusView>::init(const MinusView& x) {
00274     IntVarImpBwd::init(x.base().varimp());
00275   }
00276 
00277   forceinline int
00278   ViewRanges<MinusView>::min(void) const {
00279     return -IntVarImpBwd::max();
00280   }
00281   forceinline int
00282   ViewRanges<MinusView>::max(void) const {
00283     return -IntVarImpBwd::min();
00284   }
00285 
00286   inline int
00287   MinusView::med(void) const {
00288     if (x.range())
00289       return (min()+max())/2 - ((min()+max())%2 < 0 ? 1 : 0);
00290 
00291     unsigned int i = x.size() / 2;
00292     if (size() % 2 == 0)
00293       i--;
00294     ViewRanges<MinusView> r(*this);
00295     while (i >= r.width()) {
00296       i -= r.width();
00297       ++r;
00298     }
00299     return r.min() + static_cast<int>(i);
00300   }
00301 
00302 }}
00303 
00304 // STATISTICS: int-var
00305