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