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