int-ter.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, 2003
*
* 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 Linear {
/*
* Ternary linear propagators
*
*/
template<class Val, class A, class B, class C, PropCond pc>
forceinline
LinTer<Val,A,B,C,pc>::LinTer(Home home, A y0, B y1, C y2, Val c0)
: Propagator(home), x0(y0), x1(y1), x2(y2), c(c0) {
x0.subscribe(home,*this,pc);
x1.subscribe(home,*this,pc);
x2.subscribe(home,*this,pc);
}
template<class Val, class A, class B, class C, PropCond pc>
forceinline
LinTer<Val,A,B,C,pc>::LinTer(Space& home, LinTer<Val,A,B,C,pc>& p)
: Propagator(home,p), c(p.c) {
x0.update(home,p.x0);
x1.update(home,p.x1);
x2.update(home,p.x2);
}
template<class Val, class A, class B, class C, PropCond pc>
forceinline
LinTer<Val,A,B,C,pc>::LinTer(Space& home, Propagator& p,
A y0, B y1, C y2, Val c0)
: Propagator(home,p), c(c0) {
x0.update(home,y0);
x1.update(home,y1);
x2.update(home,y2);
}
template<class Val, class A, class B, class C, PropCond pc>
PropCost
LinTer<Val,A,B,C,pc>::cost(const Space&, const ModEventDelta&) const {
return PropCost::ternary(PropCost::LO);
}
template<class Val, class A, class B, class C, PropCond pc>
void
LinTer<Val,A,B,C,pc>::reschedule(Space& home) {
x0.reschedule(home,*this,pc);
x1.reschedule(home,*this,pc);
x2.reschedule(home,*this,pc);
}
template<class Val, class A, class B, class C, PropCond pc>
forceinline size_t
LinTer<Val,A,B,C,pc>::dispose(Space& home) {
x0.cancel(home,*this,pc);
x1.cancel(home,*this,pc);
x2.cancel(home,*this,pc);
(void) Propagator::dispose(home);
return sizeof(*this);
}
/*
* Equality propagator
*
*/
template<class Val, class A, class B, class C>
forceinline
EqTer<Val,A,B,C>::EqTer(Home home, A x0, B x1, C x2, Val c)
: LinTer<Val,A,B,C,PC_INT_BND>(home,x0,x1,x2,c) {}
template<class Val, class A, class B, class C>
ExecStatus
EqTer<Val,A,B,C>::post(Home home, A x0, B x1, C x2, Val c) {
(void) new (home) EqTer<Val,A,B,C>(home,x0,x1,x2,c);
return ES_OK;
}
template<class Val, class A, class B, class C>
forceinline
EqTer<Val,A,B,C>::EqTer(Space& home, EqTer<Val,A,B,C>& p)
: LinTer<Val,A,B,C,PC_INT_BND>(home,p) {}
template<class Val, class A, class B, class C>
forceinline
EqTer<Val,A,B,C>::EqTer(Space& home, Propagator& p,
A x0, B x1, C x2, Val c)
: LinTer<Val,A,B,C,PC_INT_BND>(home,p,x0,x1,x2,c) {}
template<class Val, class A, class B, class C>
Actor*
EqTer<Val,A,B,C>::copy(Space& home) {
return new (home) EqTer<Val,A,B,C>(home,*this);
}
enum TerMod {
TM_X0_MIN = 1<<0,
TM_X0_MAX = 1<<1,
TM_X1_MIN = 1<<2,
TM_X1_MAX = 1<<3,
TM_X2_MIN = 1<<4,
TM_X2_MAX = 1<<5,
TM_ALL = TM_X0_MIN|TM_X0_MAX|TM_X1_MIN|TM_X1_MAX|TM_X2_MIN|TM_X2_MAX
};
#define GECODE_INT_PV(CASE,TELL,UPDATE) \
if (bm & (CASE)) { \
bm -= (CASE); ModEvent me = (TELL); \
if (me_failed(me)) return ES_FAILED; \
if (me_modified(me)) bm |= (UPDATE); \
}
template<class Val, class A, class B, class C>
ExecStatus
EqTer<Val,A,B,C>::propagate(Space& home, const ModEventDelta&) {
int bm = TM_ALL;
do {
GECODE_INT_PV(TM_X0_MIN, x0.gq(home,c-x1.max()-x2.max()),
TM_X1_MAX | TM_X2_MAX);
GECODE_INT_PV(TM_X1_MIN, x1.gq(home,c-x0.max()-x2.max()),
TM_X0_MAX | TM_X2_MAX);
GECODE_INT_PV(TM_X2_MIN, x2.gq(home,c-x0.max()-x1.max()),
TM_X0_MAX | TM_X1_MAX);
GECODE_INT_PV(TM_X0_MAX, x0.lq(home,c-x1.min()-x2.min()),
TM_X1_MIN | TM_X2_MIN);
GECODE_INT_PV(TM_X1_MAX, x1.lq(home,c-x0.min()-x2.min()),
TM_X0_MIN | TM_X2_MIN);
GECODE_INT_PV(TM_X2_MAX, x2.lq(home,c-x0.min()-x1.min()),
TM_X0_MIN | TM_X1_MIN);
} while (bm);
return (x0.assigned() && x1.assigned()) ?
home.ES_SUBSUMED(*this) : ES_FIX;
}
#undef GECODE_INT_PV
/*
* Disequality propagator
*
*/
template<class Val, class A, class B, class C>
forceinline
NqTer<Val,A,B,C>::NqTer(Home home, A x0, B x1, C x2, Val c)
: LinTer<Val,A,B,C,PC_INT_VAL>(home,x0,x1,x2,c) {}
template<class Val, class A, class B, class C>
ExecStatus
NqTer<Val,A,B,C>::post(Home home, A x0, B x1, C x2, Val c) {
(void) new (home) NqTer<Val,A,B,C>(home,x0,x1,x2,c);
return ES_OK;
}
template<class Val, class A, class B, class C>
forceinline
NqTer<Val,A,B,C>::NqTer(Space& home, NqTer<Val,A,B,C>& p)
: LinTer<Val,A,B,C,PC_INT_VAL>(home,p) {}
template<class Val, class A, class B, class C>
Actor*
NqTer<Val,A,B,C>::copy(Space& home) {
return new (home) NqTer<Val,A,B,C>(home,*this);
}
template<class Val, class A, class B, class C>
forceinline
NqTer<Val,A,B,C>::NqTer(Space& home, Propagator& p,
A x0, B x1, C x2, Val c)
: LinTer<Val,A,B,C,PC_INT_VAL>(home,p,x0,x1,x2,c) {}
template<class Val, class A, class B, class C>
ExecStatus
NqTer<Val,A,B,C>::propagate(Space& home, const ModEventDelta&) {
if (x0.assigned() && x1.assigned()) {
GECODE_ME_CHECK(x2.nq(home,c-x0.val()-x1.val()));
return home.ES_SUBSUMED(*this);
}
if (x0.assigned() && x2.assigned()) {
GECODE_ME_CHECK(x1.nq(home,c-x0.val()-x2.val()));
return home.ES_SUBSUMED(*this);
}
if (x1.assigned() && x2.assigned()) {
GECODE_ME_CHECK(x0.nq(home,c-x1.val()-x2.val()));
return home.ES_SUBSUMED(*this);
}
return ES_FIX;
}
/*
* Inequality propagator
*
*/
template<class Val, class A, class B, class C>
forceinline
LqTer<Val,A,B,C>::LqTer(Home home, A x0, B x1, C x2, Val c)
: LinTer<Val,A,B,C,PC_INT_BND>(home,x0,x1,x2,c) {}
template<class Val, class A, class B, class C>
ExecStatus
LqTer<Val,A,B,C>::post(Home home, A x0, B x1, C x2, Val c) {
(void) new (home) LqTer<Val,A,B,C>(home,x0,x1,x2,c);
return ES_OK;
}
template<class Val, class A, class B, class C>
forceinline
LqTer<Val,A,B,C>::LqTer(Space& home, LqTer<Val,A,B,C>& p)
: LinTer<Val,A,B,C,PC_INT_BND>(home,p) {}
template<class Val, class A, class B, class C>
Actor*
LqTer<Val,A,B,C>::copy(Space& home) {
return new (home) LqTer<Val,A,B,C>(home,*this);
}
template<class Val, class A, class B, class C>
forceinline
LqTer<Val,A,B,C>::LqTer(Space& home, Propagator& p,
A x0, B x1, C x2, Val c)
: LinTer<Val,A,B,C,PC_INT_BND>(home,p,x0,x1,x2,c) {}
template<class Val, class A, class B, class C>
ExecStatus
LqTer<Val,A,B,C>::propagate(Space& home, const ModEventDelta&) {
GECODE_ME_CHECK(x0.lq(home,c-x1.min()-x2.min()));
GECODE_ME_CHECK(x1.lq(home,c-x0.min()-x2.min()));
GECODE_ME_CHECK(x2.lq(home,c-x0.min()-x1.min()));
return (x0.max()+x1.max()+x2.max() <= c) ?
home.ES_SUBSUMED(*this) : ES_FIX;
}
}}}
// STATISTICS: int-prop
Gecode::Actor
Base-class for both propagators and branchers.
Definition core.hpp:628
Gecode::Actor::dispose
virtual size_t dispose(Space &home)
Delete actor and return its size.
Definition core.hpp:3252
Gecode::Home
Home class for posting propagators
Definition core.hpp:856
Gecode::Int::Linear::EqTer
Propagator for bounds consistent ternary linear equality
Definition linear.hh:384
Gecode::Int::Linear::EqTer::EqTer
EqTer(Space &home, EqTer &p)
Constructor for cloning p.
Gecode::Int::Linear::EqTer::post
static ExecStatus post(Home home, A x0, B x1, C x2, Val c)
Post propagator for .
Definition int-ter.hpp:104
Gecode::Int::Linear::EqTer::propagate
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition int-ter.hpp:147
Gecode::Int::Linear::EqTer::copy
virtual Actor * copy(Space &home)
Create copy during cloning.
Definition int-ter.hpp:123
Gecode::Int::Linear::LinTer
Base-class for ternary linear propagators.
Definition linear.hh:346
Gecode::Int::Linear::LinTer::x2
C x2
View of type C.
Definition linear.hh:353
Gecode::Int::Linear::LinTer::cost
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function (defined as low ternary).
Definition int-ter.hpp:70
Gecode::Int::Linear::LinTer::LinTer
LinTer(Space &home, LinTer &p)
Constructor for cloning p.
Gecode::Int::Linear::LinTer::x0
A x0
View of type A.
Definition linear.hh:349
Gecode::Int::Linear::LinTer::c
Val c
Value of type Val.
Definition linear.hh:355
Gecode::Int::Linear::LinTer::dispose
virtual size_t dispose(Space &home)
Delete propagator and return its size.
Definition int-ter.hpp:84
Gecode::Int::Linear::LinTer::reschedule
virtual void reschedule(Space &home)
Schedule function.
Definition int-ter.hpp:76
Gecode::Int::Linear::LinTer::x1
B x1
View of type B.
Definition linear.hh:351
Gecode::Int::Linear::LqTer
Propagator for bounds consistent ternary linear less or equal
Definition linear.hh:454
Gecode::Int::Linear::LqTer::copy
virtual Actor * copy(Space &home)
Create copy during cloning.
Definition int-ter.hpp:252
Gecode::Int::Linear::LqTer::post
static ExecStatus post(Home home, A x0, B x1, C x2, Val c)
Post propagator for .
Definition int-ter.hpp:239
Gecode::Int::Linear::LqTer::LqTer
LqTer(Space &home, LqTer &p)
Constructor for cloning p.
Gecode::Int::Linear::LqTer::propagate
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition int-ter.hpp:265
Gecode::Int::Linear::NqTer
Propagator for bounds consistent ternary linear disquality
Definition linear.hh:419
Gecode::Int::Linear::NqTer::copy
virtual Actor * copy(Space &home)
Create copy during cloning.
Definition int-ter.hpp:196
Gecode::Int::Linear::NqTer::post
static ExecStatus post(Home home, A x0, B x1, C x2, Val c)
Post propagator for .
Definition int-ter.hpp:183
Gecode::Int::Linear::NqTer::propagate
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition int-ter.hpp:209
Gecode::Int::Linear::NqTer::NqTer
NqTer(Space &home, NqTer &p)
Constructor for cloning p.
Gecode::PropCost
Propagation cost.
Definition core.hpp:486
Gecode::PropCost::ternary
static PropCost ternary(PropCost::Mod m)
Three variables for modifier pcm.
Definition core.hpp:4805
Gecode::PropCost::LO
@ LO
Cheap.
Definition core.hpp:513
Gecode::Propagator
Base-class for propagators.
Definition core.hpp:1064
Gecode::Propagator::Space
friend class Space
Definition core.hpp:1066
Gecode::Propagator::Propagator
Propagator(Home home)
Constructor for posting.
Definition core.hpp:3498
Gecode::Space
Computation spaces.
Definition core.hpp:1742
Gecode::Val
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_PV
#define GECODE_INT_PV(CASE, TELL, UPDATE)
Definition int-bin.hpp:179
Gecode::Int::Linear
Linear propagators
Gecode::Int::Linear::TerMod
TerMod
Describe which view has been modified how.
Definition int-ter.hpp:128
Gecode::Int::Linear::TM_X1_MIN
@ TM_X1_MIN
Definition int-ter.hpp:131
Gecode::Int::Linear::TM_X0_MAX
@ TM_X0_MAX
Definition int-ter.hpp:130
Gecode::Int::Linear::TM_X0_MIN
@ TM_X0_MIN
Definition int-ter.hpp:129
Gecode::Int::Linear::TM_ALL
@ TM_ALL
Definition int-ter.hpp:135
Gecode::Int::Linear::TM_X1_MAX
@ TM_X1_MAX
Definition int-ter.hpp:132
Gecode::Int::Linear::TM_X2_MAX
@ TM_X2_MAX
Definition int-ter.hpp:134
Gecode::Int::Linear::TM_X2_MIN
@ TM_X2_MIN
Definition int-ter.hpp:133
Gecode::Int
Finite domain integers.
Gecode::Int::PC_INT_VAL
const Gecode::PropCond PC_INT_VAL
Propagate when a view becomes assigned (single value).
Definition var-type.hpp:82
Gecode::Int::PC_INT_BND
const Gecode::PropCond PC_INT_BND
Propagate when minimum or maximum of a view changes.
Definition var-type.hpp:91
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
forceinline
#define forceinline
Definition config.hpp:187