Generated on Thu Apr 11 13:59:19 2019 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  *  This file is part of Gecode, the generic constraint
00016  *  development environment:
00017  *     http://www.gecode.org
00018  *
00019  *  Permission is hereby granted, free of charge, to any person obtaining
00020  *  a copy of this software and associated documentation files (the
00021  *  "Software"), to deal in the Software without restriction, including
00022  *  without limitation the rights to use, copy, modify, merge, publish,
00023  *  distribute, sublicense, and/or sell copies of the Software, and to
00024  *  permit persons to whom the Software is furnished to do so, subject to
00025  *  the following conditions:
00026  *
00027  *  The above copyright notice and this permission notice shall be
00028  *  included in all copies or substantial portions of the Software.
00029  *
00030  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00031  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00032  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00033  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00034  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00035  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00036  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00037  *
00038  */
00039 
00040 namespace Gecode { namespace Set { namespace RelOp {
00041 
00042   template<class View0, class View1, class View2>
00043   forceinline
00044   SuperOfInter<View0,View1,View2>::SuperOfInter
00045   (Home home, View0 y0, View1 y1, View2 y2)
00046     : MixTernaryPropagator<View0,PC_SET_ANY,View1,PC_SET_ANY,
00047                              View2,PC_SET_CLUB>(home,y0,y1,y2) {}
00048 
00049   template<class View0, class View1, class View2>
00050   forceinline
00051   SuperOfInter<View0,View1,View2>::SuperOfInter
00052   (Space& home, SuperOfInter<View0,View1,View2>& p)
00053     : MixTernaryPropagator<View0,PC_SET_ANY,View1,PC_SET_ANY,
00054                              View2,PC_SET_CLUB>(home,p) {}
00055 
00056   template<class View0, class View1, class View2>
00057   ExecStatus
00058   SuperOfInter<View0,View1,View2>::post(Home home,
00059                                         View0 x0, View1 x1, View2 x2) {
00060     (void) new (home) SuperOfInter<View0,View1,View2>(home, x0, x1, x2);
00061     return ES_OK;
00062   }
00063 
00064   template<class View0, class View1, class View2>
00065   Actor*
00066   SuperOfInter<View0,View1,View2>::copy(Space& home) {
00067     return new (home) SuperOfInter(home,*this);
00068   }
00069 
00070   template<class View0, class View1, class View2>
00071   ExecStatus
00072   SuperOfInter<View0,View1,View2>::propagate(Space& home, const ModEventDelta& med) {
00073 
00074     bool allassigned = x0.assigned() && x1.assigned() && x2.assigned();
00075 
00076     ModEvent me0 = View0::me(med);
00077     ModEvent me1 = View1::me(med);
00078     ModEvent me2 = View2::me(med);
00079 
00080     bool modified = false;
00081 
00082     do {
00083       // glb(x2) >= glb(x0) ^ glb(x1)
00084       if ( modified || Rel::testSetEventLB(me0,me1)) {
00085         GlbRanges<View0> lb0(x0);
00086         GlbRanges<View1> lb1(x1);
00087         Iter::Ranges::Inter<GlbRanges<View0>,GlbRanges<View1> >
00088           is(lb0, lb1);
00089 
00090         GECODE_ME_CHECK_MODIFIED(modified,x2.includeI(home,is));
00091       }
00092 
00093       // lub(x0) -= glb(x1)-lub(x2)
00094       // lub(x1) -= glb(x0)-lub(x2)
00095       if ( modified || Rel::testSetEventAnyB(me0,me1,me2)) {
00096          modified = false;
00097         GlbRanges<View1> lb12(x1);
00098         LubRanges<View2> ub22(x2);
00099         Iter::Ranges::Diff<GlbRanges<View1>, LubRanges<View2> >
00100           diff1(lb12, ub22);
00101 
00102         GECODE_ME_CHECK_MODIFIED(modified, x0.excludeI(home,diff1));
00103 
00104         GlbRanges<View0> lb01(x0);
00105         LubRanges<View2> ub23(x2);
00106         Iter::Ranges::Diff<GlbRanges<View0>, LubRanges<View2> >
00107           diff2(lb01, ub23);
00108 
00109         GECODE_ME_CHECK_MODIFIED(modified, x1.excludeI(home,diff2));
00110       } else {
00111          modified = false;
00112       }
00113 
00114       // Cardinality propagation
00115       if ( modified ||
00116             Rel::testSetEventCard(me0,me1,me2) ||
00117            Rel::testSetEventUB(me0,me1)
00118            ) {
00119 
00120         LubRanges<View0> ub0(x0);
00121         LubRanges<View1> ub1(x1);
00122         Iter::Ranges::Union<LubRanges<View0>, LubRanges<View1> > u(ub0,ub1);
00123 
00124         unsigned int m = Iter::Ranges::size(u);
00125 
00126         if (m < x0.cardMin() + x1.cardMin()) {
00127           GECODE_ME_CHECK_MODIFIED(modified,
00128                             x2.cardMin( home,
00129                                         x0.cardMin()+x1.cardMin() - m ) );
00130         }
00131         if (m + x2.cardMax() > x1.cardMin()) {
00132           GECODE_ME_CHECK_MODIFIED(modified,
00133                             x0.cardMax( home,
00134                                         m+x2.cardMax()-x1.cardMin() )  );
00135         }
00136         if (m + x2.cardMax() > x0.cardMin()) {
00137           GECODE_ME_CHECK_MODIFIED(modified,
00138                             x1.cardMax( home,
00139                                         m+x2.cardMax()-x0.cardMin() )  );
00140         }
00141       }
00142     } while (modified);
00143 
00144 
00145     if (shared(x0,x1,x2)) {
00146       if (allassigned) {
00147         return home.ES_SUBSUMED(*this);
00148       } else {
00149         return ES_NOFIX;
00150       }
00151     } else {
00152       if (x0.assigned() + x1.assigned() + x2.assigned() >= 2) {
00153          return home.ES_SUBSUMED(*this);
00154       } else {
00155         return ES_FIX;
00156       }
00157     }
00158 
00159   }
00160 
00161 }}}
00162 
00163 // STATISTICS: set-prop