eqite.cpp
Go to the documentation of this file.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/distinct.hh>
00039
00040 #include <algorithm>
00041
00042 namespace Gecode { namespace Int { namespace Distinct {
00043
00044 PropCost
00045 EqIte::cost(const Space&, const ModEventDelta&) const {
00046 return PropCost::binary(PropCost::HI);
00047 }
00048
00049 Actor*
00050 EqIte::copy(Space& home, bool share) {
00051 return new (home) EqIte(home,share,*this);
00052 }
00053
00054 ExecStatus
00055 EqIte::propagate(Space& home, const ModEventDelta&) {
00056 switch (rtest_eq_dom(x0,c0)) {
00057 case RT_TRUE:
00058 GECODE_ME_CHECK(x1.eq(home,c1));
00059 return home.ES_SUBSUMED(*this);
00060 case RT_FALSE:
00061 GECODE_REWRITE(*this,(Rel::EqDom<IntView,IntView>
00062 ::post(home(*this),x0,x1)));
00063 GECODE_NEVER;
00064 case RT_MAYBE:
00065 break;
00066 default: GECODE_NEVER;
00067 }
00068
00069 GECODE_ME_CHECK(x1.lq(home,std::max(x0.max(),c1)));
00070 GECODE_ME_CHECK(x1.gq(home,std::min(x0.min(),c1)));
00071
00072 RelTest eq_then = rtest_eq_dom(x1,c1);
00073 RelTest eq_else = rtest_eq_dom(x1,x0);
00074
00075 if ((eq_then == RT_FALSE) && (eq_else == RT_FALSE))
00076 return ES_FAILED;
00077
00078 if (eq_then == RT_FALSE) {
00079
00080 GECODE_ME_CHECK(x0.nq(home,c0));
00081 if (eq_else == RT_TRUE)
00082 return home.ES_SUBSUMED(*this);
00083 else
00084 GECODE_REWRITE(*this,
00085 (Rel::EqDom<IntView,IntView>::post(home(*this),x0,x1)));
00086 }
00087
00088 if (eq_else == RT_FALSE) {
00089
00090 GECODE_ME_CHECK(x0.eq(home,c0));
00091 GECODE_ME_CHECK(x1.eq(home,c1));
00092 return home.ES_SUBSUMED(*this);
00093 }
00094
00095
00096 assert((eq_then != RT_TRUE) || (eq_else != RT_TRUE));
00097
00098 ViewRanges<IntView> r0(x0);
00099 Iter::Ranges::Singleton r1(c1,c1);
00100 Iter::Ranges::Union<ViewRanges<IntView>,
00101 Iter::Ranges::Singleton > u(r0,r1);
00102
00103 GECODE_ME_CHECK(x1.inter_r(home,u,true));
00104
00105 return ES_FIX;
00106 }
00107
00108 }}}
00109
00110