Generated on Thu Apr 11 13:59:13 2019 for Gecode by doxygen 1.6.3

neg-bool.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, 2008
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    * Negated Boolean views
00042    *
00043    */
00044 
00045   /*
00046    * Constructors and initialization
00047    *
00048    */
00049   forceinline
00050   NegBoolView::NegBoolView(void) {}
00051   forceinline
00052   NegBoolView::NegBoolView(const BoolView& y)
00053     : DerivedView<BoolView>(y) {}
00054 
00055 
00056   /*
00057    * Boolean domain tests
00058    *
00059    */
00060   forceinline BoolStatus
00061   NegBoolView::status(void) const {
00062     return x.status();
00063   }
00064   forceinline bool
00065   NegBoolView::zero(void) const {
00066     return x.one();
00067   }
00068   forceinline bool
00069   NegBoolView::one(void) const {
00070     return x.zero();
00071   }
00072   forceinline bool
00073   NegBoolView::none(void) const {
00074     return x.none();
00075   }
00076 
00077 
00078   /*
00079    * Boolean assignment operations
00080    *
00081    */
00082   forceinline ModEvent
00083   NegBoolView::zero_none(Space& home) {
00084     return x.one_none(home);
00085   }
00086   forceinline ModEvent
00087   NegBoolView::one_none(Space& home) {
00088     return x.zero_none(home);
00089   }
00090 
00091   forceinline ModEvent
00092   NegBoolView::zero(Space& home) {
00093     return x.one(home);
00094   }
00095   forceinline ModEvent
00096   NegBoolView::one(Space& home) {
00097     return x.zero(home);
00098   }
00099 
00100   /* Domain update by value
00101    *
00102    */
00103 
00104   forceinline ModEvent
00105   NegBoolView::lq(Space& home, int n) {
00106     return n==0 ? x.one(home) : (n < 0 ? ME_BOOL_FAILED : ME_BOOL_NONE);
00107   }
00108   forceinline ModEvent
00109   NegBoolView::lq(Space& home, long long int n) {
00110     return n==0 ? x.one(home) : (n < 0 ? ME_BOOL_FAILED : ME_BOOL_NONE);
00111   }
00112   forceinline ModEvent
00113   NegBoolView::le(Space& home, int n) {
00114     return n==1 ? x.one(home) : (n < 1 ? ME_BOOL_FAILED : ME_BOOL_NONE);
00115   }
00116   forceinline ModEvent
00117   NegBoolView::le(Space& home, long long int n) {
00118     return n==1 ? x.one(home) : (n < 1 ? ME_BOOL_FAILED : ME_BOOL_NONE);
00119   }
00120   forceinline ModEvent
00121   NegBoolView::gq(Space& home, int n) {
00122     return n==1 ? x.zero(home) : (n <= 0 ? ME_BOOL_NONE : ME_BOOL_FAILED);
00123   }
00124   forceinline ModEvent
00125   NegBoolView::gq(Space& home, long long int n) {
00126     return n==1 ? x.zero(home) : (n <= 0 ? ME_BOOL_NONE : ME_BOOL_FAILED);
00127   }
00128   forceinline ModEvent
00129   NegBoolView::gr(Space& home, int n) {
00130     return n==0 ? x.zero(home) : (n >= 1 ? ME_BOOL_FAILED : ME_BOOL_NONE);
00131   }
00132   forceinline ModEvent
00133   NegBoolView::gr(Space& home, long long int n) {
00134     return n==0 ? x.zero(home) : (n >= 1 ? ME_BOOL_FAILED : ME_BOOL_NONE);
00135   }
00136   forceinline ModEvent
00137   NegBoolView::nq(Space& home, int n) {
00138     return n==0 ? x.zero(home) : (n==1 ? x.one(home) : ME_BOOL_NONE);
00139   }
00140   forceinline ModEvent
00141   NegBoolView::nq(Space& home, long long int n) {
00142     return n==0 ? x.zero(home) : (n==1 ? x.one(home) : ME_BOOL_NONE);
00143   }
00144   forceinline ModEvent
00145   NegBoolView::eq(Space& home, int n) {
00146     return n==0 ? x.one(home) : (n==1 ? x.zero(home) : ME_BOOL_FAILED);
00147   }
00148   forceinline ModEvent
00149   NegBoolView::eq(Space& home, long long int n) {
00150     return n==0 ? x.one(home) : (n==1 ? x.zero(home) : ME_BOOL_FAILED);
00151   }
00152   
00153   /*
00154    * Value access
00155    *
00156    */
00157   forceinline int
00158   NegBoolView::min(void) const {
00159     return 1-x.max();
00160   }
00161   forceinline int
00162   NegBoolView::max(void) const {
00163     return 1-x.min();
00164   }
00165   forceinline int
00166   NegBoolView::val(void) const {
00167     return 1-x.val();
00168   }
00169 #ifdef GECODE_HAS_CBS
00170   forceinline int
00171   NegBoolView::baseval(int val) const {
00172     return 1-val;
00173   }
00174 #endif
00175 
00176 
00177   /*
00178    * Delta information for advisors
00179    *
00180    */
00181   forceinline int
00182   NegBoolView::min(const Delta& d) const {
00183     return x.max(d);
00184   }
00185   forceinline int
00186   NegBoolView::max(const Delta& d) const {
00187     return x.min(d);
00188   }
00189   forceinline unsigned int
00190   NegBoolView::width(const Delta& d) const {
00191     return x.width(d);
00192   }
00193   forceinline bool
00194   NegBoolView::any(const Delta& d) const {
00195     return x.any(d);
00196   }
00197   forceinline bool
00198   NegBoolView::zero(const Delta& d) {
00199     return BoolView::one(d);
00200   }
00201   forceinline bool
00202   NegBoolView::one(const Delta& d) {
00203     return BoolView::zero(d);
00204   }
00205 
00206   /*
00207    * View comparison
00208    *
00209    */
00210   forceinline bool
00211   operator ==(const NegBoolView& x, const NegBoolView& y) {
00212     return x.base() == y.base();
00213   }
00214   forceinline bool
00215   operator !=(const NegBoolView& x, const NegBoolView& y) {
00216     return !(x == y);
00217   }
00218 
00219 
00224   template<>
00225   class ViewRanges<NegBoolView> : public Iter::Ranges::Singleton {
00226   public:
00228 
00229 
00230     ViewRanges(void);
00232     ViewRanges(const NegBoolView& x);
00234     void init(const NegBoolView& x);
00236   };
00237 
00238   forceinline
00239   ViewRanges<NegBoolView>::ViewRanges(void) {}
00240 
00241   forceinline
00242   ViewRanges<NegBoolView>::ViewRanges(const NegBoolView& x)
00243     : Iter::Ranges::Singleton(x.min(),x.max()) {}
00244 
00245   forceinline void
00246   ViewRanges<NegBoolView>::init(const NegBoolView& x) {
00247     Iter::Ranges::Singleton::init(x.min(),x.max());
00248   }
00249 
00250 }}
00251 
00252 // STATISTICS: int-var