00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
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