Generated on Tue May 22 09:40:16 2018 for Gecode by doxygen 1.6.3

re-subset.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  *  Copyright:
00008  *     Guido Tack, 2004
00009  *     Christian Schulte, 2004
00010  *
00011  *  This file is part of Gecode, the generic constraint
00012  *  development environment:
00013  *     http://www.gecode.org
00014  *
00015  *  Permission is hereby granted, free of charge, to any person obtaining
00016  *  a copy of this software and associated documentation files (the
00017  *  "Software"), to deal in the Software without restriction, including
00018  *  without limitation the rights to use, copy, modify, merge, publish,
00019  *  distribute, sublicense, and/or sell copies of the Software, and to
00020  *  permit persons to whom the Software is furnished to do so, subject to
00021  *  the following conditions:
00022  *
00023  *  The above copyright notice and this permission notice shall be
00024  *  included in all copies or substantial portions of the Software.
00025  *
00026  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00027  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00028  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00029  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00030  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00031  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00032  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00033  *
00034  */
00035 
00036 namespace Gecode { namespace Set { namespace Rel {
00037 
00038   template<class View0, class View1, class CtrlView, ReifyMode rm>
00039   forceinline
00040   ReSubset<View0,View1,CtrlView,rm>::ReSubset(Home home, View0 y0,
00041                                               View1 y1, CtrlView b0)
00042     : Propagator(home), x0(y0), x1(y1), b(b0) {
00043     b.subscribe(home,*this, Gecode::Int::PC_INT_VAL);
00044     x0.subscribe(home,*this, PC_SET_ANY);
00045     x1.subscribe(home,*this, PC_SET_ANY);
00046   }
00047 
00048   template<class View0, class View1, class CtrlView, ReifyMode rm>
00049   forceinline
00050   ReSubset<View0,View1,CtrlView,rm>::ReSubset(Space& home, 
00051                                               ReSubset& p)
00052     : Propagator(home,p) {
00053     x0.update(home,p.x0);
00054     x1.update(home,p.x1);
00055     b.update(home,p.b);
00056   }
00057 
00058   template<class View0, class View1, class CtrlView, ReifyMode rm>
00059   PropCost
00060   ReSubset<View0,View1,CtrlView,rm>::cost(const Space&,
00061                                           const ModEventDelta&) const {
00062     return PropCost::ternary(PropCost::LO);
00063   }
00064 
00065   template<class View0, class View1, class CtrlView, ReifyMode rm>
00066   void
00067   ReSubset<View0,View1,CtrlView,rm>::reschedule(Space& home) {
00068     b.reschedule(home,*this, Gecode::Int::PC_INT_VAL);
00069     x0.reschedule(home,*this, PC_SET_ANY);
00070     x1.reschedule(home,*this, PC_SET_ANY);
00071   }
00072 
00073   template<class View0, class View1, class CtrlView, ReifyMode rm>
00074   forceinline size_t
00075   ReSubset<View0,View1,CtrlView,rm>::dispose(Space& home) {
00076     b.cancel(home,*this, Gecode::Int::PC_INT_VAL);
00077     x0.cancel(home,*this, PC_SET_ANY);
00078     x1.cancel(home,*this, PC_SET_ANY);
00079     (void) Propagator::dispose(home);
00080     return sizeof(*this);
00081   }
00082 
00083   template<class View0, class View1, class CtrlView, ReifyMode rm>
00084   ExecStatus
00085   ReSubset<View0,View1,CtrlView,rm>::post(Home home, View0 x0, View1 x1,
00086                                           CtrlView b) {
00087     if (!same(x0,x1)) {
00088       (void) new (home) ReSubset<View0,View1,CtrlView,rm>(home,x0,x1,b);
00089     } else if (rm != RM_IMP) {
00090       GECODE_ME_CHECK(b.one(home));
00091     }
00092     return ES_OK;
00093   }
00094 
00095   template<class View0, class View1, class CtrlView, ReifyMode rm>
00096   Actor*
00097   ReSubset<View0,View1,CtrlView,rm>::copy(Space& home) {
00098     return new (home) ReSubset<View0,View1,CtrlView,rm>(home,*this);
00099   }
00100 
00101   template<class View0, class View1, class CtrlView, ReifyMode rm>
00102   ExecStatus
00103   ReSubset<View0,View1,CtrlView,rm>::propagate(Space& home,
00104                                                const ModEventDelta&) {
00105     if (b.one()) {
00106       if (rm == RM_PMI)
00107         return home.ES_SUBSUMED(*this);
00108       GECODE_REWRITE(*this,(Subset<View0,View1>::post(home(*this),x0,x1)));
00109     }
00110     if (b.zero()) {
00111       if (rm == RM_IMP)
00112         return home.ES_SUBSUMED(*this);
00113       GECODE_REWRITE(*this,(NoSubset<View0,View1>::post(home(*this),x0,x1)));
00114     }
00115 
00116     // check whether cardinalities still allow subset
00117     if (x0.cardMin() > x1.cardMax()) {
00118       if (rm != RM_PMI)
00119         GECODE_ME_CHECK(b.zero_none(home));
00120       return home.ES_SUBSUMED(*this);
00121     }
00122 
00123     // check lub(x0) subset glb(x1)
00124     {
00125       LubRanges<View0> x0ub(x0);
00126       GlbRanges<View1> x1lb(x1);
00127       Iter::Ranges::Diff<LubRanges<View0>,GlbRanges<View1> > d(x0ub,x1lb);
00128       if (!d()) {
00129         if (rm != RM_IMP)
00130           GECODE_ME_CHECK(b.one_none(home));
00131         return home.ES_SUBSUMED(*this);
00132       }
00133     }
00134 
00135     // check glb(x0) subset lub(x1)
00136     {
00137       GlbRanges<View0> x0lb(x0);
00138       LubRanges<View1> x1ub(x1);
00139       Iter::Ranges::Diff<GlbRanges<View0>,LubRanges<View1> > d(x0lb,x1ub);
00140       if (d()) {
00141         if (rm != RM_PMI)
00142           GECODE_ME_CHECK(b.zero_none(home));
00143         return home.ES_SUBSUMED(*this);
00144       } else if (x0.assigned() && x1.assigned()) {
00145         if (rm != RM_IMP)
00146           GECODE_ME_CHECK(b.one_none(home));
00147         return home.ES_SUBSUMED(*this);
00148       }
00149     }
00150 
00151     if (x0.cardMin() > 0) {
00152       LubRanges<View0> x0ub(x0);
00153       LubRanges<View1> x1ub(x1);
00154       Iter::Ranges::Inter<LubRanges<View0>,LubRanges<View1> >
00155         i(x0ub,x1ub);
00156       if (!i()) {
00157         if (rm != RM_PMI)
00158           GECODE_ME_CHECK(b.zero_none(home));
00159         return home.ES_SUBSUMED(*this);
00160       }
00161     }
00162 
00163     return ES_FIX;
00164   }
00165 
00166 }}}
00167 
00168 // STATISTICS: set-prop