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 #include <gecode/int/rel.hh>
00039
00040 namespace Gecode { namespace Int { namespace Member {
00041
00042 template<class View>
00043 forceinline
00044 ReProp<View>::ReProp(Home home, ValSet& vs, ViewArray<View>& x, View y,
00045 BoolView b0)
00046 : Prop<View>(home,vs,x,y), b(b0) {
00047 b.subscribe(home,*this,PC_BOOL_VAL);
00048 }
00049
00050 template<class View>
00051 inline ExecStatus
00052 ReProp<View>::post(Home home, ViewArray<View>& x, View y, BoolView b) {
00053 if (x.size() == 0) {
00054 GECODE_ME_CHECK(b.zero(home));
00055 return ES_OK;
00056 }
00057
00058 x.unique(home);
00059
00060 if (x.size() == 1)
00061 return Rel::ReEqDom<View,BoolView>::post(home,x[0],y,b);
00062
00063 if (x.same(home,y)) {
00064 GECODE_ME_CHECK(b.one(home));
00065 return ES_OK;
00066 }
00067
00068
00069 ValSet vs;
00070 add(home, vs, x);
00071
00072 switch (vs.compare(y)) {
00073 case Iter::Ranges::CS_SUBSET:
00074 GECODE_ME_CHECK(b.one(home));
00075 return ES_OK;
00076 case Iter::Ranges::CS_DISJOINT:
00077 if (x.size() == 0) {
00078 GECODE_ME_CHECK(b.zero(home));
00079 return ES_OK;
00080 }
00081 break;
00082 case Iter::Ranges::CS_NONE:
00083 break;
00084 default:
00085 GECODE_NEVER;
00086 }
00087
00088 (void) new (home) ReProp<View>(home, vs, x, y, b);
00089 return ES_OK;
00090 }
00091
00092 template<class View>
00093 forceinline
00094 ReProp<View>::ReProp(Space& home, bool share, ReProp<View>& p)
00095 : Prop<View>(home, share, p) {
00096 b.update(home, share, p.b);
00097 }
00098
00099 template<class View>
00100 Propagator*
00101 ReProp<View>::copy(Space& home, bool share) {
00102 return new (home) ReProp<View>(home, share, *this);
00103 }
00104
00105 template<class View>
00106 forceinline size_t
00107 ReProp<View>::dispose(Space& home) {
00108 b.cancel(home, *this, PC_BOOL_VAL);
00109 (void) Prop<View>::dispose(home);
00110 return sizeof(*this);
00111 }
00112
00113 template<class View>
00114 ExecStatus
00115 ReProp<View>::propagate(Space& home, const ModEventDelta& med) {
00116
00117 if (View::me(med) == ME_INT_VAL)
00118 add(home,vs,x);
00119
00120 if (b.one()) {
00121 ValSet vsc(vs);
00122 vs.flush();
00123 GECODE_REWRITE(*this,Prop<View>::post(home,vsc,x,y));
00124 }
00125
00126 if (b.zero()) {
00127 ValSet::Ranges vsr(vs);
00128 GECODE_ME_CHECK(y.minus_r(home,vsr,false));
00129 for (int i=x.size(); i--; )
00130 GECODE_ES_CHECK(Rel::Nq<View>::post(home,x[i],y));
00131 return home.ES_SUBSUMED(*this);
00132 }
00133
00134
00135 eliminate(home);
00136
00137 switch (vs.compare(y)) {
00138 case Iter::Ranges::CS_SUBSET:
00139 GECODE_ME_CHECK(b.one(home));
00140 return home.ES_SUBSUMED(*this);
00141 case Iter::Ranges::CS_DISJOINT:
00142 if (x.size() == 0) {
00143 GECODE_ME_CHECK(b.zero(home));
00144 return home.ES_SUBSUMED(*this);
00145 }
00146 break;
00147 case Iter::Ranges::CS_NONE:
00148 break;
00149 default:
00150 GECODE_NEVER;
00151 }
00152
00153
00154 if (x.size() > 0) {
00155 Region r(home);
00156
00157 ValSet::Ranges vsr(vs);
00158 ViewRanges<View> xsr(x[x.size()-1]);
00159 Iter::Ranges::NaryUnion u(r,vsr,xsr);
00160 for (int i=x.size()-1; i--; ) {
00161 ViewRanges<View> xir(x[i]);
00162 u |= xir;
00163 }
00164
00165 ViewRanges<View> yr(y);
00166
00167 if (Iter::Ranges::disjoint(u,yr)) {
00168 GECODE_ME_CHECK(b.zero(home));
00169 return home.ES_SUBSUMED(*this);
00170 }
00171 }
00172
00173 return ES_FIX;
00174 }
00175
00176 }}}
00177
00178