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