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