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

superofinter.icc

Go to the documentation of this file.
00001 /*
00002  *  Main authors:
00003  *     Guido Tack <tack@gecode.org>
00004  *     Christian Schulte <schulte@gecode.org>
00005  *
00006  *  Contributing authors:
00007  *     Gabor Szokoli <szokoli@gecode.org>
00008  *
00009  *  Copyright:
00010  *     Guido Tack, 2004
00011  *     Christian Schulte, 2004
00012  *     Gabor Szokoli, 2004
00013  *
00014  *  Last modified:
00015  *     $Date: 2006-08-25 17:31:32 +0200 (Fri, 25 Aug 2006) $ by $Author: tack $
00016  *     $Revision: 3573 $
00017  *
00018  *  This file is part of Gecode, the generic constraint
00019  *  development environment:
00020  *     http://www.gecode.org
00021  *
00022  *  See the file "LICENSE" for information on usage and
00023  *  redistribution of this file, and for a
00024  *     DISCLAIMER OF ALL WARRANTIES.
00025  *
00026  */
00027 
00028 namespace Gecode { namespace Set { namespace RelOp {
00029 
00030   template <class View0, class View1, class View2>
00031   forceinline
00032   SuperOfInter<View0,View1,View2>::SuperOfInter
00033   (Space* home, View0 y0, View1 y1, View2 y2)
00034     : InhomTernaryPropagator<View0,PC_SET_ANY,View1,PC_SET_ANY,
00035                              View2,PC_SET_CLUB>(home,y0,y1,y2) {}
00036 
00037   template <class View0, class View1, class View2>
00038   forceinline
00039   SuperOfInter<View0,View1,View2>::SuperOfInter
00040   (Space* home, bool share, SuperOfInter<View0,View1,View2>& p)
00041     : InhomTernaryPropagator<View0,PC_SET_ANY,View1,PC_SET_ANY,
00042                              View2,PC_SET_CLUB>(home,share,p) {}
00043 
00044   template <class View0, class View1, class View2>
00045   ExecStatus
00046   SuperOfInter<View0,View1,View2>::post(Space* home,
00047                                         View0 x0, View1 x1, View2 x2) {
00048     (void) new (home) SuperOfInter<View0,View1,View2>(home, x0, x1, x2);
00049     return ES_OK;
00050   }
00051 
00052   template <class View0, class View1, class View2>
00053   Actor*
00054   SuperOfInter<View0,View1,View2>::copy(Space* home, bool share) {
00055     return new (home) SuperOfInter(home,share,*this);
00056   }
00057 
00058   template <class View0, class View1, class View2>
00059   ExecStatus
00060   SuperOfInter<View0,View1,View2>::propagate(Space* home) {
00061 
00062     bool allassigned = x0.assigned() && x1.assigned() && x2.assigned();
00063 
00064     ModEvent me0 = View0::pme(this);
00065     ModEvent me1 = View1::pme(this);
00066     ModEvent me2 = View2::pme(this);
00067 
00068     bool modified = false;
00069 
00070     do {
00071       // glb(x2) >= glb(x0) ^ glb(x1)
00072       if ( modified || Rel::testSetEventLB(me0,me1)) {
00073         GlbRanges<View0> lb0(x0);
00074         GlbRanges<View1> lb1(x1);
00075         Iter::Ranges::Inter<GlbRanges<View0>,GlbRanges<View1> >
00076           is(lb0, lb1);
00077 
00078         GECODE_ME_CHECK_MODIFIED(modified,x2.includeI(home,is));
00079       }
00080 
00081       // lub(x0) -= glb(x1)-lub(x2)
00082       // lub(x1) -= glb(x0)-lub(x2)
00083       if ( modified || Rel::testSetEventAnyB(me0,me1,me2)) {
00084         modified = false;
00085         GlbRanges<View1> lb12(x1);
00086         LubRanges<View2> ub22(x2);
00087         Iter::Ranges::Diff<GlbRanges<View1>, LubRanges<View2> >
00088           diff1(lb12, ub22);
00089 
00090         GECODE_ME_CHECK_MODIFIED(modified, x0.excludeI(home,diff1));
00091 
00092         GlbRanges<View0> lb01(x0);
00093         LubRanges<View2> ub23(x2);
00094         Iter::Ranges::Diff<GlbRanges<View0>, LubRanges<View2> >
00095           diff2(lb01, ub23);
00096 
00097         GECODE_ME_CHECK_MODIFIED(modified, x1.excludeI(home,diff2));
00098       } else {
00099         modified = false;
00100       }
00101 
00102       // Cardinality propagation
00103       if ( modified ||
00104            Rel::testSetEventCard(me0,me1,me2) ||
00105            Rel::testSetEventUB(me0,me1)
00106            ) {
00107 
00108         LubRanges<View0> ub0(x0);
00109         LubRanges<View1> ub1(x1);
00110         Iter::Ranges::Union<LubRanges<View0>, LubRanges<View1> > u(ub0,ub1);
00111 
00112         unsigned int m = Iter::Ranges::size(u);
00113 
00114         if (m < x0.cardMin() + x1.cardMin()) {
00115           GECODE_ME_CHECK_MODIFIED(modified,
00116                             x2.cardMin( home,
00117                                         x0.cardMin()+x1.cardMin() - m ) );
00118         }
00119         if (m + x2.cardMax() > x1.cardMin()) {
00120           GECODE_ME_CHECK_MODIFIED(modified,
00121                             x0.cardMax( home,
00122                                         m+x2.cardMax()-x1.cardMin() )  );
00123         }
00124         if (m + x2.cardMax() > x0.cardMin()) {
00125           GECODE_ME_CHECK_MODIFIED(modified,
00126                             x1.cardMax( home,
00127                                         m+x2.cardMax()-x0.cardMin() )  );
00128         }
00129       }
00130     } while (modified);
00131 
00132 
00133     if (shared(x0,x1,x2)) {
00134       if (allassigned) {
00135         return ES_SUBSUMED;
00136       } else {
00137         return ES_NOFIX;
00138       }
00139     } else {
00140       if (x0.assigned() + x1.assigned() + x2.assigned() >= 2) {
00141         return ES_SUBSUMED;
00142       } else {
00143         return ES_FIX;
00144       }
00145     }
00146 
00147   }
00148 
00149 }}}
00150 
00151 // STATISTICS: set-prop