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

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