Generated on Tue Apr 18 10:22:02 2017 for Gecode by doxygen 1.6.3

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: 2013-02-14 16:29:11 +0100 (Thu, 14 Feb 2013) $ by $Author: schulte $
00011  *     $Revision: 13292 $
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(long long int 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&, long long int 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&, long long int 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&, long long int 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&, long long int 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&, long long int 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&, long long int 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     return i() ? ME_INT_NONE : ME_INT_FAILED;
00174   }
00175   template<class I>
00176   forceinline ModEvent
00177   ConstIntView::inter_r(Space&, I& i, bool) {
00178     while (i() && (i.max() < x))
00179       ++i;
00180     return (i() && (i.min() <= x)) ? ME_INT_NONE : ME_INT_FAILED;
00181   }
00182   template<class I>
00183   forceinline ModEvent
00184   ConstIntView::minus_r(Space&, I& i, bool) {
00185     while (i() && (i.max() < x))
00186       ++i;
00187     return (i() && (i.min() <= x)) ? ME_INT_FAILED : ME_INT_NONE;
00188   }
00189   template<class I>
00190   forceinline ModEvent
00191   ConstIntView::narrow_v(Space&, I& i, bool) {
00192     return i() ? ME_INT_NONE : ME_INT_FAILED;
00193   }
00194   template<class I>
00195   forceinline ModEvent
00196   ConstIntView::inter_v(Space&, I& i, bool) {
00197     while (i() && (i.val() < x))
00198       ++i;
00199     return (i() && (i.val() == x)) ? ME_INT_NONE : ME_INT_FAILED;
00200   }
00201   template<class I>
00202   forceinline ModEvent
00203   ConstIntView::minus_v(Space&, I& i, bool) {
00204     while (i() && (i.val() < x))
00205       ++i;
00206     return (i() && (i.val() == x)) ? ME_INT_FAILED : ME_INT_NONE;
00207   }
00208 
00209 
00210   /*
00211    * Delta information for advisors
00212    *
00213    */
00214   forceinline int
00215   ConstIntView::min(const Delta&) const {
00216     return 1;
00217   }
00218   forceinline int
00219   ConstIntView::max(const Delta&) const {
00220     return 0;
00221   }
00222   forceinline bool
00223   ConstIntView::any(const Delta&) const {
00224     return true;
00225   }
00226 
00227 
00228 
00229   /*
00230    * Cloning
00231    *
00232    */
00233   forceinline void
00234   ConstIntView::update(Space& home, bool share, ConstIntView& y) {
00235     ConstView<IntView>::update(home,share,y);
00236     x = y.x;
00237   }
00238 
00239 
00244   template<>
00245   class ViewRanges<ConstIntView> {
00246   private:
00248     int n;
00249   public:
00251 
00252 
00253     ViewRanges(void);
00255     ViewRanges(const ConstIntView& x);
00257     void init(const ConstIntView& x);
00259 
00261 
00262 
00263     bool operator ()(void) const;
00265     void operator ++(void);
00267 
00269 
00270 
00271     int min(void) const;
00273     int max(void) const;
00275     unsigned int width(void) const;
00277   };
00278 
00279   forceinline
00280   ViewRanges<ConstIntView>::ViewRanges(void) {}
00281 
00282   forceinline
00283   ViewRanges<ConstIntView>::ViewRanges(const ConstIntView& x)
00284     : n(x.val()) {}
00285 
00286   forceinline bool
00287   ViewRanges<ConstIntView>::operator ()(void) const {
00288     return n <= Limits::max;
00289   }
00290   forceinline void
00291   ViewRanges<ConstIntView>::operator ++(void) {
00292     n = Limits::max+1;
00293   }
00294 
00295   forceinline int
00296   ViewRanges<ConstIntView>::min(void) const {
00297     return n;
00298   }
00299   forceinline int
00300   ViewRanges<ConstIntView>::max(void) const {
00301     return n;
00302   }
00303   forceinline unsigned int
00304   ViewRanges<ConstIntView>::width(void) const {
00305     return 1;
00306   }
00307 
00308   /*
00309    * View comparison
00310    *
00311    */
00312   forceinline bool
00313   same(const ConstIntView& x, const ConstIntView& y) {
00314     return x.min() == y.min();
00315   }
00316   forceinline bool
00317   before(const ConstIntView& x, const ConstIntView& y) {
00318     return x.min() < y.min();
00319   }
00320 
00321 }}
00322 
00323 // STATISTICS: int-var
00324