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