Generated on Fri Mar 20 15:56:08 2015 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: 2011-11-03 11:52:07 +0100 (Thu, 03 Nov 2011) $ by $Author: tack $
00011  *     $Revision: 12452 $
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   {
00047     for (int i=xs.size(); i--;)
00048       xs[i].initCache(home,IntSet::empty,IntSet(0,ys.size()-1));
00049     for (int i=ys.size(); i--;)
00050       ys[i].initCache(home,IntSet::empty,IntSet(0,xs.size()-1));
00051     xs.subscribe(home,*this, PC_SET_ANY);
00052     ys.subscribe(home,*this, PC_SET_ANY);
00053   }
00054 
00055   template <typename View>
00056   forceinline
00057   ChannelSet<View>::ChannelSet(Space& home, bool share, ChannelSet& p)
00058     : Propagator(home, share, p)
00059   {
00060     xs.update(home, share, p.xs);
00061     ys.update(home, share, p.ys);
00062   }
00063 
00064   template <typename View>
00065   forceinline ExecStatus
00066   ChannelSet<View>::post(Home home,
00067                          ViewArray<CachedView<View> >& xs,
00068                          ViewArray<CachedView<View> >& ys)
00069   {
00070     int xssize = xs.size();
00071     for (int i=ys.size(); i--;)
00072       {
00073         GECODE_ME_CHECK(ys[i].exclude(home, xssize, Limits::max));
00074         GECODE_ME_CHECK(ys[i].exclude(home, Limits::min, -1));
00075       }
00076     int yssize = ys.size();
00077     for (int i=xs.size(); i--;)
00078       {
00079         GECODE_ME_CHECK(xs[i].exclude(home, yssize, Limits::max));
00080         GECODE_ME_CHECK(xs[i].exclude(home, Limits::min, -1));
00081       }
00082     (void) new (home) ChannelSet(home,xs,ys);
00083     return ES_OK;
00084   }
00085 
00086   template <typename View>
00087   PropCost
00088   ChannelSet<View>::cost(const Space&, const ModEventDelta&) const
00089   {
00090     return PropCost::quadratic(PropCost::HI, xs.size()+ys.size());
00091   }
00092 
00093   template <typename View>
00094   forceinline size_t
00095   ChannelSet<View>::dispose(Space& home)
00096   {
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   {
00107     return new (home) ChannelSet(home,share,*this);
00108   }
00109 
00110   template <typename View>
00111   ExecStatus
00112   ChannelSet<View>::propagate(Space& home, const ModEventDelta&)
00113   {
00114     int assigned = 0;
00115     bool again = true;
00116     while (again)
00117       {
00118         assigned = 0;
00119         again = false;
00120         for (int i=xs.size(); i--;)
00121           {
00122             if (xs[i].assigned())
00123               ++assigned;
00124             if (xs[i].glbModified())
00125               {
00126                 GlbDiffRanges<View> xilb(xs[i]);
00127                 Iter::Ranges::ToValues<GlbDiffRanges<View> > dv(xilb);
00128                 for (;dv();++dv)
00129                   GECODE_ME_CHECK(ys[dv.val()].include(home,i));
00130                 xs[i].cacheGlb(home);
00131                 again = true;
00132               }
00133             if (xs[i].lubModified())
00134               {
00135                 LubDiffRanges<View> xiub(xs[i]);
00136                 Iter::Ranges::ToValues<LubDiffRanges<View> > dv(xiub);
00137                 for (;dv();++dv)
00138                   GECODE_ME_CHECK(ys[dv.val()].exclude(home,i));
00139                 xs[i].cacheLub(home);
00140                 again = true;
00141               }
00142           }
00143         for (int i=ys.size(); i--;)
00144           {
00145             if (ys[i].assigned())
00146               ++assigned;
00147             if (ys[i].glbModified())
00148               {
00149                 GlbDiffRanges<View> yilb(ys[i]);
00150                 Iter::Ranges::ToValues<GlbDiffRanges<View> > dv(yilb);
00151                 for (;dv();++dv)
00152                   GECODE_ME_CHECK(xs[dv.val()].include(home,i));
00153                 ys[i].cacheGlb(home);
00154                 again = true;
00155               }
00156             if (ys[i].lubModified())
00157               {
00158                 LubDiffRanges<View> yiub(ys[i]);
00159                 Iter::Ranges::ToValues<LubDiffRanges<View> > dv(yiub);
00160                 for (;dv();++dv)
00161                   GECODE_ME_CHECK(xs[dv.val()].exclude(home,i));
00162                 ys[i].cacheLub(home);
00163                 again = true;
00164               }
00165           }
00166       }
00167 
00168     return (assigned == xs.size()+ys.size()) ? home.ES_SUBSUMED(*this) : ES_FIX;
00169   }
00170 }}}
00171 
00172 // STATISTICS: set-prop