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 namespace Gecode { namespace Set { namespace Rel {
00037
00038 template<class View0, class View1, class CtrlView, ReifyMode rm>
00039 forceinline
00040 ReSubset<View0,View1,CtrlView,rm>::ReSubset(Home home, View0 y0,
00041 View1 y1, CtrlView b0)
00042 : Propagator(home), x0(y0), x1(y1), b(b0) {
00043 b.subscribe(home,*this, Gecode::Int::PC_INT_VAL);
00044 x0.subscribe(home,*this, PC_SET_ANY);
00045 x1.subscribe(home,*this, PC_SET_ANY);
00046 }
00047
00048 template<class View0, class View1, class CtrlView, ReifyMode rm>
00049 forceinline
00050 ReSubset<View0,View1,CtrlView,rm>::ReSubset(Space& home,
00051 ReSubset& p)
00052 : Propagator(home,p) {
00053 x0.update(home,p.x0);
00054 x1.update(home,p.x1);
00055 b.update(home,p.b);
00056 }
00057
00058 template<class View0, class View1, class CtrlView, ReifyMode rm>
00059 PropCost
00060 ReSubset<View0,View1,CtrlView,rm>::cost(const Space&,
00061 const ModEventDelta&) const {
00062 return PropCost::ternary(PropCost::LO);
00063 }
00064
00065 template<class View0, class View1, class CtrlView, ReifyMode rm>
00066 void
00067 ReSubset<View0,View1,CtrlView,rm>::reschedule(Space& home) {
00068 b.reschedule(home,*this, Gecode::Int::PC_INT_VAL);
00069 x0.reschedule(home,*this, PC_SET_ANY);
00070 x1.reschedule(home,*this, PC_SET_ANY);
00071 }
00072
00073 template<class View0, class View1, class CtrlView, ReifyMode rm>
00074 forceinline size_t
00075 ReSubset<View0,View1,CtrlView,rm>::dispose(Space& home) {
00076 b.cancel(home,*this, Gecode::Int::PC_INT_VAL);
00077 x0.cancel(home,*this, PC_SET_ANY);
00078 x1.cancel(home,*this, PC_SET_ANY);
00079 (void) Propagator::dispose(home);
00080 return sizeof(*this);
00081 }
00082
00083 template<class View0, class View1, class CtrlView, ReifyMode rm>
00084 ExecStatus
00085 ReSubset<View0,View1,CtrlView,rm>::post(Home home, View0 x0, View1 x1,
00086 CtrlView b) {
00087 if (!same(x0,x1)) {
00088 (void) new (home) ReSubset<View0,View1,CtrlView,rm>(home,x0,x1,b);
00089 } else if (rm != RM_IMP) {
00090 GECODE_ME_CHECK(b.one(home));
00091 }
00092 return ES_OK;
00093 }
00094
00095 template<class View0, class View1, class CtrlView, ReifyMode rm>
00096 Actor*
00097 ReSubset<View0,View1,CtrlView,rm>::copy(Space& home) {
00098 return new (home) ReSubset<View0,View1,CtrlView,rm>(home,*this);
00099 }
00100
00101 template<class View0, class View1, class CtrlView, ReifyMode rm>
00102 ExecStatus
00103 ReSubset<View0,View1,CtrlView,rm>::propagate(Space& home,
00104 const ModEventDelta&) {
00105 if (b.one()) {
00106 if (rm == RM_PMI)
00107 return home.ES_SUBSUMED(*this);
00108 GECODE_REWRITE(*this,(Subset<View0,View1>::post(home(*this),x0,x1)));
00109 }
00110 if (b.zero()) {
00111 if (rm == RM_IMP)
00112 return home.ES_SUBSUMED(*this);
00113 GECODE_REWRITE(*this,(NoSubset<View0,View1>::post(home(*this),x0,x1)));
00114 }
00115
00116
00117 if (x0.cardMin() > x1.cardMax()) {
00118 if (rm != RM_PMI)
00119 GECODE_ME_CHECK(b.zero_none(home));
00120 return home.ES_SUBSUMED(*this);
00121 }
00122
00123
00124 {
00125 LubRanges<View0> x0ub(x0);
00126 GlbRanges<View1> x1lb(x1);
00127 Iter::Ranges::Diff<LubRanges<View0>,GlbRanges<View1> > d(x0ub,x1lb);
00128 if (!d()) {
00129 if (rm != RM_IMP)
00130 GECODE_ME_CHECK(b.one_none(home));
00131 return home.ES_SUBSUMED(*this);
00132 }
00133 }
00134
00135
00136 {
00137 GlbRanges<View0> x0lb(x0);
00138 LubRanges<View1> x1ub(x1);
00139 Iter::Ranges::Diff<GlbRanges<View0>,LubRanges<View1> > d(x0lb,x1ub);
00140 if (d()) {
00141 if (rm != RM_PMI)
00142 GECODE_ME_CHECK(b.zero_none(home));
00143 return home.ES_SUBSUMED(*this);
00144 } else if (x0.assigned() && x1.assigned()) {
00145 if (rm != RM_IMP)
00146 GECODE_ME_CHECK(b.one_none(home));
00147 return home.ES_SUBSUMED(*this);
00148 }
00149 }
00150
00151 if (x0.cardMin() > 0) {
00152 LubRanges<View0> x0ub(x0);
00153 LubRanges<View1> x1ub(x1);
00154 Iter::Ranges::Inter<LubRanges<View0>,LubRanges<View1> >
00155 i(x0ub,x1ub);
00156 if (!i()) {
00157 if (rm != RM_PMI)
00158 GECODE_ME_CHECK(b.zero_none(home));
00159 return home.ES_SUBSUMED(*this);
00160 }
00161 }
00162
00163 return ES_FIX;
00164 }
00165
00166 }}}
00167
00168