/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ /* * Main authors: * Christian Schulte * * Copyright: * Christian Schulte, 2004 * * Last modified: * $Date: 2008-01-31 18:29:16 +0100 (Thu, 31 Jan 2008) $ by $Author: tack $ * $Revision: 6017 $ * * This file is part of Gecode, the generic constraint * development environment: * http://www.gecode.org * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */ namespace Gecode { namespace Int { namespace Bool { template forceinline Eqv::Eqv(Space* home, BVA b0, BVB b1, BVC b2) : BoolTernary(home,b0,b1,b2) {} template forceinline Eqv::Eqv(Space* home, bool share, Eqv& p) : BoolTernary(home,share,p) {} template inline ExecStatus Eqv::post(Space* home, BVA b0, BVB b1, BVC b2){ switch (bool_test(b0,b1)) { case BT_SAME: GECODE_ME_CHECK(b2.one(home)); break; case BT_COMP: GECODE_ME_CHECK(b2.zero(home)); break; case BT_NONE: if (b2.one()) return Eq::post(home,b0,b1); if (b0.one()) { if (b1.one()) { GECODE_ME_CHECK(b2.one(home)); return ES_OK; } else if (b1.zero()) { GECODE_ME_CHECK(b2.zero(home)); return ES_OK; } } if (b0.zero()) { if (b1.one()) { GECODE_ME_CHECK(b2.zero(home)); return ES_OK; } else if (b1.zero()) { GECODE_ME_CHECK(b2.one(home)); return ES_OK; } } (void) new (home) Eqv(home,b0,b1,b2); break; default: GECODE_NEVER; } return ES_OK; } template Actor* Eqv::copy(Space* home, bool share) { return new (home) Eqv(home,share,*this); } template ExecStatus Eqv::propagate(Space* home, ModEventDelta) { #define GECODE_INT_STATUS(S0,S1,S2) \ ((BVA::S0<<(2*BVA::BITS))|(BVB::S1<<(1*BVB::BITS))|(BVC::S2<<(0*BVC::BITS))) switch ((x0.status() << (2*BVA::BITS)) | (x1.status() << (1*BVB::BITS)) | (x2.status() << (0*BVC::BITS))) { case GECODE_INT_STATUS(NONE,NONE,NONE): GECODE_NEVER; case GECODE_INT_STATUS(NONE,NONE,ZERO): case GECODE_INT_STATUS(NONE,NONE,ONE): case GECODE_INT_STATUS(NONE,ZERO,NONE): return ES_FIX; case GECODE_INT_STATUS(NONE,ZERO,ZERO): GECODE_ME_CHECK(x0.one_none(home)); break; case GECODE_INT_STATUS(NONE,ZERO,ONE): GECODE_ME_CHECK(x0.zero_none(home)); break; case GECODE_INT_STATUS(NONE,ONE,NONE): return ES_FIX; case GECODE_INT_STATUS(NONE,ONE,ZERO): GECODE_ME_CHECK(x0.zero_none(home)); break; case GECODE_INT_STATUS(NONE,ONE,ONE): GECODE_ME_CHECK(x0.one_none(home)); break; case GECODE_INT_STATUS(ZERO,NONE,NONE): return ES_FIX; case GECODE_INT_STATUS(ZERO,NONE,ZERO): GECODE_ME_CHECK(x1.one_none(home)); break; case GECODE_INT_STATUS(ZERO,NONE,ONE): GECODE_ME_CHECK(x1.zero_none(home)); break; case GECODE_INT_STATUS(ZERO,ZERO,NONE): GECODE_ME_CHECK(x2.one_none(home)); break; case GECODE_INT_STATUS(ZERO,ZERO,ZERO): return ES_FAILED; case GECODE_INT_STATUS(ZERO,ZERO,ONE): break; case GECODE_INT_STATUS(ZERO,ONE,NONE): GECODE_ME_CHECK(x2.zero_none(home)); break; case GECODE_INT_STATUS(ZERO,ONE,ZERO): break; case GECODE_INT_STATUS(ZERO,ONE,ONE): return ES_FAILED; case GECODE_INT_STATUS(ONE,NONE,NONE): return ES_FIX; case GECODE_INT_STATUS(ONE,NONE,ZERO): GECODE_ME_CHECK(x1.zero_none(home)); break; case GECODE_INT_STATUS(ONE,NONE,ONE): GECODE_ME_CHECK(x1.one_none(home)); break; case GECODE_INT_STATUS(ONE,ZERO,NONE): GECODE_ME_CHECK(x2.zero_none(home)); break; case GECODE_INT_STATUS(ONE,ZERO,ZERO): break; case GECODE_INT_STATUS(ONE,ZERO,ONE): return ES_FAILED; case GECODE_INT_STATUS(ONE,ONE,NONE): GECODE_ME_CHECK(x2.one_none(home)); break; case GECODE_INT_STATUS(ONE,ONE,ZERO): return ES_FAILED; case GECODE_INT_STATUS(ONE,ONE,ONE): break; default: GECODE_NEVER; } return ES_SUBSUMED(this,sizeof(*this)); #undef GECODE_INT_STATUS } template inline Support::Symbol Eqv::ati(void) { return Reflection::mangle("Gecode::Int::Bool::Eqv"); } template Reflection::ActorSpec Eqv::spec(const Space* home, Reflection::VarMap& m) const { return BoolTernary::spec(home, m, ati()); } template void Eqv::post(Space* home, Reflection::VarMap& vars, const Reflection::ActorSpec& spec) { spec.checkArity(3); BVA b0(home, vars, spec[0]); BVB b1(home, vars, spec[1]); BVC b2(home, vars, spec[2]); (void) new (home) Eqv(home,b0,b1,b2); } }}} // STATISTICS: int-prop