Generated on Mon May 10 06:46:41 2010 for Gecode by doxygen 1.6.3

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-11-23 15:38:32 +0100 (Mon, 23 Nov 2009) $ by $Author: schulte $
00011  *     $Revision: 10098 $
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,
00248                            bool process) {
00249       if (process)
00250         schedule(home,p,ME_INT_VAL);
00251     }
00252     forceinline void
00253     ZeroIntView::cancel(Space&,Propagator&,PropCond) {}
00254     forceinline void
00255     ZeroIntView::subscribe(Space&, Advisor&) {}
00256     forceinline void
00257     ZeroIntView::cancel(Space&,Advisor&) {}
00258 
00259 
00260 
00261     /*
00262      * Delta information for advisors
00263      *
00264      */
00265     forceinline ModEvent
00266     ZeroIntView::modevent(const Delta&) {
00267       return ME_INT_NONE;
00268     }
00269     forceinline int
00270     ZeroIntView::min(const Delta&) const {
00271       return 1;
00272     }
00273     forceinline int
00274     ZeroIntView::max(const Delta&) const {
00275       return 0;
00276     }
00277     forceinline bool
00278     ZeroIntView::any(const Delta&) const {
00279       return true;
00280     }
00281 
00282 
00283 
00284     /*
00285      * Cloning
00286      *
00287      */
00288     forceinline void
00289     ZeroIntView::update(Space&, bool, ZeroIntView&) {}
00290 
00291 
00296     template<>
00297     class ViewRanges<ZeroIntView> {
00298     private:
00300       bool done;
00301     public:
00303 
00304 
00305       ViewRanges(void);
00307       ViewRanges(const ZeroIntView& x);
00309       void init(const ZeroIntView& x);
00311 
00313 
00314 
00315       bool operator ()(void) const;
00317       void operator ++(void);
00319 
00321 
00322 
00323       int min(void) const;
00325       int max(void) const;
00327       unsigned int width(void) const;
00329     };
00330 
00331     forceinline
00332     ViewRanges<ZeroIntView>::ViewRanges(void) {}
00333 
00334     forceinline
00335     ViewRanges<ZeroIntView>::ViewRanges(const ZeroIntView&)
00336       : done(false) {}
00337 
00338     forceinline bool
00339     ViewRanges<ZeroIntView>::operator ()(void) const {
00340       return !done;
00341     }
00342     forceinline void
00343     ViewRanges<ZeroIntView>::operator ++(void) {
00344       done=true;
00345     }
00346 
00347     forceinline int
00348     ViewRanges<ZeroIntView>::min(void) const {
00349       return 0;
00350     }
00351     forceinline int
00352     ViewRanges<ZeroIntView>::max(void) const {
00353       return 0;
00354     }
00355     forceinline unsigned int
00356     ViewRanges<ZeroIntView>::width(void) const {
00357       return 1;
00358     }
00359 
00360   }
00361 
00362   /*
00363    * View comparison
00364    *
00365    */
00366   forceinline bool
00367   same(const Int::ZeroIntView&, const Int::ZeroIntView&) {
00368     return true;
00369   }
00370   forceinline bool
00371   before(const Int::ZeroIntView&, const Int::ZeroIntView&) {
00372     return false;
00373   }
00374 
00375 }
00376 
00377 // STATISTICS: int-var
00378