Generated on Tue Jul 27 2010 21:59:16 for Gecode by doxygen 1.7.1

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  *  Last modified:
00010  *     $Date: 2010-06-07 12:56:38 +0200 (Mon, 07 Jun 2010) $ by $Author: schulte $
00011  *     $Revision: 11044 $
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   ZeroIntView::ZeroIntView(void) {}
00046 
00047   /*
00048    * Value access
00049    *
00050    */
00051   forceinline int
00052   ZeroIntView::min(void) const {
00053     return 0;
00054   }
00055   forceinline int
00056   ZeroIntView::max(void) const {
00057     return 0;
00058   }
00059   forceinline int
00060   ZeroIntView::med(void) const {
00061     return 0;
00062   }
00063   forceinline int
00064   ZeroIntView::val(void) const {
00065     return 0;
00066   }
00067 
00068   forceinline unsigned int
00069   ZeroIntView::size(void) const {
00070     return 1;
00071   }
00072   forceinline unsigned int
00073   ZeroIntView::width(void) const {
00074     return 1;
00075   }
00076   forceinline unsigned int
00077   ZeroIntView::regret_min(void) const {
00078     return 0;
00079   }
00080   forceinline unsigned int
00081   ZeroIntView::regret_max(void) const {
00082     return 0;
00083   }
00084 
00085 
00086   /*
00087    * Domain tests
00088    *
00089    */
00090   forceinline bool
00091   ZeroIntView::range(void) const {
00092     return true;
00093   }
00094   forceinline bool
00095   ZeroIntView::in(int n) const {
00096     return n == 0;
00097   }
00098   forceinline bool
00099   ZeroIntView::in(double n) const {
00100     return n == 0;
00101   }
00102 
00103 
00104   /*
00105    * Domain update by value
00106    *
00107    */
00108   forceinline ModEvent
00109   ZeroIntView::lq(Space&, int n) {
00110     return (0 <= n) ? ME_INT_NONE : ME_INT_FAILED;
00111   }
00112   forceinline ModEvent
00113   ZeroIntView::lq(Space&, double n) {
00114     return (0 <= n) ? ME_INT_NONE : ME_INT_FAILED;
00115   }
00116 
00117   forceinline ModEvent
00118   ZeroIntView::le(Space&, int n) {
00119     return (0 < n) ? ME_INT_NONE : ME_INT_FAILED;
00120   }
00121   forceinline ModEvent
00122   ZeroIntView::le(Space&, double n) {
00123     return (0 < n) ? ME_INT_NONE : ME_INT_FAILED;
00124   }
00125 
00126   forceinline ModEvent
00127   ZeroIntView::gq(Space&, int n) {
00128     return (0 >= n) ? ME_INT_NONE : ME_INT_FAILED;
00129   }
00130   forceinline ModEvent
00131   ZeroIntView::gq(Space&, double n) {
00132     return (0 >= n) ? ME_INT_NONE : ME_INT_FAILED;
00133   }
00134 
00135   forceinline ModEvent
00136   ZeroIntView::gr(Space&, int n) {
00137     return (0 > n) ? ME_INT_NONE : ME_INT_FAILED;
00138   }
00139   forceinline ModEvent
00140   ZeroIntView::gr(Space&, double n) {
00141     return (0 > n) ? ME_INT_NONE : ME_INT_FAILED;
00142   }
00143 
00144   forceinline ModEvent
00145   ZeroIntView::nq(Space&, int n) {
00146     return (0 != n) ? ME_INT_NONE : ME_INT_FAILED;
00147   }
00148   forceinline ModEvent
00149   ZeroIntView::nq(Space&, double n) {
00150     return (0 != n) ? ME_INT_NONE : ME_INT_FAILED;
00151   }
00152 
00153   forceinline ModEvent
00154   ZeroIntView::eq(Space&, int n) {
00155     return (0 == n) ? ME_INT_NONE : ME_INT_FAILED;
00156   }
00157   forceinline ModEvent
00158   ZeroIntView::eq(Space&, double n) {
00159     return (0 == n) ? ME_INT_NONE : ME_INT_FAILED;
00160   }
00161 
00162 
00163 
00164   /*
00165    * Iterator-based domain update
00166    *
00167    */
00168   template<class I>
00169   forceinline ModEvent
00170   ZeroIntView::narrow_r(Space&, I& i, bool) {
00171     Iter::Ranges::IsRangeIter<I>();
00172     return i() ? ME_INT_NONE : ME_INT_FAILED;
00173   }
00174   template<class I>
00175   forceinline ModEvent
00176   ZeroIntView::inter_r(Space&, I& i, bool) {
00177     Iter::Ranges::IsRangeIter<I>();
00178     while (i() && (i.max() < 0))
00179       ++i;
00180     return (i() && (i.min() <= 0)) ? ME_INT_NONE : ME_INT_FAILED;
00181   }
00182   template<class I>
00183   forceinline ModEvent
00184   ZeroIntView::minus_r(Space&, I& i, bool) {
00185     Iter::Ranges::IsRangeIter<I>();
00186     while (i() && (i.max() < 0))
00187       ++i;
00188     return (i() && (i.min() <= 0)) ? ME_INT_FAILED : ME_INT_NONE;
00189   }
00190   template<class I>
00191   forceinline ModEvent
00192   ZeroIntView::narrow_v(Space&, I& i, bool) {
00193     Iter::Values::IsValueIter<I>();
00194     return i() ? ME_INT_NONE : ME_INT_FAILED;
00195   }
00196   template<class I>
00197   forceinline ModEvent
00198   ZeroIntView::inter_v(Space&, I& i, bool) {
00199     Iter::Values::IsValueIter<I>();
00200     while (i() && (i.val() < 0))
00201       ++i;
00202     return (i() && (i.val() == 0)) ? ME_INT_NONE : ME_INT_FAILED;
00203   }
00204   template<class I>
00205   forceinline ModEvent
00206   ZeroIntView::minus_v(Space&, I& i, bool) {
00207     Iter::Values::IsValueIter<I>();
00208     while (i() && (i.val() < 0))
00209       ++i;
00210     return (i() && (i.val() == 0)) ? ME_INT_FAILED : ME_INT_NONE;
00211   }
00212 
00213   /*
00214    * Delta information for advisors
00215    *
00216    */
00217   forceinline int
00218   ZeroIntView::min(const Delta&) const {
00219     return 1;
00220   }
00221   forceinline int
00222   ZeroIntView::max(const Delta&) const {
00223     return 0;
00224   }
00225   forceinline bool
00226   ZeroIntView::any(const Delta&) const {
00227     return true;
00228   }
00229 
00230 
00235   template<>
00236   class ViewRanges<ZeroIntView> {
00237   private:
00239     bool done;
00240   public:
00242 
00243 
00244     ViewRanges(void);
00246     ViewRanges(const ZeroIntView& x);
00248     void init(const ZeroIntView& x);
00250 
00252 
00253 
00254     bool operator ()(void) const;
00256     void operator ++(void);
00258 
00260 
00261 
00262     int min(void) const;
00264     int max(void) const;
00266     unsigned int width(void) const;
00268   };
00269 
00270   forceinline
00271   ViewRanges<ZeroIntView>::ViewRanges(void) {}
00272 
00273   forceinline
00274   ViewRanges<ZeroIntView>::ViewRanges(const ZeroIntView&)
00275     : done(false) {}
00276 
00277   forceinline bool
00278   ViewRanges<ZeroIntView>::operator ()(void) const {
00279     return !done;
00280   }
00281   forceinline void
00282   ViewRanges<ZeroIntView>::operator ++(void) {
00283     done=true;
00284   }
00285 
00286   forceinline int
00287   ViewRanges<ZeroIntView>::min(void) const {
00288     return 0;
00289   }
00290   forceinline int
00291   ViewRanges<ZeroIntView>::max(void) const {
00292     return 0;
00293   }
00294   forceinline unsigned int
00295   ViewRanges<ZeroIntView>::width(void) const {
00296     return 1;
00297   }
00298 
00299   /*
00300    * View comparison
00301    *
00302    */
00303   forceinline bool
00304   same(const ZeroIntView&, const ZeroIntView&) {
00305     return true;
00306   }
00307 
00308 }}
00309 
00310 // STATISTICS: int-var
00311