Generated on Sun Feb 17 15:24:23 2019 for Gecode by doxygen 1.6.3

zero.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  *  This file is part of Gecode, the generic constraint
00010  *  development environment:
00011  *     http://www.gecode.org
00012  *
00013  *  Permission is hereby granted, free of charge, to any person obtaining
00014  *  a copy of this software and associated documentation files (the
00015  *  "Software"), to deal in the Software without restriction, including
00016  *  without limitation the rights to use, copy, modify, merge, publish,
00017  *  distribute, sublicense, and/or sell copies of the Software, and to
00018  *  permit persons to whom the Software is furnished to do so, subject to
00019  *  the following conditions:
00020  *
00021  *  The above copyright notice and this permission notice shall be
00022  *  included in all copies or substantial portions of the Software.
00023  *
00024  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00025  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00026  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00027  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00028  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00029  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00030  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00031  *
00032  */
00033 
00034 namespace Gecode { namespace Int {
00035 
00036   /*
00037    * Constructors and initialization
00038    *
00039    */
00040   forceinline
00041   ZeroIntView::ZeroIntView(void) {}
00042 
00043   /*
00044    * Value access
00045    *
00046    */
00047   forceinline int
00048   ZeroIntView::min(void) const {
00049     return 0;
00050   }
00051   forceinline int
00052   ZeroIntView::max(void) const {
00053     return 0;
00054   }
00055   forceinline int
00056   ZeroIntView::med(void) const {
00057     return 0;
00058   }
00059   forceinline int
00060   ZeroIntView::val(void) const {
00061     return 0;
00062   }
00063 
00064   forceinline unsigned int
00065   ZeroIntView::size(void) const {
00066     return 1;
00067   }
00068   forceinline unsigned int
00069   ZeroIntView::width(void) const {
00070     return 1;
00071   }
00072   forceinline unsigned int
00073   ZeroIntView::regret_min(void) const {
00074     return 0;
00075   }
00076   forceinline unsigned int
00077   ZeroIntView::regret_max(void) const {
00078     return 0;
00079   }
00080 
00081 
00082   /*
00083    * Domain tests
00084    *
00085    */
00086   forceinline bool
00087   ZeroIntView::range(void) const {
00088     return true;
00089   }
00090   forceinline bool
00091   ZeroIntView::in(int n) const {
00092     return n == 0;
00093   }
00094   forceinline bool
00095   ZeroIntView::in(long long int n) const {
00096     return n == 0;
00097   }
00098 
00099 
00100   /*
00101    * Domain update by value
00102    *
00103    */
00104   forceinline ModEvent
00105   ZeroIntView::lq(Space&, int n) {
00106     return (0 <= n) ? ME_INT_NONE : ME_INT_FAILED;
00107   }
00108   forceinline ModEvent
00109   ZeroIntView::lq(Space&, long long int n) {
00110     return (0 <= n) ? ME_INT_NONE : ME_INT_FAILED;
00111   }
00112 
00113   forceinline ModEvent
00114   ZeroIntView::le(Space&, int n) {
00115     return (0 < n) ? ME_INT_NONE : ME_INT_FAILED;
00116   }
00117   forceinline ModEvent
00118   ZeroIntView::le(Space&, long long int n) {
00119     return (0 < n) ? ME_INT_NONE : ME_INT_FAILED;
00120   }
00121 
00122   forceinline ModEvent
00123   ZeroIntView::gq(Space&, int n) {
00124     return (0 >= n) ? ME_INT_NONE : ME_INT_FAILED;
00125   }
00126   forceinline ModEvent
00127   ZeroIntView::gq(Space&, long long int n) {
00128     return (0 >= n) ? ME_INT_NONE : ME_INT_FAILED;
00129   }
00130 
00131   forceinline ModEvent
00132   ZeroIntView::gr(Space&, int n) {
00133     return (0 > n) ? ME_INT_NONE : ME_INT_FAILED;
00134   }
00135   forceinline ModEvent
00136   ZeroIntView::gr(Space&, long long int n) {
00137     return (0 > n) ? ME_INT_NONE : ME_INT_FAILED;
00138   }
00139 
00140   forceinline ModEvent
00141   ZeroIntView::nq(Space&, int n) {
00142     return (0 != n) ? ME_INT_NONE : ME_INT_FAILED;
00143   }
00144   forceinline ModEvent
00145   ZeroIntView::nq(Space&, long long int n) {
00146     return (0 != n) ? ME_INT_NONE : ME_INT_FAILED;
00147   }
00148 
00149   forceinline ModEvent
00150   ZeroIntView::eq(Space&, int n) {
00151     return (0 == n) ? ME_INT_NONE : ME_INT_FAILED;
00152   }
00153   forceinline ModEvent
00154   ZeroIntView::eq(Space&, long long int n) {
00155     return (0 == n) ? ME_INT_NONE : ME_INT_FAILED;
00156   }
00157 
00158 
00159 
00160   /*
00161    * Iterator-based domain update
00162    *
00163    */
00164   template<class I>
00165   forceinline ModEvent
00166   ZeroIntView::narrow_r(Space&, I& i, bool) {
00167     return i() ? ME_INT_NONE : ME_INT_FAILED;
00168   }
00169   template<class I>
00170   forceinline ModEvent
00171   ZeroIntView::inter_r(Space&, I& i, bool) {
00172     while (i() && (i.max() < 0))
00173       ++i;
00174     return (i() && (i.min() <= 0)) ? ME_INT_NONE : ME_INT_FAILED;
00175   }
00176   template<class I>
00177   forceinline ModEvent
00178   ZeroIntView::minus_r(Space&, I& i, bool) {
00179     while (i() && (i.max() < 0))
00180       ++i;
00181     return (i() && (i.min() <= 0)) ? ME_INT_FAILED : ME_INT_NONE;
00182   }
00183   template<class I>
00184   forceinline ModEvent
00185   ZeroIntView::narrow_v(Space&, I& i, bool) {
00186     return i() ? ME_INT_NONE : ME_INT_FAILED;
00187   }
00188   template<class I>
00189   forceinline ModEvent
00190   ZeroIntView::inter_v(Space&, I& i, bool) {
00191     while (i() && (i.val() < 0))
00192       ++i;
00193     return (i() && (i.val() == 0)) ? ME_INT_NONE : ME_INT_FAILED;
00194   }
00195   template<class I>
00196   forceinline ModEvent
00197   ZeroIntView::minus_v(Space&, I& i, bool) {
00198     while (i() && (i.val() < 0))
00199       ++i;
00200     return (i() && (i.val() == 0)) ? ME_INT_FAILED : ME_INT_NONE;
00201   }
00202 
00203   /*
00204    * Delta information for advisors
00205    *
00206    */
00207   forceinline int
00208   ZeroIntView::min(const Delta&) const {
00209     return 1;
00210   }
00211   forceinline int
00212   ZeroIntView::max(const Delta&) const {
00213     return 0;
00214   }
00215   forceinline unsigned int
00216   ZeroIntView::width(const Delta&) const {
00217     return 1U;
00218   }
00219   forceinline bool
00220   ZeroIntView::any(const Delta&) const {
00221     return true;
00222   }
00223 
00224 
00229   template<>
00230   class ViewRanges<ZeroIntView> {
00231   private:
00233     bool done;
00234   public:
00236 
00237 
00238     ViewRanges(void);
00240     ViewRanges(const ZeroIntView& x);
00242     void init(const ZeroIntView& x);
00244 
00246 
00247 
00248     bool operator ()(void) const;
00250     void operator ++(void);
00252 
00254 
00255 
00256     int min(void) const;
00258     int max(void) const;
00260     unsigned int width(void) const;
00262   };
00263 
00264   forceinline
00265   ViewRanges<ZeroIntView>::ViewRanges(void) {}
00266 
00267   forceinline
00268   ViewRanges<ZeroIntView>::ViewRanges(const ZeroIntView&)
00269     : done(false) {}
00270 
00271   forceinline bool
00272   ViewRanges<ZeroIntView>::operator ()(void) const {
00273     return !done;
00274   }
00275   forceinline void
00276   ViewRanges<ZeroIntView>::operator ++(void) {
00277     done=true;
00278   }
00279 
00280   forceinline int
00281   ViewRanges<ZeroIntView>::min(void) const {
00282     return 0;
00283   }
00284   forceinline int
00285   ViewRanges<ZeroIntView>::max(void) const {
00286     return 0;
00287   }
00288   forceinline unsigned int
00289   ViewRanges<ZeroIntView>::width(void) const {
00290     return 1;
00291   }
00292 
00293   /*
00294    * View comparison
00295    *
00296    */
00297   forceinline bool
00298   operator ==(const ZeroIntView&, const ZeroIntView&) {
00299     return true;
00300   }
00301   forceinline bool
00302   operator !=(const ZeroIntView&, const ZeroIntView&) {
00303     return false;
00304   }
00305 
00306 }}
00307 
00308 // STATISTICS: int-var
00309