Generated on Mon Nov 30 23:53:31 2009 for Gecode by doxygen 1.6.1

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