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