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
00039
00040
00041
00042 #include <gecode/int.hh>
00043
00044 namespace Gecode { namespace Set { namespace Channel {
00045
00046 template<class View>
00047 forceinline
00048 ChannelInt<View>::ChannelInt(Home home,
00049 ViewArray<Gecode::Int::CachedView<
00050 Gecode::Int::IntView> >& xs0,
00051 ViewArray<CachedView<View> >& ys0)
00052 : Propagator(home), xs(xs0), ys(ys0) {
00053 for (int i=xs.size(); i--;)
00054 xs[i].initCache(home,IntSet(0,ys.size()-1));
00055 for (int i=ys.size(); i--;)
00056 ys[i].initCache(home,IntSet::empty,IntSet(0,xs.size()-1));
00057 xs.subscribe(home,*this, Gecode::Int::PC_INT_DOM);
00058 ys.subscribe(home,*this, PC_SET_ANY);
00059 }
00060
00061 template<class View>
00062 forceinline
00063 ChannelInt<View>::ChannelInt(Space& home, bool share, ChannelInt& p)
00064 : Propagator(home,share,p) {
00065 xs.update(home,share,p.xs);
00066 ys.update(home,share,p.ys);
00067 }
00068
00069 template<class View>
00070 forceinline ExecStatus
00071 ChannelInt<View>::post(Home home,
00072 ViewArray<Gecode::Int::CachedView<
00073 Gecode::Int::IntView> >& xs,
00074 ViewArray<CachedView<View> >& ys) {
00075
00076
00077
00078 int xssize = xs.size();
00079 for (int i=ys.size(); i--;) {
00080 GECODE_ME_CHECK(ys[i].exclude(home, xssize, Limits::max));
00081 GECODE_ME_CHECK(ys[i].exclude(home, Limits::min, -1));
00082 }
00083 int yssize = ys.size();
00084 if (yssize > Gecode::Int::Limits::max)
00085 return ES_FAILED;
00086 for (int i=xs.size(); i--;) {
00087 GECODE_ME_CHECK(xs[i].gq(home, 0));
00088 GECODE_ME_CHECK(xs[i].le(home, static_cast<int>(yssize)));
00089 }
00090
00091 (void) new (home) ChannelInt(home,xs,ys);
00092 return ES_OK;
00093 }
00094
00095 template<class View>
00096 PropCost
00097 ChannelInt<View>::cost(const Space&, const ModEventDelta&) const {
00098 return PropCost::quadratic(PropCost::LO, xs.size()+ys.size());
00099 }
00100
00101 template<class View>
00102 void
00103 ChannelInt<View>::reschedule(Space& home) {
00104 xs.reschedule(home,*this, Gecode::Int::PC_INT_DOM);
00105 ys.reschedule(home,*this, PC_SET_ANY);
00106 }
00107
00108 template<class View>
00109 forceinline size_t
00110 ChannelInt<View>::dispose(Space& home) {
00111 xs.cancel(home,*this, Gecode::Int::PC_INT_DOM);
00112 ys.cancel(home,*this, PC_SET_ANY);
00113 (void) Propagator::dispose(home);
00114 return sizeof(*this);
00115 }
00116
00117 template<class View>
00118 Actor*
00119 ChannelInt<View>::copy(Space& home, bool share) {
00120 return new (home) ChannelInt(home,share,*this);
00121 }
00122
00123 template<class View>
00124 ExecStatus
00125 ChannelInt<View>::propagate(Space& home, const ModEventDelta&) {
00126 int assigned = 0;
00127 for (int v=xs.size(); v--;) {
00128 if (xs[v].assigned()) {
00129 assigned++;
00130 if (xs[v].modified())
00131 GECODE_ME_CHECK(ys[xs[v].val()].include(home,v));
00132 }
00133 if (xs[v].modified()) {
00134 Gecode::Int::ViewDiffRanges<Gecode::Int::IntView> d(xs[v]);
00135 Iter::Ranges::ToValues<Gecode::Int::ViewDiffRanges<
00136 Gecode::Int::IntView> > dv(d);
00137 for (; dv(); ++dv)
00138 GECODE_ME_CHECK(ys[dv.val()].exclude(home, v));
00139 xs[v].cache(home);
00140 }
00141 }
00142
00143 for (int i=ys.size(); i--;) {
00144 if (ys[i].glbModified()) {
00145 GlbDiffRanges<View> yilb(ys[i]);
00146 Iter::Ranges::ToValues<GlbDiffRanges<View> > dv(yilb);
00147 for (;dv();++dv)
00148 GECODE_ME_CHECK(xs[dv.val()].eq(home,i));
00149 ys[i].cacheGlb(home);
00150 }
00151 if (ys[i].lubModified()) {
00152 LubDiffRanges<View> yiub(ys[i]);
00153 Iter::Ranges::ToValues<LubDiffRanges<View> > dv(yiub);
00154 for (;dv();++dv)
00155 GECODE_ME_CHECK(xs[dv.val()].nq(home,i));
00156 ys[i].cacheLub(home);
00157 }
00158 }
00159
00160 return (assigned==xs.size()) ? home.ES_SUBSUMED(*this) : ES_NOFIX;
00161 }
00162
00163 }}}
00164
00165