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

singleton.icc

Go to the documentation of this file.
00001 /*
00002  *  Main authors:
00003  *     Guido Tack <tack@gecode.org>
00004  *
00005  *  Contributing authors:
00006  *     Christian Schulte <schulte@gecode.org>
00007  *
00008  *  Copyright:
00009  *     Guido Tack, 2004
00010  *     Christian Schulte, 2004
00011  *
00012  *  Last modified:
00013  *     $Date: 2006-08-24 11:25:05 +0200 (Thu, 24 Aug 2006) $ by $Author: schulte $
00014  *     $Revision: 3559 $
00015  *
00016  *  This file is part of Gecode, the generic constraint
00017  *  development environment:
00018  *     http://www.gecode.org
00019  *
00020  *  See the file "LICENSE" for information on usage and
00021  *  redistribution of this file, and for a
00022  *     DISCLAIMER OF ALL WARRANTIES.
00023  *
00024  */
00025 
00026 namespace Gecode { 
00027 
00028   namespace Set {
00029 
00030     forceinline
00031     SingletonView::SingletonView(void) {}
00032 
00033     forceinline
00034     SingletonView::SingletonView(Gecode::Int::IntView& i0)
00035       : DerivedViewBase<Gecode::Int::IntView>(i0) {}
00036 
00037     forceinline PropCond
00038     SingletonView::pc_settoint(PropCond pc) {
00039       switch(pc) {
00040       case PC_SET_VAL:
00041       case PC_SET_CGLB:
00042       case PC_SET_CARD:
00043         return Gecode::Int::PC_INT_VAL;
00044       default:
00045         return Gecode::Int::PC_INT_DOM;
00046       }
00047     }
00048 
00049     forceinline ModEvent
00050     SingletonView::me_inttoset(ModEvent me) {
00051       switch(me) {
00052       case Gecode::Int::ME_INT_FAILED: 
00053         return ME_SET_FAILED;
00054       case Gecode::Int::ME_INT_NONE: 
00055         return ME_SET_NONE;
00056       case Gecode::Int::ME_INT_VAL: 
00057         return ME_SET_VAL;
00058       case Gecode::Int::ME_INT_DOM: 
00059         return ME_SET_LUB;
00060       default:
00061         return ME_SET_LUB;
00062       }
00063     }
00064 
00065     forceinline bool
00066     SingletonView::assigned(void) const { return view.assigned(); }
00067 
00068     forceinline unsigned int
00069     SingletonView::glbSize(void) const { return view.assigned() ? 1 : 0; }
00070 
00071     forceinline unsigned int
00072     SingletonView::lubSize(void) const { return view.size(); }
00073 
00074     forceinline unsigned int
00075     SingletonView::unknownSize(void) const {
00076       return lubSize() - glbSize();
00077     }
00078 
00079     forceinline bool
00080     SingletonView::contains(int n) const { return view.assigned() ?
00081                                              (view.val()==n) : false; }
00082 
00083     forceinline bool
00084     SingletonView::notContains(int n) const { return !view.in(n); }
00085 
00086     forceinline unsigned int
00087     SingletonView::cardMin() const { return 1; }
00088 
00089     forceinline unsigned int
00090     SingletonView::cardMax() const { return 1; }
00091 
00092     forceinline int
00093     SingletonView::lubMin() const { return view.min(); }
00094 
00095     forceinline int
00096     SingletonView::lubMax() const { return view.max(); }
00097 
00098     forceinline int
00099     SingletonView::glbMin() const { return view.assigned() ?
00100                                       view.val() : BndSet::MIN_OF_EMPTY; }
00101 
00102     forceinline int
00103     SingletonView::glbMax() const { return view.assigned() ?
00104                                       view.val() : BndSet::MAX_OF_EMPTY; }
00105 
00106     forceinline ModEvent
00107     SingletonView::cardMin(Space* home,unsigned int c) {
00108       return c<=1 ? ME_SET_NONE : ME_SET_FAILED;
00109     }
00110 
00111     forceinline ModEvent
00112     SingletonView::cardMax(Space* home,unsigned int c) {
00113       return c<1 ? ME_SET_FAILED : ME_SET_NONE;
00114     }
00115 
00116     forceinline ModEvent
00117     SingletonView::include(Space* home,int c) { 
00118       return me_inttoset(view.eq(home,c)); 
00119     }
00120 
00121     forceinline ModEvent
00122     SingletonView::intersect(Space* home,int c) { 
00123       return me_inttoset(view.eq(home,c)); 
00124     }
00125 
00126     forceinline ModEvent
00127     SingletonView::intersect(Space* home,int i, int j) { 
00128       ModEvent me1 = me_inttoset(view.gq(home,i));
00129       ModEvent me2 = me_inttoset(view.lq(home,j));
00130       if (me_failed(me1) || me_failed(me2))
00131         return ME_SET_FAILED;
00132       switch (me1) {
00133       case ME_SET_NONE:
00134       case ME_SET_LUB:
00135         return me2;
00136       case ME_SET_VAL:
00137         return ME_SET_VAL;
00138       default:
00139         GECODE_NEVER;
00140         return ME_SET_VAL;
00141       }
00142     }
00143 
00144     forceinline ModEvent
00145     SingletonView::exclude(Space* home,int c) { 
00146       return me_inttoset(view.nq(home,c)); 
00147     }
00148 
00149     forceinline ModEvent
00150     SingletonView::include(Space* home, int j, int k) {
00151       return j==k ? me_inttoset(view.eq(home,j)) : ME_SET_FAILED ;
00152     }
00153 
00154     forceinline ModEvent
00155     SingletonView::exclude(Space* home, int j, int k) {
00156       ModEvent me1 = me_inttoset(view.gr(home,j));
00157       ModEvent me2 = me_inttoset(view.le(home,k));
00158       if (me_failed(me1) || me_failed(me2))
00159         return ME_SET_FAILED;
00160       switch (me1) {
00161       case ME_SET_NONE:
00162       case ME_SET_LUB:
00163         return me2;
00164       case ME_SET_VAL:
00165         return ME_SET_VAL;
00166       default:
00167         GECODE_NEVER;
00168         return ME_SET_VAL;
00169       }
00170     }
00171 
00172     template <class I> ModEvent
00173     SingletonView::excludeI(Space* home, I& iter) {
00174       return me_inttoset(view.minus(home,iter));
00175     }
00176 
00177     template <class I> ModEvent
00178     SingletonView::includeI(Space* home, I& iter) {
00179       if (!iter())
00180         return ME_SET_NONE;
00181 
00182       if (iter.min()!=iter.max())
00183         return ME_SET_FAILED;
00184 
00185       int val = iter.min();
00186       ++iter;
00187       if ( iter() )
00188         return ME_SET_FAILED;
00189 
00190       return me_inttoset(view.eq(home, val));
00191     }
00192 
00193     template <class I> ModEvent
00194     SingletonView::intersectI(Space* home, I& iter) {
00195       return me_inttoset(view.inter(home,iter));
00196     }
00197 
00198     forceinline void
00199     SingletonView::subscribe(Space* home, Propagator* p, PropCond pc,
00200                              bool process) {
00201       view.subscribe(home,p,pc_settoint(pc),process);
00202     }
00203     forceinline void
00204     SingletonView::cancel(Space* home, Propagator* p, PropCond pc) {
00205       view.cancel(home,p,pc_settoint(pc));
00206     }
00207 
00208 
00209     forceinline ModEvent
00210     SingletonView::pme(const Propagator* p) {
00211       return me_inttoset(Int::IntView::pme(p));
00212     }
00213     forceinline PropModEvent
00214     SingletonView::pme(ModEvent me) {
00215       // CHECK THIS
00216       return SetView::pme(me);
00217     }
00218 
00219     forceinline void
00220     SingletonView::update(Space* home, bool share, SingletonView& y) {
00221       view.update(home,share,y.view);
00222     }
00223 
00224     /*
00225      * Iterators
00226      *
00227      */
00228 
00233     template <>
00234     class LubRanges<SingletonView> : public Gecode::Int::IntVarImpFwd {
00235     public:
00237 
00238 
00239       LubRanges(void);
00241       LubRanges(const SingletonView& x);
00243       void init(const SingletonView& x);
00245     };
00246 
00247     forceinline
00248     LubRanges<SingletonView>::LubRanges(void) {}
00249 
00250     forceinline
00251     LubRanges<SingletonView>::LubRanges(const SingletonView& s) :
00252       Gecode::Int::IntVarImpFwd(s.base().variable()) {}
00253 
00254     forceinline void
00255     LubRanges<SingletonView>::init(const SingletonView& s) {
00256       Gecode::Int::IntVarImpFwd::init(s.base().variable());
00257     }
00258 
00263     template <>
00264     class GlbRanges<SingletonView> {
00265     private:
00266       int  val;
00267       bool flag;
00268     public:
00270 
00271 
00272       GlbRanges(void);
00274       GlbRanges(const SingletonView& x);
00276       void init(const SingletonView& x);
00277 
00279 
00280 
00281       bool operator()(void) const;
00283       void operator++(void);
00285 
00287 
00288 
00289       int min(void) const;
00291       int max(void) const;
00293       unsigned int width(void) const;
00295     };
00296 
00297     forceinline
00298     GlbRanges<SingletonView>::GlbRanges(void) {}
00299 
00300     forceinline void
00301     GlbRanges<SingletonView>::init(const SingletonView& s) {
00302       if (s.base().assigned()) {
00303         val = s.base().val();
00304         flag = true;
00305       } else {
00306         val = 0;
00307         flag = false;
00308       }
00309     }
00310 
00311     forceinline
00312     GlbRanges<SingletonView>::GlbRanges(const SingletonView& s) {
00313       init(s);
00314     }
00315 
00316     forceinline bool
00317     GlbRanges<SingletonView>::operator()(void) const { return flag; }
00318 
00319     forceinline void
00320     GlbRanges<SingletonView>::operator++(void) { flag=false; }
00321 
00322     forceinline int
00323     GlbRanges<SingletonView>::min(void) const { return val; }
00324     forceinline int
00325     GlbRanges<SingletonView>::max(void) const { return val; }
00326     forceinline unsigned int
00327     GlbRanges<SingletonView>::width(void) const { return 1; }
00328 
00329   }
00330 
00331   /*
00332    * Testing
00333    *
00334    */
00335   forceinline bool
00336   same(const Set::SingletonView& x, const Set::SingletonView& y) {
00337     return same(x.base(),y.base());
00338   }
00339   forceinline bool
00340   before(const Set::SingletonView& x, const Set::SingletonView& y) {
00341     return before(x.base(),y.base());
00342   }
00343 
00344 
00345 }
00346 
00347 // STATISTICS: set-var
00348