Generated on Tue Apr 18 10:21:52 2017 for Gecode by doxygen 1.6.3

eqite.cpp

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