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

superofinter.icc

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Guido Tack <tack@gecode.org>
00005  *     Christian Schulte <schulte@gecode.org>
00006  *
00007  *  Contributing authors:
00008  *     Gabor Szokoli <szokoli@gecode.org>
00009  *
00010  *  Copyright:
00011  *     Guido Tack, 2004
00012  *     Christian Schulte, 2004
00013  *     Gabor Szokoli, 2004
00014  *
00015  *  Last modified:
00016  *     $Date: 2008-01-31 18:29:16 +0100 (Thu, 31 Jan 2008) $ by $Author: tack $
00017  *     $Revision: 6017 $
00018  *
00019  *  This file is part of Gecode, the generic constraint
00020  *  development environment:
00021  *     http://www.gecode.org
00022  *
00023  *  Permission is hereby granted, free of charge, to any person obtaining
00024  *  a copy of this software and associated documentation files (the
00025  *  "Software"), to deal in the Software without restriction, including
00026  *  without limitation the rights to use, copy, modify, merge, publish,
00027  *  distribute, sublicense, and/or sell copies of the Software, and to
00028  *  permit persons to whom the Software is furnished to do so, subject to
00029  *  the following conditions:
00030  *
00031  *  The above copyright notice and this permission notice shall be
00032  *  included in all copies or substantial portions of the Software.
00033  *
00034  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00035  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00036  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00037  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00038  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00039  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00040  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00041  *
00042  */
00043 
00044 namespace Gecode { namespace Set { namespace RelOp {
00045 
00046   template <class View0, class View1, class View2>
00047   forceinline
00048   SuperOfInter<View0,View1,View2>::SuperOfInter
00049   (Space* home, View0 y0, View1 y1, View2 y2)
00050     : MixTernaryPropagator<View0,PC_SET_ANY,View1,PC_SET_ANY,
00051                              View2,PC_SET_CLUB>(home,y0,y1,y2) {}
00052 
00053   template <class View0, class View1, class View2>
00054   forceinline
00055   SuperOfInter<View0,View1,View2>::SuperOfInter
00056   (Space* home, bool share, SuperOfInter<View0,View1,View2>& p)
00057     : MixTernaryPropagator<View0,PC_SET_ANY,View1,PC_SET_ANY,
00058                              View2,PC_SET_CLUB>(home,share,p) {}
00059 
00060   template <class View0, class View1, class View2>
00061   ExecStatus
00062   SuperOfInter<View0,View1,View2>::post(Space* home,
00063                                         View0 x0, View1 x1, View2 x2) {
00064     (void) new (home) SuperOfInter<View0,View1,View2>(home, x0, x1, x2);
00065     return ES_OK;
00066   }
00067 
00068   template <class View0, class View1, class View2>
00069   Actor*
00070   SuperOfInter<View0,View1,View2>::copy(Space* home, bool share) {
00071     return new (home) SuperOfInter(home,share,*this);
00072   }
00073 
00074   template <class View0, class View1, class View2>
00075   Support::Symbol
00076   SuperOfInter<View0,View1,View2>::ati(void) {
00077     return Reflection::mangle<View0,View1,View2>("Gecode::Set::RelOp::SuperOfInter");
00078   }
00079 
00080   template <class View0, class View1, class View2>
00081   Reflection::ActorSpec
00082   SuperOfInter<View0,View1,View2>::spec(const Space* home,
00083                                         Reflection::VarMap& m) const {
00084     return MixTernaryPropagator<View0,PC_SET_ANY,View1,PC_SET_ANY,
00085       View2,PC_SET_CLUB>::spec(home, m, ati());
00086   }
00087 
00088   template <class View0, class View1, class View2>
00089   void
00090   SuperOfInter<View0,View1,View2>::post(Space* home,
00091                                         Reflection::VarMap& vars,
00092                                         const Reflection::ActorSpec& spec) {
00093     spec.checkArity(3);
00094     View0 x0(home, vars, spec[0]);
00095     View1 x1(home, vars, spec[1]);
00096     View2 x2(home, vars, spec[2]);
00097     (void) new (home) SuperOfInter(home,x0,x1,x2);
00098   }
00099 
00100   template <class View0, class View1, class View2>
00101   ExecStatus
00102   SuperOfInter<View0,View1,View2>::propagate(Space* home, ModEventDelta med) {
00103 
00104     bool allassigned = x0.assigned() && x1.assigned() && x2.assigned();
00105 
00106     ModEvent me0 = View0::me(med);
00107     ModEvent me1 = View1::me(med);
00108     ModEvent me2 = View2::me(med);
00109 
00110     bool modified = false;
00111 
00112     do {
00113       // glb(x2) >= glb(x0) ^ glb(x1)
00114       if ( modified || Rel::testSetEventLB(me0,me1)) {
00115         GlbRanges<View0> lb0(x0);
00116         GlbRanges<View1> lb1(x1);
00117         Iter::Ranges::Inter<GlbRanges<View0>,GlbRanges<View1> >
00118           is(lb0, lb1);
00119 
00120         GECODE_ME_CHECK_MODIFIED(modified,x2.includeI(home,is));
00121       }
00122 
00123       // lub(x0) -= glb(x1)-lub(x2)
00124       // lub(x1) -= glb(x0)-lub(x2)
00125       if ( modified || Rel::testSetEventAnyB(me0,me1,me2)) {
00126          modified = false;
00127         GlbRanges<View1> lb12(x1);
00128         LubRanges<View2> ub22(x2);
00129         Iter::Ranges::Diff<GlbRanges<View1>, LubRanges<View2> >
00130           diff1(lb12, ub22);
00131 
00132         GECODE_ME_CHECK_MODIFIED(modified, x0.excludeI(home,diff1));
00133 
00134         GlbRanges<View0> lb01(x0);
00135         LubRanges<View2> ub23(x2);
00136         Iter::Ranges::Diff<GlbRanges<View0>, LubRanges<View2> >
00137           diff2(lb01, ub23);
00138 
00139         GECODE_ME_CHECK_MODIFIED(modified, x1.excludeI(home,diff2));
00140       } else {
00141          modified = false;
00142       }
00143 
00144       // Cardinality propagation
00145       if ( modified ||
00146             Rel::testSetEventCard(me0,me1,me2) ||
00147            Rel::testSetEventUB(me0,me1)
00148            ) {
00149 
00150         LubRanges<View0> ub0(x0);
00151         LubRanges<View1> ub1(x1);
00152         Iter::Ranges::Union<LubRanges<View0>, LubRanges<View1> > u(ub0,ub1);
00153 
00154         unsigned int m = Iter::Ranges::size(u);
00155 
00156         if (m < x0.cardMin() + x1.cardMin()) {
00157           GECODE_ME_CHECK_MODIFIED(modified,
00158                             x2.cardMin( home,
00159                                         x0.cardMin()+x1.cardMin() - m ) );
00160         }
00161         if (m + x2.cardMax() > x1.cardMin()) {
00162           GECODE_ME_CHECK_MODIFIED(modified,
00163                             x0.cardMax( home,
00164                                         m+x2.cardMax()-x1.cardMin() )  );
00165         }
00166         if (m + x2.cardMax() > x0.cardMin()) {
00167           GECODE_ME_CHECK_MODIFIED(modified,
00168                             x1.cardMax( home,
00169                                         m+x2.cardMax()-x0.cardMin() )  );
00170         }
00171       }
00172     } while (modified);
00173 
00174 
00175     if (shared(x0,x1,x2)) {
00176       if (allassigned) {
00177         return ES_SUBSUMED(this,home);
00178       } else {
00179         return ES_NOFIX;
00180       }
00181     } else {
00182       if (x0.assigned() + x1.assigned() + x2.assigned() >= 2) {
00183          return ES_SUBSUMED(this,home);
00184       } else {
00185         return ES_FIX;
00186       }
00187     }
00188 
00189   }
00190 
00191 }}}
00192 
00193 // STATISTICS: set-prop