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/float/rel.hh>
00035
00036 namespace Gecode { namespace Float { namespace Bool {
00037
00038 template<class View>
00039 forceinline
00040 Ite<View>::Ite(Home home, Int::BoolView b0, View y0, View y1, View y2)
00041 : Propagator(home), b(b0), x0(y0), x1(y1), x2(y2) {
00042 b.subscribe(home,*this,Int::PC_BOOL_VAL);
00043 x0.subscribe(home,*this,PC_FLOAT_BND);
00044 x1.subscribe(home,*this,PC_FLOAT_BND);
00045 x2.subscribe(home,*this,PC_FLOAT_BND);
00046 }
00047
00048 template<class View>
00049 forceinline
00050 Ite<View>::Ite(Space& home, Ite<View>& p)
00051 : Propagator(home,p) {
00052 b.update(home,p.b);
00053 x0.update(home,p.x0);
00054 x1.update(home,p.x1);
00055 x2.update(home,p.x2);
00056 }
00057
00058 template<class View>
00059 PropCost
00060 Ite<View>::cost(const Space&, const ModEventDelta&) const {
00061 return PropCost::ternary(PropCost::LO);
00062 }
00063
00064 template<class View>
00065 void
00066 Ite<View>::reschedule(Space& home) {
00067 b.reschedule(home,*this,Int::PC_BOOL_VAL);
00068 x0.reschedule(home,*this,PC_FLOAT_BND);
00069 x1.reschedule(home,*this,PC_FLOAT_BND);
00070 x2.reschedule(home,*this,PC_FLOAT_BND);
00071 }
00072
00073 template<class View>
00074 forceinline size_t
00075 Ite<View>::dispose(Space& home) {
00076 b.cancel(home,*this,Int::PC_BOOL_VAL);
00077 x0.cancel(home,*this,PC_FLOAT_BND);
00078 x1.cancel(home,*this,PC_FLOAT_BND);
00079 x2.cancel(home,*this,PC_FLOAT_BND);
00080 (void) Propagator::dispose(home);
00081 return sizeof(*this);
00082 }
00083
00084
00085
00086 template<class View>
00087 Actor*
00088 Ite<View>::copy(Space& home) {
00089 return new (home) Ite<View>(home,*this);
00090 }
00091
00092 template<class View>
00093 inline ExecStatus
00094 Ite<View>::post(Home home, Int::BoolView b, View x0, View x1, View x2) {
00095 if (b.one())
00096 return Rel::Eq<View,View>::post(home,x2,x0);
00097 if (b.zero())
00098 return Rel::Eq<View,View>::post(home,x2,x1);
00099 GECODE_ME_CHECK(x2.lq(home,std::max(x0.max(),x1.max())));
00100 GECODE_ME_CHECK(x2.gq(home,std::min(x0.min(),x1.min())));
00101 (void) new (home) Ite<View>(home,b,x0,x1,x2);
00102 return ES_OK;
00103 }
00104
00105 template<class View>
00106 ExecStatus
00107 Ite<View>::propagate(Space& home, const ModEventDelta&) {
00108 if (b.one())
00109 GECODE_REWRITE(*this,(Rel::Eq<View,View>::post(home(*this),x2,x0)));
00110 if (b.zero())
00111 GECODE_REWRITE(*this,(Rel::Eq<View,View>::post(home(*this),x2,x1)));
00112
00113 GECODE_ME_CHECK(x2.lq(home,std::max(x0.max(),x1.max())));
00114 GECODE_ME_CHECK(x2.gq(home,std::min(x0.min(),x1.min())));
00115
00116 RelTest eq20 = rtest_eq(x2,x0);
00117 RelTest eq21 = rtest_eq(x2,x1);
00118
00119 if ((eq20 == RT_FALSE) && (eq21 == RT_FALSE))
00120 return ES_FAILED;
00121
00122 if (eq20 == RT_FALSE) {
00123 GECODE_ME_CHECK(b.zero_none(home));
00124 if (eq21 == RT_TRUE)
00125 return home.ES_SUBSUMED(*this);
00126 else
00127 GECODE_REWRITE(*this,(Rel::Eq<View,View>::post(home(*this),x2,x1)));
00128 }
00129
00130 if (eq21 == RT_FALSE) {
00131 GECODE_ME_CHECK(b.one_none(home));
00132 if (eq20 == RT_TRUE)
00133 return home.ES_SUBSUMED(*this);
00134 else
00135 GECODE_REWRITE(*this,(Rel::Eq<View,View>::post(home(*this),x2,x0)));
00136 }
00137
00138 if ((eq20 == RT_TRUE) && (eq21 == RT_TRUE))
00139 return home.ES_SUBSUMED(*this);
00140
00141 return ES_FIX;
00142 }
00143
00144 }}}
00145
00146