Generated on Thu Mar 22 10:39:45 2012 for Gecode by doxygen 1.6.3

superofinter.hpp

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: 2010-03-03 17:32:21 +0100 (Wed, 03 Mar 2010) $ by $Author: schulte $
00017  *     $Revision: 10364 $
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   (Home 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(Home 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   ExecStatus
00076   SuperOfInter<View0,View1,View2>::propagate(Space& home, const ModEventDelta& med) {
00077 
00078     bool allassigned = x0.assigned() && x1.assigned() && x2.assigned();
00079 
00080     ModEvent me0 = View0::me(med);
00081     ModEvent me1 = View1::me(med);
00082     ModEvent me2 = View2::me(med);
00083 
00084     bool modified = false;
00085 
00086     do {
00087       // glb(x2) >= glb(x0) ^ glb(x1)
00088       if ( modified || Rel::testSetEventLB(me0,me1)) {
00089         GlbRanges<View0> lb0(x0);
00090         GlbRanges<View1> lb1(x1);
00091         Iter::Ranges::Inter<GlbRanges<View0>,GlbRanges<View1> >
00092           is(lb0, lb1);
00093 
00094         GECODE_ME_CHECK_MODIFIED(modified,x2.includeI(home,is));
00095       }
00096 
00097       // lub(x0) -= glb(x1)-lub(x2)
00098       // lub(x1) -= glb(x0)-lub(x2)
00099       if ( modified || Rel::testSetEventAnyB(me0,me1,me2)) {
00100          modified = false;
00101         GlbRanges<View1> lb12(x1);
00102         LubRanges<View2> ub22(x2);
00103         Iter::Ranges::Diff<GlbRanges<View1>, LubRanges<View2> >
00104           diff1(lb12, ub22);
00105 
00106         GECODE_ME_CHECK_MODIFIED(modified, x0.excludeI(home,diff1));
00107 
00108         GlbRanges<View0> lb01(x0);
00109         LubRanges<View2> ub23(x2);
00110         Iter::Ranges::Diff<GlbRanges<View0>, LubRanges<View2> >
00111           diff2(lb01, ub23);
00112 
00113         GECODE_ME_CHECK_MODIFIED(modified, x1.excludeI(home,diff2));
00114       } else {
00115          modified = false;
00116       }
00117 
00118       // Cardinality propagation
00119       if ( modified ||
00120             Rel::testSetEventCard(me0,me1,me2) ||
00121            Rel::testSetEventUB(me0,me1)
00122            ) {
00123 
00124         LubRanges<View0> ub0(x0);
00125         LubRanges<View1> ub1(x1);
00126         Iter::Ranges::Union<LubRanges<View0>, LubRanges<View1> > u(ub0,ub1);
00127 
00128         unsigned int m = Iter::Ranges::size(u);
00129 
00130         if (m < x0.cardMin() + x1.cardMin()) {
00131           GECODE_ME_CHECK_MODIFIED(modified,
00132                             x2.cardMin( home,
00133                                         x0.cardMin()+x1.cardMin() - m ) );
00134         }
00135         if (m + x2.cardMax() > x1.cardMin()) {
00136           GECODE_ME_CHECK_MODIFIED(modified,
00137                             x0.cardMax( home,
00138                                         m+x2.cardMax()-x1.cardMin() )  );
00139         }
00140         if (m + x2.cardMax() > x0.cardMin()) {
00141           GECODE_ME_CHECK_MODIFIED(modified,
00142                             x1.cardMax( home,
00143                                         m+x2.cardMax()-x0.cardMin() )  );
00144         }
00145       }
00146     } while (modified);
00147 
00148 
00149     if (shared(x0,x1,x2)) {
00150       if (allassigned) {
00151         return home.ES_SUBSUMED(*this);
00152       } else {
00153         return ES_NOFIX;
00154       }
00155     } else {
00156       if (x0.assigned() + x1.assigned() + x2.assigned() >= 2) {
00157          return home.ES_SUBSUMED(*this);
00158       } else {
00159         return ES_FIX;
00160       }
00161     }
00162 
00163   }
00164 
00165 }}}
00166 
00167 // STATISTICS: set-prop