Generated on Tue Apr 18 10:21:35 2017 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  *  Last modified:
00010  *     $Date: 2016-12-02 13:20:09 +0100 (Fri, 02 Dec 2016) $ by $Author: schulte $
00011  *     $Revision: 15304 $
00012  *
00013  *  This file is part of Gecode, the generic constraint
00014  *  development environment:
00015  *     http://www.gecode.org
00016  *
00017  *  Permission is hereby granted, free of charge, to any person obtaining
00018  *  a copy of this software and associated documentation files (the
00019  *  "Software"), to deal in the Software without restriction, including
00020  *  without limitation the rights to use, copy, modify, merge, publish,
00021  *  distribute, sublicense, and/or sell copies of the Software, and to
00022  *  permit persons to whom the Software is furnished to do so, subject to
00023  *  the following conditions:
00024  *
00025  *  The above copyright notice and this permission notice shall be
00026  *  included in all copies or substantial portions of the Software.
00027  *
00028  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00029  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00030  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00031  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00032  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00033  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00034  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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 // STATISTICS: float-prop