Generated on Mon Nov 30 23:53:30 2009 for Gecode by doxygen 1.6.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: 2009-09-08 21:10:29 +0200 (Tue, 08 Sep 2009) $ by $Author: schulte $
00011  *     $Revision: 9692 $
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 {
00039 
00040   namespace Int {
00041 
00042     /*
00043      * Constructors and initialization
00044      *
00045      */
00046     forceinline
00047     ConstIntView::ConstIntView(void) {}
00048     forceinline
00049     ConstIntView::ConstIntView(int n) : x(n) {}
00050     forceinline void
00051     ConstIntView::init(int n) {
00052       x=n;
00053     }
00054 
00055 
00056     /*
00057      * Value access
00058      *
00059      */
00060     forceinline int
00061     ConstIntView::min(void) const {
00062       return x;
00063     }
00064     forceinline int
00065     ConstIntView::max(void) const {
00066       return x;
00067     }
00068     forceinline int
00069     ConstIntView::med(void) const {
00070       return x;
00071     }
00072     forceinline int
00073     ConstIntView::val(void) const {
00074       return x;
00075     }
00076 
00077     forceinline unsigned int
00078     ConstIntView::size(void) const {
00079       return 1;
00080     }
00081     forceinline unsigned int
00082     ConstIntView::width(void) const {
00083       return 1;
00084     }
00085     forceinline unsigned int
00086     ConstIntView::regret_min(void) const {
00087       return 0;
00088     }
00089     forceinline unsigned int
00090     ConstIntView::regret_max(void) const {
00091       return 0;
00092     }
00093 
00094 
00095     /*
00096      * Domain tests
00097      *
00098      */
00099     forceinline bool
00100     ConstIntView::range(void) const {
00101       return true;
00102     }
00103     forceinline bool
00104     ConstIntView::assigned(void) const {
00105       return true;
00106     }
00107 
00108     forceinline bool
00109     ConstIntView::in(int n) const {
00110       return n == x;
00111     }
00112     forceinline bool
00113     ConstIntView::in(double n) const {
00114       return n == x;
00115     }
00116 
00117 
00118     /*
00119      * Domain update by value
00120      *
00121      */
00122     forceinline ModEvent
00123     ConstIntView::lq(Space&, int n) {
00124       return (x <= n) ? ME_INT_NONE : ME_INT_FAILED;
00125     }
00126     forceinline ModEvent
00127     ConstIntView::lq(Space&, double n) {
00128       return (x <= n) ? ME_INT_NONE : ME_INT_FAILED;
00129     }
00130 
00131     forceinline ModEvent
00132     ConstIntView::le(Space&, int n) {
00133       return (x < n) ? ME_INT_NONE : ME_INT_FAILED;
00134     }
00135     forceinline ModEvent
00136     ConstIntView::le(Space&, double n) {
00137       return (x < n) ? ME_INT_NONE : ME_INT_FAILED;
00138     }
00139 
00140     forceinline ModEvent
00141     ConstIntView::gq(Space&, int n) {
00142       return (x >= n) ? ME_INT_NONE : ME_INT_FAILED;
00143     }
00144     forceinline ModEvent
00145     ConstIntView::gq(Space&, double n) {
00146       return (x >= n) ? ME_INT_NONE : ME_INT_FAILED;
00147     }
00148 
00149     forceinline ModEvent
00150     ConstIntView::gr(Space&, int n) {
00151       return (x > n) ? ME_INT_NONE : ME_INT_FAILED;
00152     }
00153     forceinline ModEvent
00154     ConstIntView::gr(Space&, double n) {
00155       return (x > n) ? ME_INT_NONE : ME_INT_FAILED;
00156     }
00157 
00158     forceinline ModEvent
00159     ConstIntView::nq(Space&, int n) {
00160       return (x != n) ? ME_INT_NONE : ME_INT_FAILED;
00161     }
00162     forceinline ModEvent
00163     ConstIntView::nq(Space&, double n) {
00164       return (x != n) ? ME_INT_NONE : ME_INT_FAILED;
00165     }
00166 
00167     forceinline ModEvent
00168     ConstIntView::eq(Space&, int n) {
00169       return (x == n) ? ME_INT_NONE : ME_INT_FAILED;
00170     }
00171     forceinline ModEvent
00172     ConstIntView::eq(Space&, double n) {
00173       return (x == n) ? ME_INT_NONE : ME_INT_FAILED;
00174     }
00175 
00176 
00177 
00178     /*
00179      * Iterator-based domain update
00180      *
00181      */
00182     template<class I>
00183     forceinline ModEvent
00184     ConstIntView::narrow_r(Space&, I& i, bool) {
00185       Iter::Ranges::IsRangeIter<I>();
00186       return i() ? ME_INT_NONE : ME_INT_FAILED;
00187     }
00188     template<class I>
00189     forceinline ModEvent
00190     ConstIntView::inter_r(Space&, I& i, bool) {
00191       Iter::Ranges::IsRangeIter<I>();
00192       while (i() && (i.max() < x))
00193         ++i;
00194       return (i() && (i.min() <= x)) ? ME_INT_NONE : ME_INT_FAILED;
00195     }
00196     template<class I>
00197     forceinline ModEvent
00198     ConstIntView::minus_r(Space&, I& i, bool) {
00199       Iter::Ranges::IsRangeIter<I>();
00200       while (i() && (i.max() < x))
00201         ++i;
00202       return (i() && (i.min() <= x)) ? ME_INT_FAILED : ME_INT_NONE;
00203     }
00204     template<class I>
00205     forceinline ModEvent
00206     ConstIntView::narrow_v(Space&, I& i, bool) {
00207       Iter::Values::IsValueIter<I>();
00208       return i() ? ME_INT_NONE : ME_INT_FAILED;
00209     }
00210     template<class I>
00211     forceinline ModEvent
00212     ConstIntView::inter_v(Space&, I& i, bool) {
00213       Iter::Values::IsValueIter<I>();
00214       while (i() && (i.val() < x))
00215         ++i;
00216       return (i() && (i.val() == x)) ? ME_INT_NONE : ME_INT_FAILED;
00217     }
00218     template<class I>
00219     forceinline ModEvent
00220     ConstIntView::minus_v(Space&, I& i, bool) {
00221       Iter::Values::IsValueIter<I>();
00222       while (i() && (i.val() < x))
00223         ++i;
00224       return (i() && (i.val() == x)) ? ME_INT_FAILED : ME_INT_NONE;
00225     }
00226 
00227 
00228 
00229     /*
00230      * Propagator modification events
00231      *
00232      */
00233     forceinline void
00234     ConstIntView::schedule(Space& home, Propagator& p, ModEvent me) {
00235       return IntView::schedule(home,p,me);
00236     }
00237     forceinline ModEvent
00238     ConstIntView::me(const ModEventDelta&) {
00239       return ME_INT_NONE;
00240     }
00241     forceinline ModEventDelta
00242     ConstIntView::med(ModEvent me) {
00243       return static_cast<ModEventDelta>(me);
00244     }
00245 
00246 
00247     /*
00248      * Dependencies
00249      *
00250      */
00251     forceinline void
00252     ConstIntView::subscribe(Space& home, Propagator& p, PropCond,bool) {
00253       schedule(home,p,ME_INT_VAL);
00254     }
00255     forceinline void
00256     ConstIntView::cancel(Space&,Propagator&,PropCond) {}
00257     forceinline void
00258     ConstIntView::subscribe(Space&, Advisor&) {}
00259     forceinline void
00260     ConstIntView::cancel(Space&,Advisor&) {}
00261 
00262 
00263 
00264     /*
00265      * Delta information for advisors
00266      *
00267      */
00268     forceinline ModEvent
00269     ConstIntView::modevent(const Delta&) {
00270       return ME_INT_NONE;
00271     }
00272     forceinline int
00273     ConstIntView::min(const Delta&) const {
00274       return 1;
00275     }
00276     forceinline int
00277     ConstIntView::max(const Delta&) const {
00278       return 0;
00279     }
00280     forceinline bool
00281     ConstIntView::any(const Delta&) const {
00282       return true;
00283     }
00284 
00285 
00286 
00287     /*
00288      * Cloning
00289      *
00290      */
00291     forceinline void
00292     ConstIntView::update(Space&, bool, ConstIntView& y) {
00293       x = y.x;
00294     }
00295 
00296 
00301     template<>
00302     class ViewRanges<ConstIntView> {
00303     private:
00305       int n;
00306     public:
00308 
00309 
00310       ViewRanges(void);
00312       ViewRanges(const ConstIntView& x);
00314       void init(const ConstIntView& x);
00316 
00318 
00319 
00320       bool operator ()(void) const;
00322       void operator ++(void);
00324 
00326 
00327 
00328       int min(void) const;
00330       int max(void) const;
00332       unsigned int width(void) const;
00334     };
00335 
00336     forceinline
00337     ViewRanges<ConstIntView>::ViewRanges(void) {}
00338 
00339     forceinline
00340     ViewRanges<ConstIntView>::ViewRanges(const ConstIntView& x)
00341       : n(x.val()) {}
00342 
00343     forceinline bool
00344     ViewRanges<ConstIntView>::operator ()(void) const {
00345       return n <= Limits::max;
00346     }
00347     forceinline void
00348     ViewRanges<ConstIntView>::operator ++(void) {
00349       n = Limits::max+1;
00350     }
00351 
00352     forceinline int
00353     ViewRanges<ConstIntView>::min(void) const {
00354       return n;
00355     }
00356     forceinline int
00357     ViewRanges<ConstIntView>::max(void) const {
00358       return n;
00359     }
00360     forceinline unsigned int
00361     ViewRanges<ConstIntView>::width(void) const {
00362       return 1;
00363     }
00364 
00365   }
00366 
00367   /*
00368    * View comparison
00369    *
00370    */
00371   forceinline bool
00372   same(const Int::ConstIntView& x, const Int::ConstIntView& y) {
00373     return x.min() == y.min();
00374   }
00375   forceinline bool
00376   same(const Int::IntView&, const Int::ConstIntView&) {
00377     return false;
00378   }
00379   forceinline bool
00380   same(const Int::BoolView&, const Int::ConstIntView&) {
00381     return false;
00382   }
00383   forceinline bool
00384   before(const Int::ConstIntView& x, const Int::ConstIntView& y) {
00385     return x.min() < y.min();
00386   }
00387 
00388 }
00389 
00390 // STATISTICS: int-var
00391