Generated on Fri Oct 19 11:24:59 2018 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  *  Contributing authors:
00007  *     Samuel Gagnon <samuel.gagnon92@gmail.com>
00008  *
00009  *  Copyright:
00010  *     Christian Schulte, 2003
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 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 #ifdef GECODE_HAS_CBS
00068   forceinline int
00069   MinusView::baseval(int val) const {
00070     return -val;
00071   }
00072 #endif
00073 
00074   forceinline unsigned int
00075   MinusView::width(void) const {
00076     return x.width();
00077   }
00078   forceinline unsigned int
00079   MinusView::size(void) const {
00080     return x.size();
00081   }
00082   forceinline unsigned int
00083   MinusView::regret_min(void) const {
00084     return x.regret_max();
00085   }
00086   forceinline unsigned int
00087   MinusView::regret_max(void) const {
00088     return x.regret_min();
00089   }
00090 
00091 
00092   /*
00093    * Domain tests
00094    *
00095    */
00096   forceinline bool
00097   MinusView::range(void) const {
00098     return x.range();
00099   }
00100   forceinline bool
00101   MinusView::in(int n) const {
00102     return x.in(-n);
00103   }
00104   forceinline bool
00105   MinusView::in(long long int n) const {
00106     return x.in(-n);
00107   }
00108 
00109 
00110   /*
00111    * Domain update by value
00112    *
00113    */
00114   forceinline ModEvent
00115   MinusView::lq(Space& home, int n) {
00116     return x.gq(home,-n);
00117   }
00118   forceinline ModEvent
00119   MinusView::lq(Space& home, long long int n) {
00120     return x.gq(home,-n);
00121   }
00122 
00123   forceinline ModEvent
00124   MinusView::le(Space& home, int n) {
00125     return x.gr(home,-n);
00126   }
00127   forceinline ModEvent
00128   MinusView::le(Space& home, long long int n) {
00129     return x.gr(home,-n);
00130   }
00131 
00132   forceinline ModEvent
00133   MinusView::gq(Space& home, int n) {
00134     return x.lq(home,-n);
00135   }
00136   forceinline ModEvent
00137   MinusView::gq(Space& home, long long int n) {
00138     return x.lq(home,-n);
00139   }
00140 
00141   forceinline ModEvent
00142   MinusView::gr(Space& home, int n) {
00143     return x.le(home,-n);
00144   }
00145   forceinline ModEvent
00146   MinusView::gr(Space& home, long long int n) {
00147     return x.le(home,-n);
00148   }
00149 
00150   forceinline ModEvent
00151   MinusView::nq(Space& home, int n) {
00152     return x.nq(home,-n);
00153   }
00154   forceinline ModEvent
00155   MinusView::nq(Space& home, long long int n) {
00156     return x.nq(home,-n);
00157   }
00158 
00159   forceinline ModEvent
00160   MinusView::eq(Space& home, int n) {
00161     return x.eq(home,-n);
00162   }
00163   forceinline ModEvent
00164   MinusView::eq(Space& home, long long int n) {
00165     return x.eq(home,-n);
00166   }
00167 
00168 
00169   /*
00170    * Iterator-based domain update
00171    *
00172    */
00173   template<class I>
00174   forceinline ModEvent
00175   MinusView::narrow_r(Space& home, I& i, bool) {
00176     Region r;
00177     Iter::Ranges::Minus mi(r,i);
00178     return x.narrow_r(home,mi,false);
00179   }
00180   template<class I>
00181   forceinline ModEvent
00182   MinusView::inter_r(Space& home, I& i, bool) {
00183     Region r;
00184     Iter::Ranges::Minus mi(r,i);
00185     return x.inter_r(home,mi,false);
00186   }
00187   template<class I>
00188   forceinline ModEvent
00189   MinusView::minus_r(Space& home, I& i, bool) {
00190     Region r;
00191     Iter::Ranges::Minus mi(r,i);
00192     return x.minus_r(home,mi,false);
00193   }
00194   template<class I>
00195   forceinline ModEvent
00196   MinusView::narrow_v(Space& home, I& i, bool) {
00197     Region r;
00198     Iter::Values::Minus mi(r,i);
00199     return x.narrow_v(home,mi,false);
00200   }
00201   template<class I>
00202   forceinline ModEvent
00203   MinusView::inter_v(Space& home, I& i, bool) {
00204     Region r;
00205     Iter::Values::Minus mi(r,i);
00206     return x.inter_v(home,mi,false);
00207   }
00208   template<class I>
00209   forceinline ModEvent
00210   MinusView::minus_v(Space& home, I& i, bool) {
00211     Region r;
00212     Iter::Values::Minus mi(r,i);
00213     return x.minus_v(home,mi,false);
00214   }
00215 
00216 
00217   /*
00218    * Propagator modification events
00219    *
00220    */
00221   forceinline ModEventDelta
00222   MinusView::med(ModEvent me) {
00223     return IntView::med(me);
00224   }
00225 
00226 
00227   /*
00228    * Delta information for advisors
00229    *
00230    */
00231   forceinline int
00232   MinusView::min(const Delta& d) const {
00233     return -x.max(d);
00234   }
00235   forceinline int
00236   MinusView::max(const Delta& d) const {
00237     return -x.min(d);
00238   }
00239   forceinline unsigned int
00240   MinusView::width(const Delta& d) const {
00241     return x.width(d);
00242   }
00243   forceinline bool
00244   MinusView::any(const Delta& d) const {
00245     return x.any(d);
00246   }
00247 
00248 
00253   template<>
00254   class ViewRanges<MinusView> : public IntVarImpBwd {
00255   public:
00257 
00258 
00259     ViewRanges(void);
00261     ViewRanges(const MinusView& x);
00263     void init(const MinusView& x);
00265 
00267 
00268 
00269     int min(void) const;
00271     int max(void) const;
00273   };
00274 
00275   forceinline
00276   ViewRanges<MinusView>::ViewRanges(void) {}
00277 
00278   forceinline
00279   ViewRanges<MinusView>::ViewRanges(const MinusView& x)
00280     : IntVarImpBwd(x.base().varimp()) {}
00281 
00282   forceinline void
00283   ViewRanges<MinusView>::init(const MinusView& x) {
00284     IntVarImpBwd::init(x.base().varimp());
00285   }
00286 
00287   forceinline int
00288   ViewRanges<MinusView>::min(void) const {
00289     return -IntVarImpBwd::max();
00290   }
00291   forceinline int
00292   ViewRanges<MinusView>::max(void) const {
00293     return -IntVarImpBwd::min();
00294   }
00295 
00296   inline int
00297   MinusView::med(void) const {
00298     if (x.range())
00299       return (min()+max())/2 - ((min()+max())%2 < 0 ? 1 : 0);
00300 
00301     unsigned int i = x.size() / 2;
00302     if (size() % 2 == 0)
00303       i--;
00304     ViewRanges<MinusView> r(*this);
00305     while (i >= r.width()) {
00306       i -= r.width();
00307       ++r;
00308     }
00309     return r.min() + static_cast<int>(i);
00310   }
00311 
00312   /*
00313    * View comparison
00314    *
00315    */
00316   forceinline bool
00317   operator ==(const MinusView& x, const MinusView& y) {
00318     return x.base() == y.base();
00319   }
00320   forceinline bool
00321   operator !=(const MinusView& x, const MinusView& y) {
00322     return !(x == y);
00323   }
00324 
00325 }}
00326 
00327 // STATISTICS: int-var
00328