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 Int {
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 forceinline size_t
00103 ChannelInt<View>::dispose(Space& home) {
00104 xs.cancel(home,*this, Gecode::Int::PC_INT_DOM);
00105 ys.cancel(home,*this, PC_SET_ANY);
00106 (void) Propagator::dispose(home);
00107 return sizeof(*this);
00108 }
00109
00110 template<class View>
00111 Actor*
00112 ChannelInt<View>::copy(Space& home, bool share) {
00113 return new (home) ChannelInt(home,share,*this);
00114 }
00115
00116 template<class View>
00117 ExecStatus
00118 ChannelInt<View>::propagate(Space& home, const ModEventDelta&) {
00119 int assigned = 0;
00120 for (int v=xs.size(); v--;) {
00121 if (xs[v].assigned()) {
00122 assigned++;
00123 if (xs[v].modified())
00124 GECODE_ME_CHECK(ys[xs[v].val()].include(home,v));
00125 }
00126 if (xs[v].modified()) {
00127 Gecode::Int::ViewDiffRanges<Gecode::Int::IntView> d(xs[v]);
00128 Iter::Ranges::ToValues<Gecode::Int::ViewDiffRanges<
00129 Gecode::Int::IntView> > dv(d);
00130 for (; dv(); ++dv)
00131 GECODE_ME_CHECK(ys[dv.val()].exclude(home, v));
00132 xs[v].cache(home);
00133 }
00134 }
00135
00136 for (int i=ys.size(); i--;) {
00137 if (ys[i].glbModified()) {
00138 GlbDiffRanges<View> yilb(ys[i]);
00139 Iter::Ranges::ToValues<GlbDiffRanges<View> > dv(yilb);
00140 for (;dv();++dv)
00141 GECODE_ME_CHECK(xs[dv.val()].eq(home,i));
00142 ys[i].cacheGlb(home);
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()].nq(home,i));
00149 ys[i].cacheLub(home);
00150 }
00151 }
00152
00153 return (assigned==xs.size()) ? home.ES_SUBSUMED(*this) : ES_NOFIX;
00154 }
00155
00156 }}}
00157
00158