or.hpp
Go to the documentation of this file.
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
* Main authors:
* Christian Schulte <schulte@gecode.org>
*
* Copyright:
* Christian Schulte, 2004
*
* 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<class BV>
class OrTrueSubsumed : public BoolBinary<BV,BV> {
protected:
using BoolBinary<BV,BV>::x0;
using BoolBinary<BV,BV>::x1;
OrTrueSubsumed(Space& home, OrTrueSubsumed& p);
static ExecStatus post(Home home, BV b0, BV b1);
public:
OrTrueSubsumed(Home home, BV b0, BV b1);
OrTrueSubsumed(Space& home, Propagator& p,
BV b0, BV b1);
virtual Actor* copy(Space& home);
virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
};
template<class BV>
forceinline
OrTrueSubsumed<BV>::OrTrueSubsumed
(Home home, BV b0, BV b1)
: BoolBinary<BV,BV>(home,b0,b1) {}
template<class BV>
forceinline ExecStatus
OrTrueSubsumed<BV>::post(Home home, BV b0, BV b1) {
(void) new (home) OrTrueSubsumed(home,b0,b1);
return ES_OK;
}
template<class BV>
forceinline
OrTrueSubsumed<BV>::OrTrueSubsumed
(Space& home, OrTrueSubsumed<BV>& p)
: BoolBinary<BV,BV>(home,p) {}
template<class BV>
forceinline
OrTrueSubsumed<BV>::OrTrueSubsumed(Space& home, Propagator& p,
BV b0, BV b1)
: BoolBinary<BV,BV>(home,p,b0,b1) {}
template<class BV>
Actor*
OrTrueSubsumed<BV>::copy(Space& home) {
return new (home) OrTrueSubsumed<BV>(home,*this);
}
template<class BV>
ExecStatus
OrTrueSubsumed<BV>::propagate(Space& home, const ModEventDelta&) {
return home.ES_SUBSUMED(*this);
}
/*
* Binary Boolean disjunction propagator (true)
*
*/
template<class BVA, class BVB>
forceinline
BinOrTrue<BVA,BVB>::BinOrTrue(Home home, BVA b0, BVB b1)
: BoolBinary<BVA,BVB>(home,b0,b1) {}
template<class BVA, class BVB>
forceinline
BinOrTrue<BVA,BVB>::BinOrTrue(Space& home, BinOrTrue<BVA,BVB>& p)
: BoolBinary<BVA,BVB>(home,p) {}
template<class BVA, class BVB>
forceinline
BinOrTrue<BVA,BVB>::BinOrTrue(Space& home, Propagator& p,
BVA b0, BVB b1)
: BoolBinary<BVA,BVB>(home,p,b0,b1) {}
template<class BVA, class BVB>
Actor*
BinOrTrue<BVA,BVB>::copy(Space& home) {
return new (home) BinOrTrue<BVA,BVB>(home,*this);
}
template<class BVA, class BVB>
inline ExecStatus
BinOrTrue<BVA,BVB>::post(Home 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<BVA,BVB>(home,b0,b1);
}
break;
default: GECODE_NEVER;
}
return ES_OK;
}
template<class BVA, class BVB>
ExecStatus
BinOrTrue<BVA,BVB>::propagate(Space& home, const 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):
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):
case GECODE_INT_STATUS(ONE,NONE):
case GECODE_INT_STATUS(ONE,ZERO):
case GECODE_INT_STATUS(ONE,ONE):
break;
default:
GECODE_NEVER;
}
return home.ES_SUBSUMED(*this);
#undef GECODE_INT_STATUS
}
/*
* Boolean disjunction propagator (true)
*
*/
template<class BV>
forceinline
TerOrTrue<BV>::TerOrTrue(Home home, BV b0, BV b1, BV b2)
: BoolBinary<BV,BV>(home,b0,b1), x2(b2) {}
template<class BV>
forceinline size_t
TerOrTrue<BV>::dispose(Space& home) {
(void) BoolBinary<BV,BV>::dispose(home);
return sizeof(*this);
}
template<class BV>
forceinline
TerOrTrue<BV>::TerOrTrue(Space& home, TerOrTrue<BV>& p)
: BoolBinary<BV,BV>(home,p) {
x2.update(home,p.x2);
}
template<class BV>
forceinline
TerOrTrue<BV>::TerOrTrue(Space& home, Propagator& p,
BV b0, BV b1, BV b2)
: BoolBinary<BV,BV>(home,p,b0,b1) {
x2.update(home,b2);
}
template<class BV>
Actor*
TerOrTrue<BV>::copy(Space& home) {
assert(x0.none() && x1.none());
if (x2.one())
return new (home) OrTrueSubsumed<BV>(home,*this,x0,x1);
else if (x2.zero())
return new (home) BinOrTrue<BV,BV>(home,*this,x0,x1);
else
return new (home) TerOrTrue<BV>(home,*this);
}
template<class BV>
forceinline ExecStatus
TerOrTrue<BV>::post(Home home, BV b0, BV b1, BV b2) {
(void) new (home) TerOrTrue<BV>(home,b0,b1,b2);
return ES_OK;
}
template<class BV>
ExecStatus
TerOrTrue<BV>::propagate(Space& home, const 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):
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):
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):
case GECODE_INT_STATUS(ONE,NONE,NONE):
case GECODE_INT_STATUS(ONE,NONE,ZERO):
case GECODE_INT_STATUS(ONE,NONE,ONE):
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 home.ES_SUBSUMED(*this);
#undef GECODE_INT_STATUS
}
/*
* Boolean disjunction propagator (true)
*
*/
template<class BV>
forceinline
QuadOrTrue<BV>::QuadOrTrue(Home home, BV b0, BV b1, BV b2, BV b3)
: BoolBinary<BV,BV>(home,b0,b1), x2(b2), x3(b3) {}
template<class BV>
forceinline size_t
QuadOrTrue<BV>::dispose(Space& home) {
(void) BoolBinary<BV,BV>::dispose(home);
return sizeof(*this);
}
template<class BV>
forceinline
QuadOrTrue<BV>::QuadOrTrue(Space& home, QuadOrTrue<BV>& p)
: BoolBinary<BV,BV>(home,p) {
x2.update(home,p.x2);
x3.update(home,p.x3);
}
template<class BV>
forceinline
QuadOrTrue<BV>::QuadOrTrue(Space& home, Propagator& p,
BV b0, BV b1, BV b2, BV b3)
: BoolBinary<BV,BV>(home,p,b0,b1) {
x2.update(home,b2);
x3.update(home,b3);
}
template<class BV>
Actor*
QuadOrTrue<BV>::copy(Space& home) {
assert(x0.none() && x1.none());
if (x2.one() || x3.one())
return new (home) OrTrueSubsumed<BV>(home,*this,x0,x1);
else if (x2.zero() && x3.zero())
return new (home) BinOrTrue<BV,BV>(home,*this,x0,x1);
else if (x2.zero())
return new (home) TerOrTrue<BV>(home,*this,x0,x1,x3);
else if (x3.zero())
return new (home) TerOrTrue<BV>(home,*this,x0,x1,x2);
else
return new (home) QuadOrTrue<BV>(home,*this);
}
template<class BV>
forceinline ExecStatus
QuadOrTrue<BV>::post(Home home, BV b0, BV b1, BV b2, BV b3) {
(void) new (home) QuadOrTrue<BV>(home,b0,b1,b2,b3);
return ES_OK;
}
template<class BV>
ExecStatus
QuadOrTrue<BV>::propagate(Space& home, const 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):
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):
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):
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):
case GECODE_INT_STATUS(ZERO,NONE,ONE,NONE):
case GECODE_INT_STATUS(ZERO,NONE,ONE,ZERO):
case GECODE_INT_STATUS(ZERO,NONE,ONE,ONE):
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):
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):
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 home.ES_SUBSUMED(*this);
#undef GECODE_INT_STATUS
}
/*
* Boolean disjunction propagator
*
*/
template<class BVA, class BVB, class BVC>
forceinline
Or<BVA,BVB,BVC>::Or(Home home, BVA b0, BVB b1, BVC b2)
: BoolTernary<BVA,BVB,BVC>(home,b0,b1,b2) {}
template<class BVA, class BVB, class BVC>
forceinline
Or<BVA,BVB,BVC>::Or(Space& home, Or<BVA,BVB,BVC>& p)
: BoolTernary<BVA,BVB,BVC>(home,p) {}
template<class BVA, class BVB, class BVC>
forceinline
Or<BVA,BVB,BVC>::Or(Space& home, Propagator& p,
BVA b0, BVB b1, BVC b2)
: BoolTernary<BVA,BVB,BVC>(home,p,b0,b1,b2) {}
template<class BVA, class BVB, class BVC>
Actor*
Or<BVA,BVB,BVC>::copy(Space& home) {
if (x2.one()) {
assert(x0.none() && x1.none());
return new (home) BinOrTrue<BVA,BVB>(home,*this,x0,x1);
} else if (x0.zero()) {
assert(x1.none() && x2.none());
return new (home) Eq<BVB,BVC>(home,*this,x1,x2);
} else if (x1.zero()) {
assert(x0.none() && x2.none());
return new (home) Eq<BVA,BVC>(home,*this,x0,x2);
} else {
return new (home) Or<BVA,BVB,BVC>(home,*this);
}
}
template<class BVA, class BVB, class BVC>
inline ExecStatus
Or<BVA,BVB,BVC>::post(Home 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<BVA,BVB>::post(home,b0,b1);
} else {
switch (bool_test(b0,b1)) {
case BT_SAME:
return Eq<BVA,BVC>::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<BVB,BVC>::post(home,b1,b2);
} else if (b1.zero()) {
return Eq<BVA,BVC>::post(home,b0,b2);
} else {
(void) new (home) Or<BVA,BVB,BVC>(home,b0,b1,b2);
}
break;
default: GECODE_NEVER;
}
}
return ES_OK;
}
template<class BVA, class BVB, class BVC>
ExecStatus
Or<BVA,BVB,BVC>::propagate(Space& home, const 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 home.ES_SUBSUMED(*this);
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):
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):
break;
case GECODE_INT_STATUS(ZERO,NONE,NONE):
switch (bool_test(x1,x2)) {
case BT_SAME: return home.ES_SUBSUMED(*this);
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):
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):
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 home.ES_SUBSUMED(*this);
#undef GECODE_INT_STATUS
}
/*
* N-ary Boolean disjunction propagator (true)
*
*/
template<class BV>
forceinline
NaryOrTrue<BV>::NaryOrTrue(Home home, ViewArray<BV>& b)
: BinaryPropagator<BV,PC_BOOL_VAL>(home,b[0],b[1]), x(b) {
assert(x.size() > 2);
x.drop_fst(2);
}
template<class BV>
PropCost
NaryOrTrue<BV>::cost(const Space&, const ModEventDelta&) const {
return PropCost::binary(PropCost::LO);
}
template<class BV>
forceinline
NaryOrTrue<BV>::NaryOrTrue(Space& home, NaryOrTrue<BV>& p)
: BinaryPropagator<BV,PC_BOOL_VAL>(home,p) {
x.update(home,p.x);
}
template<class BV>
Actor*
NaryOrTrue<BV>::copy(Space& home) {
int n = x.size();
if (n > 0) {
// 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<BV>(home,*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<BV,BV>(home,*this,x0,x1);
case 1:
return new (home) TerOrTrue<BV>(home,*this,x0,x1,x[0]);
case 2:
return new (home) QuadOrTrue<BV>(home,*this,x0,x1,x[0],x[1]);
default:
return new (home) NaryOrTrue<BV>(home,*this);
}
}
template<class BV>
inline ExecStatus
NaryOrTrue<BV>::post(Home home, ViewArray<BV>& 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<BV,BV>::post(home,b[0],b[1]);
} else if (b.size() == 3) {
return TerOrTrue<BV>::post(home,b[0],b[1],b[2]);
} else if (b.size() == 4) {
return QuadOrTrue<BV>::post(home,b[0],b[1],b[2],b[3]);
} else {
(void) new (home) NaryOrTrue(home,b);
}
return ES_OK;
}
template<class BV>
forceinline size_t
NaryOrTrue<BV>::dispose(Space& home) {
(void) BinaryPropagator<BV,PC_BOOL_VAL>::dispose(home);
return sizeof(*this);
}
template<class BV>
forceinline ExecStatus
NaryOrTrue<BV>::resubscribe(Space& home, BV& x0, BV x1) {
if (x0.zero()) {
int n = x.size();
for (int i=n; i--; )
if (x[i].one()) {
return home.ES_SUBSUMED(*this);
} else if (x[i].zero()) {
x[i] = x[--n];
} else {
// 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!
GECODE_ME_CHECK(x1.one(home));
return home.ES_SUBSUMED(*this);
}
return ES_FIX;
}
template<class BV>
ExecStatus
NaryOrTrue<BV>::propagate(Space& home, const ModEventDelta&) {
if (x0.one())
return home.ES_SUBSUMED(*this);
if (x1.one())
return home.ES_SUBSUMED(*this);
GECODE_ES_CHECK(resubscribe(home,x0,x1));
GECODE_ES_CHECK(resubscribe(home,x1,x0));
return ES_FIX;
}
/*
* N-ary Boolean disjunction propagator
*
*/
template<class VX, class VY>
forceinline
NaryOr<VX,VY>::NaryOr(Home home, ViewArray<VX>& x, VY y)
: MixNaryOnePropagator<VX,PC_BOOL_NONE,VY,PC_BOOL_VAL>(home,x,y),
n_zero(0), c(home) {
x.subscribe(home,*new (home) Advisor(home,*this,c));
}
template<class VX, class VY>
forceinline
NaryOr<VX,VY>::NaryOr(Space& home, NaryOr<VX,VY>& p)
: MixNaryOnePropagator<VX,PC_BOOL_NONE,VY,PC_BOOL_VAL>(home,p),
n_zero(p.n_zero) {
c.update(home,p.c);
}
template<class VX, class VY>
Actor*
NaryOr<VX,VY>::copy(Space& home) {
assert(n_zero < x.size());
if (n_zero > 0) {
int n=x.size();
// Eliminate all zeros
for (int i=n; i--; )
if (x[i].zero())
x[i]=x[--n];
x.size(n);
n_zero = 0;
}
assert(n_zero < x.size());
return new (home) NaryOr<VX,VY>(home,*this);
}
template<class VX, class VY>
inline ExecStatus
NaryOr<VX,VY>::post(Home home, ViewArray<VX>& x, VY y) {
assert(!shared(x));
if (y.one())
return NaryOrTrue<VX>::post(home,x);
if (y.zero()) {
for (int i=0; i<x.size(); i++)
GECODE_ME_CHECK(x[i].zero(home));
return ES_OK;
}
for (int i=x.size(); i--; )
if (x[i].one()) {
GECODE_ME_CHECK(y.one_none(home));
return ES_OK;
} else if (x[i].zero()) {
x.move_lst(i);
}
if (x.size() == 0) {
GECODE_ME_CHECK(y.zero_none(home));
} else if (x.size() == 1) {
return Eq<VX,VY>::post(home,x[0],y);
} else if (x.size() == 2) {
return Or<VX,VX,VY>::post(home,x[0],x[1],y);
} else {
(void) new (home) NaryOr(home,x,y);
}
return ES_OK;
}
template<class VX, class VY>
PropCost
NaryOr<VX,VY>::cost(const Space&, const ModEventDelta&) const {
return PropCost::unary(PropCost::LO);
}
template<class VX, class VY>
ExecStatus
NaryOr<VX,VY>::advise(Space&, Advisor&, const Delta& d) {
// Decides whether the propagator must be run
if (VX::zero(d) && (++n_zero < x.size()))
return ES_FIX;
else
return ES_NOFIX;
}
template<class VX, class VY>
void
NaryOr<VX,VY>::reschedule(Space& home) {
y.reschedule(home,*this,PC_BOOL_VAL);
if (n_zero == x.size())
VX::schedule(home,*this,ME_BOOL_VAL);
for (int i=0; i<x.size(); i++)
if (x[i].one()) {
VX::schedule(home,*this,ME_BOOL_VAL);
break;
}
}
template<class VX, class VY>
forceinline size_t
NaryOr<VX,VY>::dispose(Space& home) {
Advisors<Advisor> as(c);
x.cancel(home,as.advisor());
c.dispose(home);
(void) MixNaryOnePropagator<VX,PC_BOOL_NONE,VY,PC_BOOL_VAL>
::dispose(home);
return sizeof(*this);
}
template<class VX, class VY>
ExecStatus
NaryOr<VX,VY>::propagate(Space& home, const ModEventDelta&) {
if (y.one())
GECODE_REWRITE(*this,NaryOrTrue<VX>::post(home(*this),x));
if (y.zero()) {
// Note that this might trigger the advisor of this propagator!
for (int i=0; i<x.size(); i++)
GECODE_ME_CHECK(x[i].zero(home));
} else if (n_zero == x.size()) {
// All views are zero
GECODE_ME_CHECK(y.zero_none(home));
} else {
// There is at least one view which is one
GECODE_ME_CHECK(y.one_none(home));
}
return home.ES_SUBSUMED(*this);
}
}}}
// STATISTICS: int-prop
Gecode::ActorLink::Actor
friend class Actor
Definition core.hpp:590
Gecode::Actor
Base-class for both propagators and branchers.
Definition core.hpp:628
Gecode::Advisors
Class to iterate over advisors of a council.
Definition core.hpp:1266
Gecode::Advisors::advisor
A & advisor(void) const
Return advisor.
Definition core.hpp:4010
Gecode::BinaryPropagator< BV, PC_BOOL_VAL >::x0
BV x0
Definition pattern.hpp:87
Gecode::BinaryPropagator< BV, PC_BOOL_VAL >::BinaryPropagator
BinaryPropagator(Space &home, BinaryPropagator &p)
Gecode::BinaryPropagator::dispose
virtual size_t dispose(Space &home)
Delete propagator and return its size.
Definition pattern.hpp:396
Gecode::BinaryPropagator< BV, PC_BOOL_VAL >::x1
BV x1
Definition pattern.hpp:87
Gecode::Delta
Generic domain change information to be supplied to advisors.
Definition core.hpp:204
Gecode::FloatVal::size
FloatNum size(void) const
Return size of float value (distance between maximum and minimum).
Definition val.hpp:78
Gecode::Home
Home class for posting propagators
Definition core.hpp:856
Gecode::Int::Bool::BinOrTrue
Binary Boolean disjunction propagator (true).
Definition bool.hh:237
Gecode::Int::Bool::BinOrTrue::BinOrTrue
BinOrTrue(Home home, BVA b0, BVB b1)
Constructor for posting.
Definition or.hpp:103
Gecode::Int::Bool::BinOrTrue::propagate
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition or.hpp:148
Gecode::Int::Bool::BinOrTrue::post
static ExecStatus post(Home home, BVA b0, BVB b1)
Post propagator .
Definition or.hpp:125
Gecode::Int::Bool::BinOrTrue::copy
virtual Actor * copy(Space &home)
Copy propagator during cloning.
Definition or.hpp:119
Gecode::Int::Bool::BoolBinary::dispose
virtual size_t dispose(Space &home)
Delete propagator and return its size.
Definition base.hpp:80
Gecode::Int::Bool::BoolBinary< BV, BV >::x1
BV x1
Definition bool.hh:58
Gecode::Int::Bool::BoolBinary< BV, BV >::BoolBinary
BoolBinary(Home home, BV b0, BV b1)
Definition base.hpp:42
Gecode::Int::Bool::BoolBinary< BV, BV >::x0
BV x0
Definition bool.hh:57
Gecode::Int::Bool::BoolTernary::BoolTernary
BoolTernary(Home home, BVA b0, BVB b1, BVC b2)
Definition base.hpp:94
Gecode::Int::Bool::BoolTernary::x1
BVB x1
Boolean view.
Definition bool.hh:80
Gecode::Int::Bool::BoolTernary::x0
BVA x0
Boolean view.
Definition bool.hh:79
Gecode::Int::Bool::BoolTernary::x2
BVC x2
Boolean view Constructor for posting.
Definition bool.hh:81
Gecode::Int::Bool::Eq
Boolean equality propagator.
Definition bool.hh:105
Gecode::Int::Bool::Eq::post
static ExecStatus post(Home home, BVA x0, BVB x1)
Post propagator .
Definition eq.hpp:60
Gecode::Int::Bool::NaryOrTrue::propagate
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition or.hpp:718
Gecode::Int::Bool::NaryOrTrue::resubscribe
ExecStatus resubscribe(Space &home, BV &x0, BV x1)
Update subscription.
Definition or.hpp:694
Gecode::Int::Bool::NaryOrTrue::post
static ExecStatus post(Home home, ViewArray< BV > &b)
Post propagator .
Definition or.hpp:663
Gecode::Int::Bool::NaryOrTrue::x
ViewArray< BV > x
Views not yet subscribed to.
Definition bool.hh:398
Gecode::Int::Bool::NaryOrTrue::copy
virtual Actor * copy(Space &home)
Copy propagator during cloning.
Definition or.hpp:634
Gecode::Int::Bool::NaryOrTrue::cost
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function (defined as low unary).
Definition or.hpp:621
Gecode::Int::Bool::NaryOrTrue::NaryOrTrue
NaryOrTrue(Home home, ViewArray< BV > &x)
Constructor for posting.
Definition or.hpp:613
Gecode::Int::Bool::NaryOrTrue::dispose
virtual size_t dispose(Space &home)
Delete propagator and return its size.
Definition or.hpp:687
Gecode::Int::Bool::NaryOr::reschedule
virtual void reschedule(Space &home)
Schedule function.
Definition or.hpp:815
Gecode::Int::Bool::NaryOr::advise
virtual ExecStatus advise(Space &home, Advisor &a, const Delta &d)
Give advice to propagator.
Definition or.hpp:805
Gecode::Int::Bool::NaryOr::NaryOr
NaryOr(Home home, ViewArray< VX > &x, VY y)
Constructor for posting.
Definition or.hpp:736
Gecode::Int::Bool::NaryOr::copy
virtual Actor * copy(Space &home)
Copy propagator during cloning.
Definition or.hpp:752
Gecode::Int::Bool::NaryOr::propagate
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition or.hpp:839
Gecode::Int::Bool::NaryOr::cost
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function (defined as low unary).
Definition or.hpp:799
Gecode::Int::Bool::NaryOr::n_zero
int n_zero
The number of views assigned to zero in x.
Definition bool.hh:361
Gecode::Int::Bool::NaryOr::c
Council< Advisor > c
The advisor council.
Definition bool.hh:363
Gecode::Int::Bool::NaryOr::post
static ExecStatus post(Home home, ViewArray< VX > &x, VY y)
Post propagator .
Definition or.hpp:769
Gecode::Int::Bool::NaryOr::dispose
virtual size_t dispose(Space &home)
Delete propagator and return its size.
Definition or.hpp:828
Gecode::Int::Bool::OrTrueSubsumed
Binary Boolean disjunction propagator (subsumed).
Definition or.hpp:38
Gecode::Int::Bool::OrTrueSubsumed::propagate
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition or.hpp:91
Gecode::Int::Bool::OrTrueSubsumed::post
static ExecStatus post(Home home, BV b0, BV b1)
Post propagator.
Definition or.hpp:66
Gecode::Int::Bool::OrTrueSubsumed::copy
virtual Actor * copy(Space &home)
Copy propagator during cloning.
Definition or.hpp:85
Gecode::Int::Bool::OrTrueSubsumed::OrTrueSubsumed
OrTrueSubsumed(Space &home, OrTrueSubsumed &p)
Constructor for cloning p.
Definition or.hpp:74
Gecode::Int::Bool::Or::propagate
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition or.hpp:526
Gecode::Int::Bool::Or::copy
virtual Actor * copy(Space &home)
Copy propagator during cloning.
Definition or.hpp:477
Gecode::Int::Bool::Or::post
static ExecStatus post(Home home, BVA b0, BVB b1, BVC b2)
Post propagator .
Definition or.hpp:494
Gecode::Int::Bool::Or::Or
Or(Home home, BVA b0, BVB b1, BVC b2)
Constructor for posting.
Definition or.hpp:461
Gecode::Int::Bool::QuadOrTrue
Quarternary Boolean disjunction propagator (true).
Definition bool.hh:295
Gecode::Int::Bool::QuadOrTrue::QuadOrTrue
QuadOrTrue(Home home, BV b0, BV b1, BV b2, BV b3)
Constructor for posting.
Definition or.hpp:285
Gecode::Int::Bool::QuadOrTrue::x2
BV x2
Boolean view without subscription.
Definition bool.hh:300
Gecode::Int::Bool::QuadOrTrue::x3
BV x3
Boolean view without subscription.
Definition bool.hh:302
Gecode::Int::Bool::QuadOrTrue::post
static ExecStatus post(Home home, BV b0, BV b1, BV b2, BV b3)
Post propagator .
Definition or.hpp:330
Gecode::Int::Bool::QuadOrTrue::dispose
virtual size_t dispose(Space &home)
Delete propagator and return its size.
Definition or.hpp:290
Gecode::Int::Bool::QuadOrTrue::propagate
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition or.hpp:337
Gecode::Int::Bool::QuadOrTrue::copy
virtual Actor * copy(Space &home)
Copy propagator during cloning.
Definition or.hpp:314
Gecode::Int::Bool::TerOrTrue
Ternary Boolean disjunction propagator (true).
Definition bool.hh:264
Gecode::Int::Bool::TerOrTrue::TerOrTrue
TerOrTrue(Home home, BV b0, BV b1, BV b2)
Constructor for posting.
Definition or.hpp:181
Gecode::Int::Bool::TerOrTrue::copy
virtual Actor * copy(Space &home)
Copy propagator during cloning.
Definition or.hpp:208
Gecode::Int::Bool::TerOrTrue::x2
BV x2
Boolean view without subscription.
Definition bool.hh:269
Gecode::Int::Bool::TerOrTrue::dispose
virtual size_t dispose(Space &home)
Delete propagator and return its size.
Definition or.hpp:186
Gecode::Int::Bool::TerOrTrue::propagate
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition or.hpp:227
Gecode::Int::Bool::TerOrTrue::post
static ExecStatus post(Home home, BV b0, BV b1, BV b2)
Post propagator .
Definition or.hpp:220
Gecode::MixNaryOnePropagator< VX, PC_BOOL_NONE, VY, PC_BOOL_VAL >::MixNaryOnePropagator
MixNaryOnePropagator(Space &home, MixNaryOnePropagator &p)
Definition pattern.hpp:733
Gecode::MixNaryOnePropagator< VX, PC_BOOL_NONE, VY, PC_BOOL_VAL >::x
ViewArray< VX > x
Definition pattern.hpp:275
Gecode::MixNaryOnePropagator< VX, PC_BOOL_NONE, VY, PC_BOOL_VAL >::y
VY y
Definition pattern.hpp:277
Gecode::PropCost
Propagation cost.
Definition core.hpp:486
Gecode::PropCost::unary
static PropCost unary(PropCost::Mod m)
Single variable for modifier pcm.
Definition core.hpp:4813
Gecode::PropCost::binary
static PropCost binary(PropCost::Mod m)
Two variables for modifier pcm.
Definition core.hpp:4809
Gecode::PropCost::LO
@ LO
Cheap.
Definition core.hpp:513
Gecode::Propagator::Space
friend class Space
Definition core.hpp:1066
Gecode::Propagator::Advisor
friend class Advisor
Definition core.hpp:1068
Gecode::Propagator::med
ModEventDelta med
A set of modification events (used during propagation).
Definition core.hpp:1075
Gecode::Propagator::Propagator
Propagator(Home home)
Constructor for posting.
Definition core.hpp:3498
Gecode::ViewArray
View arrays.
Definition array.hpp:253
Gecode::Space::ES_SUBSUMED
ExecStatus ES_SUBSUMED(Propagator &p)
Definition core.hpp:3563
Gecode::ModEventDelta
int ModEventDelta
Modification event deltas.
Definition core.hpp:89
GECODE_ME_CHECK
#define GECODE_ME_CHECK(me)
Check whether modification event me is failed, and forward failure.
Definition macros.hpp:52
GECODE_REWRITE
#define GECODE_REWRITE(prop, post)
Rewrite propagator by executing post function.
Definition macros.hpp:116
GECODE_ES_CHECK
#define GECODE_ES_CHECK(es)
Check whether execution status es is failed or subsumed, and forward failure or subsumption.
Definition macros.hpp:91
GECODE_INT_STATUS
#define GECODE_INT_STATUS(S0, S1)
Gecode::Int::Bool
Boolean propagators.
Gecode::Int::Bool::resubscribe
ExecStatus resubscribe(Space &home, Propagator &p, VX &x0, ViewArray< VX > &x, VY &x1, ViewArray< VY > &y)
Definition clause.hpp:138
Gecode::Int
Finite domain integers.
Gecode::Int::PC_BOOL_NONE
const Gecode::PropCond PC_BOOL_NONE
Propagation condition to be ignored (convenience).
Definition var-type.hpp:118
Gecode::Int::ME_BOOL_VAL
const Gecode::ModEvent ME_BOOL_VAL
Domain operation has resulted in a value (assigned variable).
Definition var-type.hpp:116
Gecode::Int::PC_BOOL_VAL
const Gecode::PropCond PC_BOOL_VAL
Propagate when a view becomes assigned (single value).
Definition var-type.hpp:126
Gecode::Int::bool_test
BoolTest bool_test(const BoolView &b0, const BoolView &b1)
Definition bool-test.hpp:41
Gecode::Int::BT_NONE
@ BT_NONE
No sharing.
Definition view.hpp:1785
Gecode::Int::BT_COMP
@ BT_COMP
Same variable but complement.
Definition view.hpp:1787
Gecode::Int::BT_SAME
@ BT_SAME
Same variable.
Definition view.hpp:1786
Gecode
Gecode toplevel namespace
Gecode::ExecStatus
ExecStatus
Definition core.hpp:472
Gecode::ES_OK
@ ES_OK
Execution is okay.
Definition core.hpp:476
Gecode::ES_FIX
@ ES_FIX
Propagation has computed fixpoint.
Definition core.hpp:477
Gecode::ES_FAILED
@ ES_FAILED
Execution has resulted in failure.
Definition core.hpp:474
Gecode::ES_NOFIX
@ ES_NOFIX
Propagation has not computed fixpoint.
Definition core.hpp:475
Gecode::shared
bool shared(ViewArray< ViewX > x, ViewArray< ViewY > y)
Definition array.hpp:1466
forceinline
#define forceinline
Definition config.hpp:187
GECODE_NEVER
#define GECODE_NEVER
Assert that this command is never executed.
Definition macros.hpp:56