Generated on Wed Nov 1 15:04:40 2006 for Gecode by doxygen 1.4.5

constint.icc

Go to the documentation of this file.
00001 /*
00002  *  Main authors:
00003  *     Christian Schulte <schulte@gecode.org>
00004  *
00005  *  Copyright:
00006  *     Christian Schulte, 2003
00007  *
00008  *  Last modified:
00009  *     $Date: 2006-08-24 11:25:05 +0200 (Thu, 24 Aug 2006) $ by $Author: schulte $
00010  *     $Revision: 3559 $
00011  *
00012  *  This file is part of Gecode, the generic constraint
00013  *  development environment:
00014  *     http://www.gecode.org
00015  *
00016  *  See the file "LICENSE" for information on usage and
00017  *  redistribution of this file, and for a
00018  *     DISCLAIMER OF ALL WARRANTIES.
00019  *
00020  */
00021 
00022 namespace Gecode {
00023 
00024   namespace Int {
00025 
00026     /*
00027      * Constructors and initialization
00028      *
00029      */
00030     forceinline
00031     ConstIntView::ConstIntView(void) {}
00032     forceinline
00033     ConstIntView::ConstIntView(int n) : x(n) {}
00034     forceinline void
00035     ConstIntView::init(int n) {
00036       x=n;
00037     }
00038 
00039 
00040     /*
00041      * Value access
00042      *
00043      */
00044     forceinline int
00045     ConstIntView::min(void) const {
00046       return x;
00047     }
00048     forceinline int
00049     ConstIntView::max(void) const {
00050       return x;
00051     }
00052     forceinline int
00053     ConstIntView::med(void) const {
00054       return x;
00055     }
00056     forceinline int
00057     ConstIntView::val(void) const {
00058       return x;
00059     }
00060 
00061     forceinline unsigned int
00062     ConstIntView::size(void) const {
00063       return 1;
00064     }
00065     forceinline unsigned int
00066     ConstIntView::width(void) const {
00067       return 1;
00068     }
00069     forceinline unsigned int
00070     ConstIntView::regret_min(void) const {
00071       return 0;
00072     }
00073     forceinline unsigned int
00074     ConstIntView::regret_max(void) const {
00075       return 0;
00076     }
00077 
00078 
00079     /*
00080      * Domain tests
00081      *
00082      */
00083     forceinline bool
00084     ConstIntView::range(void) const {
00085       return true;
00086     }
00087     forceinline bool
00088     ConstIntView::assigned(void) const {
00089       return true;
00090     }
00091 
00092     forceinline bool
00093     ConstIntView::in(int n) const {
00094       return n == x;
00095     }
00096     forceinline bool
00097     ConstIntView::in(double 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*, double 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*, double 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*, double 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*, double 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*, double 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*, double n) {
00157       return (x == n) ? ME_INT_NONE : ME_INT_FAILED;
00158     }
00159 
00160 
00161 
00162     /*
00163      * Domain update by range iterator
00164      *
00165      */
00166     template <class I>
00167     forceinline ModEvent
00168     ConstIntView::narrow(Space*, I& i) {
00169       return i() ? ME_INT_NONE : ME_INT_FAILED;
00170     }
00171     template <class I>
00172     ModEvent
00173     ConstIntView::inter(Space*, I& i) {
00174       while (i() && (i.max() < x)) ++i;
00175       return (i() && (i.min() <= x)) ? ME_INT_NONE : ME_INT_FAILED;
00176     }
00177     template <class I>
00178     ModEvent
00179     ConstIntView::minus(Space*, I& i) {
00180       while (i() && (i.max() < x)) ++i;
00181       return (i() && (i.min() <= x)) ? ME_INT_FAILED : ME_INT_NONE;
00182     }
00183 
00184 
00185 
00186     /*
00187      * Propagator modification events
00188      *
00189      */
00190     forceinline ModEvent
00191     ConstIntView::pme(const Propagator*) {
00192       return ME_INT_NONE;
00193     }
00194     forceinline PropModEvent
00195     ConstIntView::pme(ModEvent me) {
00196       return static_cast<PropModEvent>(me);
00197     }
00198 
00199 
00200     /*
00201      * Dependencies
00202      *
00203      */
00204     forceinline void
00205     ConstIntView::subscribe(Space*,Propagator*,PropCond,bool) {}
00206     forceinline void
00207     ConstIntView::cancel(Space* home, Propagator*,PropCond) {}
00208 
00209 
00210 
00211     /*
00212      * Cloning
00213      *
00214      */
00215     forceinline void
00216     ConstIntView::update(Space*, bool, ConstIntView& y) {
00217       x = y.x;
00218     }
00219 
00224     template <>
00225     class ViewRanges<ConstIntView> {
00226     private:
00228       int n;
00229     public:
00231 
00232 
00233       ViewRanges(void);
00235       ViewRanges(const ConstIntView& x);
00237       void init(const ConstIntView& x);
00239 
00241 
00242 
00243       bool operator()(void) const;
00245       void operator++(void);
00247 
00249 
00250 
00251       int min(void) const;
00253       int max(void) const;
00255       unsigned int width(void) const;
00257     };
00258 
00259     forceinline
00260     ViewRanges<ConstIntView>::ViewRanges(void) {}
00261 
00262     forceinline
00263     ViewRanges<ConstIntView>::ViewRanges(const ConstIntView& x)
00264       : n(x.val()) {}
00265 
00266     forceinline bool
00267     ViewRanges<ConstIntView>::operator()(void) const {
00268       return n < Limits::Int::int_max;
00269     }
00270     forceinline void
00271     ViewRanges<ConstIntView>::operator++(void) {
00272       n = Limits::Int::int_max;
00273     }
00274 
00275     forceinline int
00276     ViewRanges<ConstIntView>::min(void) const {
00277       return n;
00278     }
00279     forceinline int
00280     ViewRanges<ConstIntView>::max(void) const {
00281       return n;
00282     }
00283     forceinline unsigned int
00284     ViewRanges<ConstIntView>::width(void) const {
00285       return 1;
00286     }
00287 
00288   }
00289 
00290   /*
00291    * View comparison
00292    *
00293    */
00294   forceinline bool
00295   same(const Int::ConstIntView& x, const Int::ConstIntView& y) {
00296     return x.min() == y.min();
00297   }
00298   forceinline bool
00299   before(const Int::ConstIntView& x, const Int::ConstIntView& y) {
00300     return x.min() < y.min();
00301   }
00302 
00303 }
00304 
00305 // STATISTICS: int-var
00306