eqv.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 BVA, class BVB, class BVC>
forceinline
Eqv<BVA,BVB,BVC>::Eqv(Home home, BVA b0, BVB b1, BVC b2)
: BoolTernary<BVA,BVB,BVC>(home,b0,b1,b2) {}
template<class BVA, class BVB, class BVC>
forceinline
Eqv<BVA,BVB,BVC>::Eqv(Space& home, Eqv<BVA,BVB,BVC>& p)
: BoolTernary<BVA,BVB,BVC>(home,p) {}
template<class BVA, class BVB, class BVC>
inline ExecStatus
Eqv<BVA,BVB,BVC>::post(Home 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<BVA,BVB>::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<class BVA, class BVB, class BVC>
Actor*
Eqv<BVA,BVB,BVC>::copy(Space& home) {
return new (home) Eqv<BVA,BVB,BVC>(home,*this);
}
template<class BVA, class BVB, class BVC>
ExecStatus
Eqv<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):
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 home.ES_SUBSUMED(*this);
#undef GECODE_INT_STATUS
}
/*
* N-ary Boolean equivalence propagator
*
*/
forceinline
NaryEqv::NaryEqv(Home home, ViewArray<BoolView>& x0, int pm20)
: BinaryPropagator<BoolView,PC_BOOL_VAL>(home,x0[0],x0[1]),
x(x0), pm2(pm20) {
assert(x.size() >= 2);
x.drop_fst(2);
}
forceinline
NaryEqv::NaryEqv(Space& home, NaryEqv& p)
: BinaryPropagator<BoolView,PC_BOOL_VAL>(home,p), pm2(p.pm2) {
x.update(home,p.x);
}
forceinline size_t
NaryEqv::dispose(Space& home) {
(void) BinaryPropagator<BoolView,PC_BOOL_VAL>::dispose(home);
return sizeof(*this);
}
forceinline void
NaryEqv::resubscribe(Space& home, BoolView& x0) {
if (x0.assigned()) {
pm2 ^= x0.val();
int n = x.size();
for (int i=n; i--; )
if (x[i].assigned()) {
pm2 ^= x[i].val();
x[i] = x[--n];
} else {
// Move to x0 and subscribe
x0=x[i]; x[i]=x[--n];
x0.subscribe(home,*this,PC_BOOL_VAL,false);
break;
}
x.size(n);
}
}
}}}
// STATISTICS: int-prop
Gecode::Actor
Base-class for both propagators and branchers.
Definition core.hpp:628
Gecode::BinaryPropagator< BoolView, PC_BOOL_VAL >::x0
BoolView x0
Definition pattern.hpp:87
Gecode::BinaryPropagator< BoolView, 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::Home
Home class for posting propagators
Definition core.hpp:856
Gecode::Int::BoolView
Boolean view for Boolean variables.
Definition view.hpp:1380
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::post
static ExecStatus post(Home home, BVA x0, BVB x1)
Post propagator .
Definition eq.hpp:60
Gecode::Int::Bool::Eqv::propagate
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition eqv.hpp:87
Gecode::Int::Bool::Eqv::post
static ExecStatus post(Home home, BVA b0, BVB b1, BVC b2)
Post propagator (equivalence).
Definition eqv.hpp:48
Gecode::Int::Bool::Eqv::Eqv
Eqv(Space &home, Eqv &p)
Constructor for cloning p.
Definition eqv.hpp:43
Gecode::Int::Bool::Eqv::copy
virtual Actor * copy(Space &home)
Copy propagator during cloning.
Definition eqv.hpp:81
Gecode::Int::Bool::NaryEqv::resubscribe
void resubscribe(Space &home, BoolView &x0)
Update subscription.
Definition eqv.hpp:178
Gecode::Int::Bool::NaryEqv::NaryEqv
NaryEqv(Home home, ViewArray< BoolView > &x, int pm2)
Constructor for posting.
Definition eqv.hpp:158
Gecode::Int::Bool::NaryEqv::dispose
virtual size_t dispose(Space &home)
Delete propagator and return its size.
Definition eqv.hpp:172
Gecode::Int::Bool::NaryEqv::pm2
int pm2
Parity information mod 2.
Definition bool.hh:460
Gecode::Int::Bool::NaryEqv::x
ViewArray< BoolView > x
Views not yet subscribed to.
Definition bool.hh:458
Gecode::Propagator::Space
friend class Space
Definition core.hpp:1066
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_INT_STATUS
#define GECODE_INT_STATUS(S0, S1)
Gecode::Int::Bool
Boolean propagators.
Gecode::Int
Finite domain integers.
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
forceinline
#define forceinline
Definition config.hpp:187
GECODE_NEVER
#define GECODE_NEVER
Assert that this command is never executed.
Definition macros.hpp:56