Generated on Tue Apr 18 10:22:13 2017 for Gecode by doxygen 1.6.3

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