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