Generated on Tue Apr 18 10:21:53 2017 for Gecode by doxygen 1.6.3

set.hpp

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Denys Duchier <denys.duchier@univ-orleans.fr>
00005  *
00006  *  Copyright:
00007  *     Denys Duchier, 2011
00008  *
00009  *  Last modified:
00010  *     $Date: 2016-06-29 17:28:17 +0200 (Wed, 29 Jun 2016) $ by $Author: schulte $
00011  *     $Revision: 15137 $
00012  *
00013  *  This file is part of Gecode, the generic constraint
00014  *  development environment:
00015  *     http://www.gecode.org
00016  *
00017  *  Permission is hereby granted, free of charge, to any person obtaining
00018  *  a copy of this software and associated documentation files (the
00019  *  "Software"), to deal in the Software without restriction, including
00020  *  without limitation the rights to use, copy, modify, merge, publish,
00021  *  distribute, sublicense, and/or sell copies of the Software, and to
00022  *  permit persons to whom the Software is furnished to do so, subject to
00023  *  the following conditions:
00024  *
00025  *  The above copyright notice and this permission notice shall be
00026  *  included in all copies or substantial portions of the Software.
00027  *
00028  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00029  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00030  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00031  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00032  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00033  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00034  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00035  *
00036  */
00037 
00038 namespace Gecode { namespace Set { namespace Channel {
00039 
00040   template <typename View>
00041   forceinline
00042   ChannelSet<View>::ChannelSet(Home home,
00043                                ViewArray<CachedView<View> >& xs0,
00044                                ViewArray<CachedView<View> >& ys0)
00045     : Propagator(home), xs(xs0), ys(ys0) {
00046     for (int i=xs.size(); i--;)
00047       xs[i].initCache(home,IntSet::empty,IntSet(0,ys.size()-1));
00048     for (int i=ys.size(); i--;)
00049       ys[i].initCache(home,IntSet::empty,IntSet(0,xs.size()-1));
00050     xs.subscribe(home,*this, PC_SET_ANY);
00051     ys.subscribe(home,*this, PC_SET_ANY);
00052   }
00053 
00054   template <typename View>
00055   forceinline
00056   ChannelSet<View>::ChannelSet(Space& home, bool share, ChannelSet& p)
00057     : Propagator(home, share, p) {
00058     xs.update(home, share, p.xs);
00059     ys.update(home, share, p.ys);
00060   }
00061 
00062   template <typename View>
00063   forceinline ExecStatus
00064   ChannelSet<View>::post(Home home,
00065                          ViewArray<CachedView<View> >& xs,
00066                          ViewArray<CachedView<View> >& ys) {
00067     int xssize = xs.size();
00068     for (int i=ys.size(); i--;) {
00069         GECODE_ME_CHECK(ys[i].exclude(home, xssize, Limits::max));
00070         GECODE_ME_CHECK(ys[i].exclude(home, Limits::min, -1));
00071       }
00072     int yssize = ys.size();
00073     for (int i=xs.size(); i--;) {
00074         GECODE_ME_CHECK(xs[i].exclude(home, yssize, Limits::max));
00075         GECODE_ME_CHECK(xs[i].exclude(home, Limits::min, -1));
00076       }
00077     (void) new (home) ChannelSet(home,xs,ys);
00078     return ES_OK;
00079   }
00080 
00081   template <typename View>
00082   PropCost
00083   ChannelSet<View>::cost(const Space&, const ModEventDelta&) const {
00084     return PropCost::quadratic(PropCost::HI, xs.size()+ys.size());
00085   }
00086 
00087   template <typename View>
00088   void
00089   ChannelSet<View>::reschedule(Space& home) {
00090     xs.reschedule(home,*this, PC_SET_ANY);
00091     ys.reschedule(home,*this, PC_SET_ANY);
00092   }
00093 
00094   template <typename View>
00095   forceinline size_t
00096   ChannelSet<View>::dispose(Space& home) {
00097     xs.cancel(home, *this, PC_SET_ANY);
00098     ys.cancel(home, *this, PC_SET_ANY);
00099     (void) Propagator::dispose(home);
00100     return sizeof(*this);
00101   }
00102 
00103   template <typename View>
00104   Actor*
00105   ChannelSet<View>::copy(Space& home, bool share) {
00106     return new (home) ChannelSet(home,share,*this);
00107   }
00108 
00109   template <typename View>
00110   ExecStatus
00111   ChannelSet<View>::propagate(Space& home, const ModEventDelta&) {
00112     int assigned = 0;
00113     bool again = true;
00114     while (again) {
00115       assigned = 0;
00116       again = false;
00117       for (int i=xs.size(); i--;) {
00118         if (xs[i].assigned())
00119           ++assigned;
00120         if (xs[i].glbModified()) {
00121           GlbDiffRanges<View> xilb(xs[i]);
00122           Iter::Ranges::ToValues<GlbDiffRanges<View> > dv(xilb);
00123           for (;dv();++dv)
00124             GECODE_ME_CHECK(ys[dv.val()].include(home,i));
00125           xs[i].cacheGlb(home);
00126           again = true;
00127         }
00128         if (xs[i].lubModified()) {
00129           LubDiffRanges<View> xiub(xs[i]);
00130           Iter::Ranges::ToValues<LubDiffRanges<View> > dv(xiub);
00131           for (;dv();++dv)
00132             GECODE_ME_CHECK(ys[dv.val()].exclude(home,i));
00133           xs[i].cacheLub(home);
00134           again = true;
00135         }
00136       }
00137       for (int i=ys.size(); i--;) {
00138         if (ys[i].assigned())
00139           ++assigned;
00140         if (ys[i].glbModified()) {
00141           GlbDiffRanges<View> yilb(ys[i]);
00142           Iter::Ranges::ToValues<GlbDiffRanges<View> > dv(yilb);
00143           for (;dv();++dv)
00144             GECODE_ME_CHECK(xs[dv.val()].include(home,i));
00145           ys[i].cacheGlb(home);
00146           again = true;
00147         }
00148         if (ys[i].lubModified()) {
00149           LubDiffRanges<View> yiub(ys[i]);
00150           Iter::Ranges::ToValues<LubDiffRanges<View> > dv(yiub);
00151           for (;dv();++dv)
00152             GECODE_ME_CHECK(xs[dv.val()].exclude(home,i));
00153           ys[i].cacheLub(home);
00154           again = true;
00155         }
00156       }
00157     }
00158 
00159     return (assigned == xs.size()+ys.size()) ? home.ES_SUBSUMED(*this) : ES_FIX;
00160   }
00161 
00162 }}}
00163 
00164 // STATISTICS: set-prop