/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ /* * Main authors: * Christian Schulte * * Copyright: * Christian Schulte, 2004 * * Last modified: * $Date: 2008-02-25 00:16:01 +0100 (Mon, 25 Feb 2008) $ by $Author: schulte $ * $Revision: 6288 $ * * 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 { /// Binary Boolean disjunction propagator (subsumed) template class OrTrueSubsumed : public BoolBinary { protected: using BoolBinary::x0; using BoolBinary::x1; /// Constructor for cloning \a p OrTrueSubsumed(Space* home, bool share, OrTrueSubsumed& p); public: /// Constructor OrTrueSubsumed(Space* home, BV b0, BV b1); /// Constructor for rewriting \a p during cloning OrTrueSubsumed(Space* home, bool share, Propagator& p, BV b0, BV b1); /// Copy propagator during cloning virtual Actor* copy(Space* home, bool share); /// Perform propagation virtual ExecStatus propagate(Space* home, ModEventDelta med); /// Specification for this propagator virtual Reflection::ActorSpec spec(const Space* home, Reflection::VarMap& m) const; /// Post using specification static void post(Space* home, Reflection::VarMap& vars, const Reflection::ActorSpec& spec); /// Actor type identifier of this propagator static Support::Symbol ati(void); }; template forceinline OrTrueSubsumed::OrTrueSubsumed (Space* home, BV b0, BV b1) : BoolBinary(home,b0,b1) {} template forceinline OrTrueSubsumed::OrTrueSubsumed (Space* home, bool share, OrTrueSubsumed& p) : BoolBinary(home,share,p) {} template forceinline OrTrueSubsumed::OrTrueSubsumed(Space* home, bool share, Propagator& p, BV b0, BV b1) : BoolBinary(home,share,p,b0,b1) {} template Actor* OrTrueSubsumed::copy(Space* home, bool share) { return new (home) OrTrueSubsumed(home,share,*this); } template ExecStatus OrTrueSubsumed::propagate(Space* home, ModEventDelta) { return ES_SUBSUMED(this,home); } template inline Support::Symbol OrTrueSubsumed::ati(void) { return Reflection::mangle("Gecode::Int::Bool::OrTrueSubsumed"); } template Reflection::ActorSpec OrTrueSubsumed::spec(const Space* home, Reflection::VarMap& m) const { return BoolBinary::spec(home, m, ati()); } template void OrTrueSubsumed::post(Space* home, Reflection::VarMap& vars, const Reflection::ActorSpec& spec) { spec.checkArity(2); BV b0(home, vars, spec[0]); BV b1(home, vars, spec[1]); (void) new (home) OrTrueSubsumed(home,b0,b1); } /* * Binary Boolean disjunction propagator (true) * */ template forceinline BinOrTrue::BinOrTrue(Space* home, BVA b0, BVB b1) : BoolBinary(home,b0,b1) {} template forceinline BinOrTrue::BinOrTrue(Space* home, bool share, BinOrTrue& p) : BoolBinary(home,share,p) {} template forceinline BinOrTrue::BinOrTrue(Space* home, bool share, Propagator& p, BVA b0, BVB b1) : BoolBinary(home,share,p,b0,b1) {} template Actor* BinOrTrue::copy(Space* home, bool share) { return new (home) BinOrTrue(home,share,*this); } template inline ExecStatus BinOrTrue::post(Space* home, BVA b0, BVB b1) { switch (bool_test(b0,b1)) { case BT_SAME: GECODE_ME_CHECK(b0.one(home)); break; case BT_COMP: break; case BT_NONE: if (b0.zero()) { GECODE_ME_CHECK(b1.one(home)); } else if (b1.zero()) { GECODE_ME_CHECK(b0.one(home)); } else if (!b0.one() && !b1.one()) { (void) new (home) BinOrTrue(home,b0,b1); } break; default: GECODE_NEVER; } return ES_OK; } template ExecStatus BinOrTrue::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.one_none(home)); break; case GECODE_INT_STATUS(NONE,ONE): x0.cancel(home,this,PC_BOOL_VAL); break; case GECODE_INT_STATUS(ZERO,NONE): GECODE_ME_CHECK(x1.one_none(home)); break; case GECODE_INT_STATUS(ZERO,ZERO): return ES_FAILED; case GECODE_INT_STATUS(ZERO,ONE): break; case GECODE_INT_STATUS(ONE,NONE): x1.cancel(home,this,PC_BOOL_VAL); break; case GECODE_INT_STATUS(ONE,ZERO): break; case GECODE_INT_STATUS(ONE,ONE): break; default: GECODE_NEVER; } return ES_SUBSUMED(this,sizeof(*this)); #undef GECODE_INT_STATUS } template Support::Symbol BinOrTrue::ati(void) { return Reflection::mangle("Gecode::Int::Bool::BinOrTrue"); } template Reflection::ActorSpec BinOrTrue::spec(const Space* home, Reflection::VarMap& m) const { return BoolBinary::spec(home, m, ati()); } template void BinOrTrue::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) BinOrTrue(home,b0,b1); } /* * Boolean disjunction propagator (true) * */ template forceinline TerOrTrue::TerOrTrue(Space* home, BV b0, BV b1, BV b2) : BoolBinary(home,b0,b1), x2(b2) {} template forceinline size_t TerOrTrue::dispose(Space* home) { (void) BoolBinary::dispose(home); return sizeof(*this); } template forceinline TerOrTrue::TerOrTrue(Space* home, bool share, TerOrTrue& p) : BoolBinary(home,share,p) { x2.update(home,share,p.x2); } template forceinline TerOrTrue::TerOrTrue(Space* home, bool share, Propagator& p, BV b0, BV b1, BV b2) : BoolBinary(home,share,p,b0,b1) { x2.update(home,share,b2); } template Actor* TerOrTrue::copy(Space* home, bool share) { assert(x0.none() && x1.none()); if (x2.one()) return new (home) OrTrueSubsumed(home,share,*this,x0,x1); else if (x2.zero()) return new (home) BinOrTrue(home,share,*this,x0,x1); else return new (home) TerOrTrue(home,share,*this); } template forceinline ExecStatus TerOrTrue::post(Space* home, BV b0, BV b1, BV b2) { (void) new (home) TerOrTrue(home,b0,b1,b2); return ES_OK; } template ExecStatus TerOrTrue::propagate(Space* home, ModEventDelta) { #define GECODE_INT_STATUS(S0,S1,S2) \ ((BV::S0<<(2*BV::BITS))|(BV::S1<<(1*BV::BITS))|(BV::S2<<(0*BV::BITS))) switch ((x0.status() << (2*BV::BITS)) | (x1.status() << (1*BV::BITS)) | (x2.status() << (0*BV::BITS))) { case GECODE_INT_STATUS(NONE,NONE,NONE): case GECODE_INT_STATUS(NONE,NONE,ZERO): case GECODE_INT_STATUS(NONE,NONE,ONE): GECODE_NEVER; case GECODE_INT_STATUS(NONE,ZERO,NONE): std::swap(x1,x2); x1.subscribe(home,this,PC_BOOL_VAL); 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): case GECODE_INT_STATUS(NONE,ONE,NONE): case GECODE_INT_STATUS(NONE,ONE,ZERO): case GECODE_INT_STATUS(NONE,ONE,ONE): x0.cancel(home,this,PC_BOOL_VAL); break; case GECODE_INT_STATUS(ZERO,NONE,NONE): std::swap(x0,x2); x0.subscribe(home,this,PC_BOOL_VAL); 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): x1.cancel(home,this,PC_BOOL_VAL); 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): case GECODE_INT_STATUS(ZERO,ONE,NONE): case GECODE_INT_STATUS(ZERO,ONE,ZERO): case GECODE_INT_STATUS(ZERO,ONE,ONE): break; case GECODE_INT_STATUS(ONE,NONE,NONE): case GECODE_INT_STATUS(ONE,NONE,ZERO): case GECODE_INT_STATUS(ONE,NONE,ONE): x1.cancel(home,this,PC_BOOL_VAL); break; case GECODE_INT_STATUS(ONE,ZERO,NONE): case GECODE_INT_STATUS(ONE,ZERO,ZERO): case GECODE_INT_STATUS(ONE,ZERO,ONE): case GECODE_INT_STATUS(ONE,ONE,NONE): case GECODE_INT_STATUS(ONE,ONE,ZERO): case GECODE_INT_STATUS(ONE,ONE,ONE): break; default: GECODE_NEVER; } return ES_SUBSUMED(this,sizeof(*this)); #undef GECODE_INT_STATUS } template Support::Symbol TerOrTrue::ati(void) { return Reflection::mangle("Gecode::Int::Bool::TerOrTrue"); } template Reflection::ActorSpec TerOrTrue::spec(const Space* home, Reflection::VarMap& m) const { return BoolBinary::spec(home, m, ati()) << x2.spec(home, m); } template void TerOrTrue::post(Space* home, Reflection::VarMap& vars, const Reflection::ActorSpec& spec) { spec.checkArity(3); BV b0(home, vars, spec[0]); BV b1(home, vars, spec[1]); BV b2(home, vars, spec[2]); (void) new (home) TerOrTrue(home,b0,b1,b2); } /* * Boolean disjunction propagator (true) * */ template forceinline QuadOrTrue::QuadOrTrue(Space* home, BV b0, BV b1, BV b2, BV b3) : BoolBinary(home,b0,b1), x2(b2), x3(b3) {} template forceinline size_t QuadOrTrue::dispose(Space* home) { (void) BoolBinary::dispose(home); return sizeof(*this); } template forceinline QuadOrTrue::QuadOrTrue(Space* home, bool share, QuadOrTrue& p) : BoolBinary(home,share,p) { x2.update(home,share,p.x2); x3.update(home,share,p.x3); } template forceinline QuadOrTrue::QuadOrTrue(Space* home, bool share, Propagator& p, BV b0, BV b1, BV b2, BV b3) : BoolBinary(home,share,p,b0,b1) { x2.update(home,share,b2); x3.update(home,share,b3); } template Actor* QuadOrTrue::copy(Space* home, bool share) { assert(x0.none() && x1.none()); if (x2.one() || x3.one()) return new (home) OrTrueSubsumed(home,share,*this,x0,x1); else if (x2.zero() && x3.zero()) return new (home) BinOrTrue(home,share,*this,x0,x1); else if (x2.zero()) return new (home) TerOrTrue(home,share,*this,x0,x1,x3); else if (x3.zero()) return new (home) TerOrTrue(home,share,*this,x0,x1,x2); else return new (home) QuadOrTrue(home,share,*this); } template forceinline ExecStatus QuadOrTrue::post(Space* home, BV b0, BV b1, BV b2, BV b3) { (void) new (home) QuadOrTrue(home,b0,b1,b2,b3); return ES_OK; } template ExecStatus QuadOrTrue::propagate(Space* home, ModEventDelta) { #define GECODE_INT_STATUS(S0,S1,S2,S3) \ ((BV::S0 << (3*BV::BITS)) | (BV::S1 << (2*BV::BITS)) | \ (BV::S2 << (1*BV::BITS)) | (BV::S3 << (0*BV::BITS))) switch ((x0.status() << (3*BV::BITS)) | (x1.status() << (2*BV::BITS)) | (x2.status() << (1*BV::BITS)) | (x3.status() << (0*BV::BITS))) { case GECODE_INT_STATUS(NONE,NONE,NONE,NONE): case GECODE_INT_STATUS(NONE,NONE,NONE,ZERO): case GECODE_INT_STATUS(NONE,NONE,NONE,ONE): case GECODE_INT_STATUS(NONE,NONE,ZERO,NONE): case GECODE_INT_STATUS(NONE,NONE,ZERO,ZERO): case GECODE_INT_STATUS(NONE,NONE,ZERO,ONE): case GECODE_INT_STATUS(NONE,NONE,ONE,NONE): case GECODE_INT_STATUS(NONE,NONE,ONE,ZERO): case GECODE_INT_STATUS(NONE,NONE,ONE,ONE): GECODE_NEVER; case GECODE_INT_STATUS(NONE,ZERO,NONE,NONE): case GECODE_INT_STATUS(NONE,ZERO,NONE,ZERO): std::swap(x1,x2); x1.subscribe(home,this,PC_BOOL_VAL,false); return ES_FIX; case GECODE_INT_STATUS(NONE,ZERO,NONE,ONE): x0.cancel(home,this,PC_BOOL_VAL); break; case GECODE_INT_STATUS(NONE,ZERO,ZERO,NONE): std::swap(x1,x3); x1.subscribe(home,this,PC_BOOL_VAL,false); return ES_FIX; case GECODE_INT_STATUS(NONE,ZERO,ZERO,ZERO): GECODE_ME_CHECK(x0.one_none(home)); break; case GECODE_INT_STATUS(NONE,ZERO,ZERO,ONE): case GECODE_INT_STATUS(NONE,ZERO,ONE,NONE): case GECODE_INT_STATUS(NONE,ZERO,ONE,ZERO): case GECODE_INT_STATUS(NONE,ZERO,ONE,ONE): case GECODE_INT_STATUS(NONE,ONE,NONE,NONE): case GECODE_INT_STATUS(NONE,ONE,NONE,ZERO): case GECODE_INT_STATUS(NONE,ONE,NONE,ONE): case GECODE_INT_STATUS(NONE,ONE,ZERO,NONE): case GECODE_INT_STATUS(NONE,ONE,ZERO,ZERO): case GECODE_INT_STATUS(NONE,ONE,ZERO,ONE): case GECODE_INT_STATUS(NONE,ONE,ONE,NONE): case GECODE_INT_STATUS(NONE,ONE,ONE,ZERO): case GECODE_INT_STATUS(NONE,ONE,ONE,ONE): x0.cancel(home,this,PC_BOOL_VAL); break; case GECODE_INT_STATUS(ZERO,NONE,NONE,NONE): case GECODE_INT_STATUS(ZERO,NONE,NONE,ZERO): std::swap(x0,x2); x0.subscribe(home,this,PC_BOOL_VAL,false); return ES_FIX; case GECODE_INT_STATUS(ZERO,NONE,NONE,ONE): x1.cancel(home,this,PC_BOOL_VAL); break; case GECODE_INT_STATUS(ZERO,NONE,ZERO,NONE): std::swap(x0,x3); x0.subscribe(home,this,PC_BOOL_VAL,false); return ES_FIX; case GECODE_INT_STATUS(ZERO,NONE,ZERO,ZERO): GECODE_ME_CHECK(x1.one_none(home)); break; case GECODE_INT_STATUS(ZERO,NONE,ZERO,ONE): x1.cancel(home,this,PC_BOOL_VAL); break; case GECODE_INT_STATUS(ZERO,NONE,ONE,NONE): case GECODE_INT_STATUS(ZERO,NONE,ONE,ZERO): case GECODE_INT_STATUS(ZERO,NONE,ONE,ONE): x1.cancel(home,this,PC_BOOL_VAL); break; case GECODE_INT_STATUS(ZERO,ZERO,NONE,NONE): std::swap(x0,x2); x0.subscribe(home,this,PC_BOOL_VAL,false); std::swap(x1,x3); x1.subscribe(home,this,PC_BOOL_VAL,false); return ES_FIX; case GECODE_INT_STATUS(ZERO,ZERO,NONE,ZERO): GECODE_ME_CHECK(x2.one_none(home)); break; case GECODE_INT_STATUS(ZERO,ZERO,NONE,ONE): break; case GECODE_INT_STATUS(ZERO,ZERO,ZERO,NONE): GECODE_ME_CHECK(x3.one_none(home)); break; case GECODE_INT_STATUS(ZERO,ZERO,ZERO,ZERO): return ES_FAILED; case GECODE_INT_STATUS(ZERO,ZERO,ZERO,ONE): case GECODE_INT_STATUS(ZERO,ZERO,ONE,NONE): case GECODE_INT_STATUS(ZERO,ZERO,ONE,ZERO): case GECODE_INT_STATUS(ZERO,ZERO,ONE,ONE): case GECODE_INT_STATUS(ZERO,ONE,NONE,NONE): case GECODE_INT_STATUS(ZERO,ONE,NONE,ZERO): case GECODE_INT_STATUS(ZERO,ONE,NONE,ONE): case GECODE_INT_STATUS(ZERO,ONE,ZERO,NONE): case GECODE_INT_STATUS(ZERO,ONE,ZERO,ZERO): case GECODE_INT_STATUS(ZERO,ONE,ZERO,ONE): case GECODE_INT_STATUS(ZERO,ONE,ONE,NONE): case GECODE_INT_STATUS(ZERO,ONE,ONE,ZERO): case GECODE_INT_STATUS(ZERO,ONE,ONE,ONE): break; case GECODE_INT_STATUS(ONE,NONE,NONE,NONE): case GECODE_INT_STATUS(ONE,NONE,NONE,ZERO): case GECODE_INT_STATUS(ONE,NONE,NONE,ONE): case GECODE_INT_STATUS(ONE,NONE,ZERO,NONE): case GECODE_INT_STATUS(ONE,NONE,ZERO,ZERO): case GECODE_INT_STATUS(ONE,NONE,ZERO,ONE): case GECODE_INT_STATUS(ONE,NONE,ONE,NONE): case GECODE_INT_STATUS(ONE,NONE,ONE,ZERO): case GECODE_INT_STATUS(ONE,NONE,ONE,ONE): x1.cancel(home,this,PC_BOOL_VAL); break; case GECODE_INT_STATUS(ONE,ZERO,NONE,NONE): case GECODE_INT_STATUS(ONE,ZERO,NONE,ZERO): case GECODE_INT_STATUS(ONE,ZERO,NONE,ONE): case GECODE_INT_STATUS(ONE,ZERO,ZERO,NONE): case GECODE_INT_STATUS(ONE,ZERO,ZERO,ZERO): case GECODE_INT_STATUS(ONE,ZERO,ZERO,ONE): case GECODE_INT_STATUS(ONE,ZERO,ONE,NONE): case GECODE_INT_STATUS(ONE,ZERO,ONE,ZERO): case GECODE_INT_STATUS(ONE,ZERO,ONE,ONE): case GECODE_INT_STATUS(ONE,ONE,NONE,NONE): case GECODE_INT_STATUS(ONE,ONE,NONE,ZERO): case GECODE_INT_STATUS(ONE,ONE,NONE,ONE): case GECODE_INT_STATUS(ONE,ONE,ZERO,NONE): case GECODE_INT_STATUS(ONE,ONE,ZERO,ZERO): case GECODE_INT_STATUS(ONE,ONE,ZERO,ONE): case GECODE_INT_STATUS(ONE,ONE,ONE,NONE): case GECODE_INT_STATUS(ONE,ONE,ONE,ZERO): case GECODE_INT_STATUS(ONE,ONE,ONE,ONE): break; default: GECODE_NEVER; } return ES_SUBSUMED(this,sizeof(*this)); #undef GECODE_INT_STATUS } template Support::Symbol QuadOrTrue::ati(void) { return Reflection::mangle("Gecode::Int::Bool::QuadOrTrue"); } template Reflection::ActorSpec QuadOrTrue::spec(const Space* home, Reflection::VarMap& m) const { return BoolBinary::spec(home, m, ati()) << x2.spec(home, m) << x3.spec(home, m); } template void QuadOrTrue::post(Space* home, Reflection::VarMap& vars, const Reflection::ActorSpec& spec) { spec.checkArity(4); BV b0(home, vars, spec[0]); BV b1(home, vars, spec[1]); BV b2(home, vars, spec[2]); BV b3(home, vars, spec[3]); (void) new (home) QuadOrTrue(home,b0,b1,b2,b3); } /* * Boolean disjunction propagator * */ template forceinline Or::Or(Space* home, BVA b0, BVB b1, BVC b2) : BoolTernary(home,b0,b1,b2) {} template forceinline Or::Or(Space* home, bool share, Or& p) : BoolTernary(home,share,p) {} template forceinline Or::Or(Space* home, bool share, Propagator& p, BVA b0, BVB b1, BVC b2) : BoolTernary(home,share,p,b0,b1,b2) {} template Actor* Or::copy(Space* home, bool share) { if (x2.one()) { assert(x0.none() && x1.none()); return new (home) BinOrTrue(home,share,*this,x0,x1); } else if (x0.zero()) { assert(x1.none() && x2.none()); return new (home) Eq(home,share,*this,x1,x2); } else if (x1.zero()) { assert(x0.none() && x2.none()); return new (home) Eq(home,share,*this,x0,x2); } else { return new (home) Or(home,share,*this); } } template inline ExecStatus Or::post(Space* home, BVA b0, BVB b1, BVC b2) { if (b2.zero()) { GECODE_ME_CHECK(b0.zero(home)); GECODE_ME_CHECK(b1.zero(home)); } else if (b2.one()) { return BinOrTrue::post(home,b0,b1); } else { switch (bool_test(b0,b1)) { case BT_SAME: return Eq::post(home,b0,b2); case BT_COMP: GECODE_ME_CHECK(b2.one(home)); break; case BT_NONE: if (b0.one() || b1.one()) { GECODE_ME_CHECK(b2.one(home)); } else if (b0.zero()) { return Eq::post(home,b1,b2); } else if (b1.zero()) { return Eq::post(home,b0,b2); } else { (void) new (home) Or(home,b0,b1,b2); } break; default: GECODE_NEVER; } } return ES_OK; } template ExecStatus Or::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): GECODE_ME_CHECK(x0.zero_none(home)); GECODE_ME_CHECK(x1.zero_none(home)); break; case GECODE_INT_STATUS(NONE,NONE,ONE): return ES_FIX; case GECODE_INT_STATUS(NONE,ZERO,NONE): switch (bool_test(x0,x2)) { case BT_SAME: return ES_SUBSUMED(this,home); case BT_COMP: return ES_FAILED; case BT_NONE: return ES_FIX; default: GECODE_NEVER; } GECODE_NEVER; case GECODE_INT_STATUS(NONE,ZERO,ZERO): GECODE_ME_CHECK(x0.zero_none(home)); break; case GECODE_INT_STATUS(NONE,ZERO,ONE): GECODE_ME_CHECK(x0.one_none(home)); break; case GECODE_INT_STATUS(NONE,ONE,NONE): x0.cancel(home,this,PC_BOOL_VAL); GECODE_ME_CHECK(x2.one_none(home)); break; case GECODE_INT_STATUS(NONE,ONE,ZERO): return ES_FAILED; case GECODE_INT_STATUS(NONE,ONE,ONE): x0.cancel(home,this,PC_BOOL_VAL); break; case GECODE_INT_STATUS(ZERO,NONE,NONE): switch (bool_test(x1,x2)) { case BT_SAME: return ES_SUBSUMED(this,home); case BT_COMP: return ES_FAILED; case BT_NONE: return ES_FIX; default: GECODE_NEVER; } GECODE_NEVER; case GECODE_INT_STATUS(ZERO,NONE,ZERO): GECODE_ME_CHECK(x1.zero_none(home)); break; case GECODE_INT_STATUS(ZERO,NONE,ONE): GECODE_ME_CHECK(x1.one_none(home)); break; case GECODE_INT_STATUS(ZERO,ZERO,NONE): GECODE_ME_CHECK(x2.zero_none(home)); break; case GECODE_INT_STATUS(ZERO,ZERO,ZERO): break; case GECODE_INT_STATUS(ZERO,ZERO,ONE): return ES_FAILED; case GECODE_INT_STATUS(ZERO,ONE,NONE): GECODE_ME_CHECK(x2.one_none(home)); break; case GECODE_INT_STATUS(ZERO,ONE,ZERO): return ES_FAILED; case GECODE_INT_STATUS(ZERO,ONE,ONE): break; case GECODE_INT_STATUS(ONE,NONE,NONE): x1.cancel(home,this,PC_BOOL_VAL); GECODE_ME_CHECK(x2.one_none(home)); break; case GECODE_INT_STATUS(ONE,NONE,ZERO): return ES_FAILED; case GECODE_INT_STATUS(ONE,NONE,ONE): x1.cancel(home,this,PC_BOOL_VAL); break; case GECODE_INT_STATUS(ONE,ZERO,NONE): GECODE_ME_CHECK(x2.one_none(home)); break; case GECODE_INT_STATUS(ONE,ZERO,ZERO): return ES_FAILED; case GECODE_INT_STATUS(ONE,ZERO,ONE): break; 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 Support::Symbol Or::ati(void) { return Reflection::mangle("Gecode::Int::Bool::Or"); } template Reflection::ActorSpec Or::spec(const Space* home, Reflection::VarMap& m) const { return BoolTernary::spec(home, m, ati()); } template void Or::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]); BVB b2(home, vars, spec[2]); (void) new (home) Or(home,b0,b1,b2); } /* * N-ary Boolean disjunction propagator (true) * */ template forceinline NaryOrTrue::NaryOrTrue(Space* home, ViewArray& b) : BinaryPropagator(home, b[b.size()-2], b[b.size()-1]), x(b) { assert(x.size() > 2); x.size(x.size()-2); } template PropCost NaryOrTrue::cost(ModEventDelta) const { return cost_lo(x.size(),PC_LINEAR_LO); } template forceinline NaryOrTrue::NaryOrTrue(Space* home, bool share, NaryOrTrue& p) : BinaryPropagator(home,share,p) { x.update(home,share,p.x); } template Actor* NaryOrTrue::copy(Space* home, bool share) { int n = x.size(); if (n > 0) { // Check whether the original has already been purged if (x[0].one()) { x.size(1); // The rest does not matter any longer return new (home) OrTrueSubsumed(home,share,*this,x0,x1); } // Eliminate all zeros and find a one for (int i=n; i--; ) if (x[i].one()) { // Only keep the one x[0]=x[i]; x.size(1); return new (home) OrTrueSubsumed(home,share,*this,x0,x1); } else if (x[i].zero()) { // Eliminate the zero x[i]=x[--n]; } x.size(n); } switch (n) { case 0: return new (home) BinOrTrue(home,share,*this,x0,x1); case 1: return new (home) TerOrTrue(home,share,*this,x0,x1,x[0]); case 2: return new (home) QuadOrTrue(home,share,*this,x0,x1,x[0],x[1]); default: return new (home) NaryOrTrue(home,share,*this); } } template inline ExecStatus NaryOrTrue::post(Space* home, ViewArray& b) { for (int i=b.size(); i--; ) if (b[i].one()) return ES_OK; else if (b[i].zero()) b.move_lst(i); if (b.size() == 0) return ES_FAILED; if (b.size() == 1) { GECODE_ME_CHECK(b[0].one(home)); } else if (b.size() == 2) { return BinOrTrue::post(home,b[0],b[1]); } else if (b.size() == 3) { return TerOrTrue::post(home,b[0],b[1],b[2]); } else if (b.size() == 4) { return QuadOrTrue::post(home,b[0],b[1],b[2],b[3]); } else { (void) new (home) NaryOrTrue(home,b); } return ES_OK; } template forceinline ExecStatus NaryOrTrue::resubscribe(Space* home, BV& x0, BV x1) { if (x0.zero()) { int n = x.size(); for (int i=n; i--; ) if (x[i].one()) { x.size(n); return ES_SUBSUMED(this,home); } else if (x[i].zero()) { x[i] = x[--n]; } else { // New unassigned view found assert(!x[i].zero() && !x[i].one()); // Rewrite if there is just one view left if (i == 0) { BV y = x[0]; x.size(0); GECODE_REWRITE(this,(BinOrTrue::post(home,x1,y))); } // Move to x0 and subscribe x0=x[i]; x[i]=x[--n]; x.size(n); x0.subscribe(home,this,PC_BOOL_VAL,false); return ES_FIX; } // All views have been assigned! x.size(0); GECODE_ME_CHECK(x1.one(home)); return ES_SUBSUMED(this,sizeof(*this)); } return ES_FIX; } template ExecStatus NaryOrTrue::propagate(Space* home, ModEventDelta) { if (x0.one() || x1.one()) return ES_SUBSUMED(this,home); GECODE_ES_CHECK(resubscribe(home,x0,x1)); GECODE_ES_CHECK(resubscribe(home,x1,x0)); return ES_FIX; } template Support::Symbol NaryOrTrue::ati(void) { return Reflection::mangle("Gecode::Int::Bool::NaryOrTrue"); } template Reflection::ActorSpec NaryOrTrue::spec(const Space* home, Reflection::VarMap& m) const { return BinaryPropagator::spec(home, m, ati()) << x.spec(home, m); } template void NaryOrTrue::post(Space* home, Reflection::VarMap& vars, const Reflection::ActorSpec& spec) { spec.checkArity(3); BV b0(home, vars, spec[0]); BV b1(home, vars, spec[1]); ViewArray b(home, vars, spec[2]); ViewArray bb(home, b.size()+2); for (int i=b.size(); i--;) bb[i] = b[i]; bb[b.size()] = b0; bb[b.size()+1] = b1; (void) new (home) NaryOrTrue(home,bb); } /* * N-ary Boolean disjunction propagator * */ template forceinline NaryOr::NaryOr(Space* home, ViewArray& b, BV c) : NaryOnePropagator(home,b,c) {} template forceinline NaryOr::NaryOr(Space* home, bool share, NaryOr& p) : NaryOnePropagator(home,share,p) {} template Actor* NaryOr::copy(Space* home, bool share) { if (x.size() == 1) return new (home) Eq(home,share,*this,x[0],y); if (x.size() == 2) return new (home) Or(home,share,*this,x[0],x[1],y); return new (home) NaryOr(home,share,*this); } template inline ExecStatus NaryOr::post(Space* home, ViewArray& b, BV c) { if (c.one()) return NaryOrTrue::post(home,b); if (c.zero()) { for (int i=b.size(); i--; ) GECODE_ME_CHECK(b[i].zero(home)); return ES_OK; } for (int i=b.size(); i--; ) if (b[i].one()) { GECODE_ME_CHECK(c.one_none(home)); return ES_OK; } else if (b[i].zero()) { b.move_lst(i); } if (b.size() == 0) { GECODE_ME_CHECK(c.zero_none(home)); } else if (b.size() == 1) { return Eq::post(home,b[0],c); } else if (b.size() == 2) { return Or::post(home,b[0],b[1],c); } else { (void) new (home) NaryOr(home,b,c); } return ES_OK; } template ExecStatus NaryOr::propagate(Space* home, ModEventDelta) { if (y.zero()) { for (int i = x.size(); i--; ) GECODE_ME_CHECK(x[i].zero(home)); return ES_SUBSUMED(this,sizeof(*this)); } if (y.one()) GECODE_REWRITE(this,NaryOrTrue::post(home,x)); for (int i = x.size(); i--; ) { if (x[i].one()) { GECODE_ME_CHECK(y.one_none(home)); return ES_SUBSUMED(this,home); } if (x[i].zero()) x.move_lst(i); } if (x.size() == 0) { GECODE_ME_CHECK(y.zero_none(home)); return ES_SUBSUMED(this,sizeof(*this)); } return ES_FIX; } template Support::Symbol NaryOr::ati(void) { return Reflection::mangle("Gecode::Int::Bool::NaryOr"); } template Reflection::ActorSpec NaryOr::spec(const Space* home, Reflection::VarMap& m) const { return NaryOnePropagator::spec(home, m, ati()); } template void NaryOr::post(Space* home, Reflection::VarMap& vars, const Reflection::ActorSpec& spec) { spec.checkArity(2); ViewArray b(home, vars, spec[0]); BV b0(home, vars, spec[1]); (void) new (home) NaryOr(home,b,b0); } }}} // STATISTICS: int-prop