/* -*- 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 Eq::Eq(Space* home, BVA b0, BVB b1) : BoolBinary(home,b0,b1) {} template forceinline Eq::Eq(Space* home, bool share, Eq& p) : BoolBinary(home,share,p) {} template forceinline Eq::Eq(Space* home, bool share, Propagator& p, BVA b0, BVB b1) : BoolBinary(home,share,p,b0,b1) {} template Actor* Eq::copy(Space* home, bool share) { return new (home) Eq(home,share,*this); } template inline ExecStatus Eq::post(Space* home, BVA b0, BVB b1) { switch (bool_test(b0,b1)) { case BT_SAME: return ES_OK; case BT_COMP: return ES_FAILED; case BT_NONE: if (b0.zero()) { GECODE_ME_CHECK(b1.zero(home)); } else if (b0.one()) { GECODE_ME_CHECK(b1.one(home)); } else if (b1.zero()) { GECODE_ME_CHECK(b0.zero(home)); } else if (b1.one()) { GECODE_ME_CHECK(b0.one(home)); } else { (void) new (home) Eq(home,b0,b1); } break; default: GECODE_NEVER; } return ES_OK; } template ExecStatus Eq::propagate(Space* home, ModEventDelta) { #define GECODE_INT_STATUS(S0,S1) \ ((BVA::S0<<(1*BVA::BITS))|(BVB::S1<<(0*BVB::BITS))) switch ((x0.status() << (1*BVA::BITS)) | (x1.status() << (0*BVB::BITS))) { case GECODE_INT_STATUS(NONE,NONE): GECODE_NEVER; case GECODE_INT_STATUS(NONE,ZERO): GECODE_ME_CHECK(x0.zero_none(home)); break; case GECODE_INT_STATUS(NONE,ONE): GECODE_ME_CHECK(x0.one_none(home)); break; case GECODE_INT_STATUS(ZERO,NONE): GECODE_ME_CHECK(x1.zero_none(home)); break; case GECODE_INT_STATUS(ZERO,ZERO): break; case GECODE_INT_STATUS(ZERO,ONE): return ES_FAILED; case GECODE_INT_STATUS(ONE,NONE): GECODE_ME_CHECK(x1.one_none(home)); break; case GECODE_INT_STATUS(ONE,ZERO): return ES_FAILED; case GECODE_INT_STATUS(ONE,ONE): break; default: GECODE_NEVER; } return ES_SUBSUMED(this,sizeof(*this)); #undef GECODE_INT_STATUS } template inline Support::Symbol Eq::ati(void) { return Reflection::mangle("Gecode::Int::Bool::Eq"); } template Reflection::ActorSpec Eq::spec(const Space* home, Reflection::VarMap& m) const { return BoolBinary::spec(home, m, ati()); } template void Eq::post(Space* home, Reflection::VarMap& vars, const Reflection::ActorSpec& spec) { spec.checkArity(2); BVA b0(home, vars, spec[0]); BVB b1(home, vars, spec[1]); (void) new (home) Eq(home,b0,b1); } template forceinline NaryEq::NaryEq(Space* home, ViewArray& x) : NaryPropagator(home,x) {} template forceinline NaryEq::NaryEq(Space* home, bool share, NaryEq& p) : NaryPropagator(home,share,p) {} template Actor* NaryEq::copy(Space* home, bool share) { return new (home) NaryEq(home,share,*this); } template inline ExecStatus NaryEq::post(Space* home, ViewArray& x) { x.unique(); int n = x.size(); if (n < 2) return ES_OK; if (n == 2) return Eq::post(home,x[0],x[1]); for (int i=n; i--; ) if (x[i].assigned()) { if (x[i].one()) { for (int j=i; j--; ) GECODE_ME_CHECK(x[j].one(home)); for (int j=i+1; j(home,x); return ES_OK; } template void NaryEq::post(Space* home, Reflection::VarMap& vars, const Reflection::ActorSpec& spec) { spec.checkArity(1); ViewArray x(home, vars, spec[0]); (void) new (home) NaryEq(home, x); } template PropCost NaryEq::cost(ModEventDelta) const { return PC_UNARY_LO; } template ExecStatus NaryEq::propagate(Space* home, ModEventDelta) { int n=x.size(); int i=0; while (true) { if (x[i].assigned()) { if (x[i].one()) { for (int j=0; j Support::Symbol NaryEq::ati(void) { return Reflection::mangle("Gecode::Int::Bool::NaryEq"); } template Reflection::ActorSpec NaryEq::spec(const Space* home, Reflection::VarMap& m) const { return NaryPropagator::spec(home, m, ati()); } }}} // STATISTICS: int-prop