Generated on Mon Aug 25 11:35:39 2008 for Gecode by doxygen 1.5.6

constint.icc

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