Generated on Fri Oct 19 11:24:53 2018 for Gecode by doxygen 1.6.3

ite.hpp

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Christian Schulte <schulte@gecode.org>
00005  *
00006  *  Copyright:
00007  *     Christian Schulte, 2016
00008  *
00009  *  This file is part of Gecode, the generic constraint
00010  *  development environment:
00011  *     http://www.gecode.org
00012  *
00013  *  Permission is hereby granted, free of charge, to any person obtaining
00014  *  a copy of this software and associated documentation files (the
00015  *  "Software"), to deal in the Software without restriction, including
00016  *  without limitation the rights to use, copy, modify, merge, publish,
00017  *  distribute, sublicense, and/or sell copies of the Software, and to
00018  *  permit persons to whom the Software is furnished to do so, subject to
00019  *  the following conditions:
00020  *
00021  *  The above copyright notice and this permission notice shall be
00022  *  included in all copies or substantial portions of the Software.
00023  *
00024  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00025  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00026  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00027  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00028  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00029  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00030  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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 // STATISTICS: float-prop