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 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