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 Prop<View>::Prop(Home home, ValSet& vs0, ViewArray<View>& x, View y)
00045 : NaryOnePropagator<View,PC_INT_DOM>(home,x,y),
00046 vs(vs0) {}
00047
00048 template<class View>
00049 forceinline void
00050 Prop<View>::add(Space& home, ValSet& vs, ViewArray<View>& x) {
00051 int n=x.size();
00052 for (int i=n; i--; )
00053 if (x[i].assigned()) {
00054 vs.add(home, x[i].val());
00055 x[i] = x[--n];
00056 }
00057 x.size(n);
00058 }
00059
00060 template<class View>
00061 forceinline void
00062 Prop<View>::eliminate(Space& home) {
00063 int n=x.size();
00064 for (int i=n; i--; )
00065 if ((rtest_eq_dom(x[i],y) == RT_FALSE) || vs.subset(x[i])) {
00066
00067 x[i].cancel(home, *this, PC_INT_DOM);
00068 x[i] = x[--n];
00069 }
00070 x.size(n);
00071 }
00072
00073 template<class View>
00074 inline ExecStatus
00075 Prop<View>::post(Home home, ViewArray<View>& x, View y) {
00076 if (x.size() == 0)
00077 return ES_FAILED;
00078
00079 x.unique(home);
00080
00081 if (x.size() == 1)
00082 return Rel::EqDom<View,View>::post(home,x[0],y);
00083
00084 if (x.same(home,y))
00085 return ES_OK;
00086
00087
00088 ValSet vs;
00089 add(home, vs, x);
00090
00091 if (x.size() == 0) {
00092 ValSet::Ranges vsr(vs);
00093 GECODE_ME_CHECK(y.inter_r(home,vsr,false));
00094 return ES_OK;
00095 }
00096
00097 (void) new (home) Prop<View>(home, vs, x, y);
00098 return ES_OK;
00099 }
00100
00101 template<class View>
00102 forceinline ExecStatus
00103 Prop<View>::post(Home home, ValSet& vs, ViewArray<View>& x, View y) {
00104 (void) new (home) Prop<View>(home, vs, x, y);
00105 return ES_OK;
00106 }
00107
00108 template<class View>
00109 forceinline
00110 Prop<View>::Prop(Space& home, bool share, Prop<View>& p)
00111 : NaryOnePropagator<View,PC_INT_DOM>(home, share, p) {
00112 vs.update(home, share, p.vs);
00113 }
00114
00115 template<class View>
00116 Propagator*
00117 Prop<View>::copy(Space& home, bool share) {
00118 return new (home) Prop<View>(home, share, *this);
00119 }
00120
00121 template<class View>
00122 forceinline size_t
00123 Prop<View>::dispose(Space& home) {
00124 vs.dispose(home);
00125 (void) NaryOnePropagator<View,PC_INT_DOM>::dispose(home);
00126 return sizeof(*this);
00127 }
00128
00129 template<class View>
00130 PropCost
00131 Prop<View>::cost(const Space&, const ModEventDelta&) const {
00132 return PropCost::linear(PropCost::HI, x.size()+1);
00133 }
00134
00135 template<class View>
00136 ExecStatus
00137 Prop<View>::propagate(Space& home, const ModEventDelta& med) {
00138
00139 if (View::me(med) == ME_INT_VAL)
00140 add(home,vs,x);
00141
00142
00143 eliminate(home);
00144
00145 if (x.size() == 0) {
00146
00147 ValSet::Ranges vsr(vs);
00148 GECODE_ME_CHECK(y.inter_r(home,vsr,false));
00149 return home.ES_SUBSUMED(*this);
00150 }
00151
00152
00153 Region r(home);
00154
00155 assert(x.size() > 0);
00156 ValSet::Ranges vsr(vs);
00157 ViewRanges<View> xsr(x[x.size()-1]);
00158 Iter::Ranges::NaryUnion u(r,vsr,xsr);
00159 for (int i=x.size()-1; i--; ) {
00160 ViewRanges<View> xir(x[i]);
00161 u |= xir;
00162 }
00163
00164 GECODE_ME_CHECK(y.inter_r(home,u,false));
00165
00166
00167 if (vs.subset(y))
00168 return home.ES_SUBSUMED(*this);
00169
00170 return ES_FIX;
00171 }
00172
00173 }}}
00174
00175