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

re-subset.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  *  Copyright:
00008  *     Guido Tack, 2004
00009  *     Christian Schulte, 2004
00010  *
00011  *  Last modified:
00012  *     $Date: 2008-07-11 09:31:51 +0200 (Fri, 11 Jul 2008) $ by $Author: tack $
00013  *     $Revision: 7288 $
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 Rel {
00041 
00042   template <class View0, class View1>
00043   forceinline
00044   ReSubset<View0,View1>::ReSubset(Space* home, View0 y0,
00045                                   View1 y1, Gecode::Int::BoolView y2)
00046     : Propagator(home), x0(y0), x1(y1), b(y2) {
00047     b.subscribe(home,this, Gecode::Int::PC_INT_VAL);
00048     x0.subscribe(home,this, PC_SET_ANY);
00049     x1.subscribe(home,this, PC_SET_ANY);
00050   }
00051 
00052   template <class View0, class View1>
00053   forceinline
00054   ReSubset<View0,View1>::ReSubset(Space* home, bool share, ReSubset& p)
00055     : Propagator(home,share,p) {
00056     x0.update(home,share,p.x0);
00057     x1.update(home,share,p.x1);
00058     b.update(home,share,p.b);
00059   }
00060 
00061   template <class View0, class View1>
00062   PropCost
00063   ReSubset<View0,View1>::cost(ModEventDelta) const {
00064     return PC_TERNARY_LO;
00065   }
00066 
00067   template <class View0, class View1>
00068   Support::Symbol
00069   ReSubset<View0,View1>::ati(void) {
00070     return Reflection::mangle<View0,View1>("Gecode::Set::Rel::ReSubset");
00071   }
00072 
00073   template <class View0, class View1>
00074   Reflection::ActorSpec
00075   ReSubset<View0,View1>::spec(const Space* home,
00076                               Reflection::VarMap& m) const {
00077     Reflection::ActorSpec s(ati());
00078     return s << x0.spec(home, m)
00079              << x1.spec(home, m)
00080              << b.spec(home, m);
00081   }
00082 
00083   template <class View0, class View1>
00084   void
00085   ReSubset<View0,View1>::post(Space* home, Reflection::VarMap& vars,
00086                               const Reflection::ActorSpec& spec) {
00087     spec.checkArity(3);
00088     View0 x0(home, vars, spec[0]);
00089     View1 x1(home, vars, spec[1]);
00090     Gecode::Int::BoolView b(home, vars, spec[2]);
00091     (void) new (home) ReSubset(home,x0,x1,b);
00092   }
00093 
00094   template <class View0, class View1>
00095   size_t
00096   ReSubset<View0,View1>::dispose(Space* home) {
00097     assert(!home->failed());
00098     b.cancel(home,this, Gecode::Int::PC_INT_VAL);
00099     x0.cancel(home,this, PC_SET_ANY);
00100     x1.cancel(home,this, PC_SET_ANY);
00101     (void) Propagator::dispose(home);
00102     return sizeof(*this);
00103   }
00104 
00105   template <class View0, class View1>
00106   ExecStatus
00107   ReSubset<View0,View1>::post(Space* home, View0 x0, View1 x1,
00108                               Gecode::Int::BoolView b) {
00109     (void) new (home) ReSubset<View0,View1>(home,x0,x1,b);
00110     return ES_OK;
00111   }
00112 
00113   template <class View0, class View1>
00114   Actor*
00115   ReSubset<View0,View1>::copy(Space* home, bool share) {
00116     return new (home) ReSubset<View0,View1>(home,share,*this);
00117   }
00118 
00119   template <class View0, class View1>
00120   ExecStatus
00121   ReSubset<View0,View1>::propagate(Space* home, ModEventDelta) {
00122     if (b.one())
00123       GECODE_REWRITE(this,(SubSet<View0,View1>::post(home,x0,x1)));
00124     if (b.zero())
00125       GECODE_REWRITE(this,(NoSubSet<View0,View1>::post(home,x0,x1)));
00126 
00127     // check whether cardinalities still allow subset
00128     if (x0.cardMin() > x1.cardMax()) {
00129       GECODE_ME_CHECK(b.zero_none(home));
00130       return ES_SUBSUMED(this,home);
00131     }
00132 
00133     // check lub(x0) subset glb(x1)
00134     {
00135       LubRanges<View0> x0ub(x0);
00136       GlbRanges<View1> x1lb(x1);
00137       Iter::Ranges::Diff<LubRanges<View0>,GlbRanges<View1> > d(x0ub,x1lb);
00138       if (!d()) {
00139         GECODE_ME_CHECK(b.one_none(home));
00140         return ES_SUBSUMED(this,home);
00141       }
00142     }
00143 
00144     // check glb(x0) subset lub(x1)
00145     {
00146       GlbRanges<View0> x0lb(x0);
00147       LubRanges<View1> x1ub(x1);
00148       Iter::Ranges::Diff<GlbRanges<View0>,LubRanges<View1> > d(x0lb,x1ub);
00149       if (d()) {
00150         GECODE_ME_CHECK(b.zero_none(home));
00151         return ES_SUBSUMED(this,home);
00152       } else if (x0.assigned() && x1.assigned()) {
00153         GECODE_ME_CHECK(b.one_none(home));
00154         return ES_SUBSUMED(this,home);
00155       }
00156     }
00157     
00158     if (x0.cardMin() > 0) {
00159       LubRanges<View0> x0ub(x0);
00160       LubRanges<View1> x1ub(x1);
00161       Iter::Ranges::Inter<LubRanges<View0>,LubRanges<View1> >
00162         i(x0ub,x1ub);
00163       if (!i()) {
00164         GECODE_ME_CHECK(b.zero_none(home));
00165         return ES_SUBSUMED(this,home);
00166       }
00167     }
00168     
00169     return ES_FIX;
00170   }
00171 
00172 }}}
00173 
00174 // STATISTICS: set-prop