lq-le.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>
* Gabor Szokoli <szokoli@gecode.org>
* Vincent Barichard <Vincent.Barichard@univ-angers.fr>
*
* Copyright:
* Christian Schulte, 2003
* Gabor Szokoli, 2003
* Vincent Barichard, 2012
*
* 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 Float { namespace Rel {
/*
* Less or equal propagator
*
*/
template<class View>
forceinline
Lq<View>::Lq(Home home, View x0, View x1)
: BinaryPropagator<View,PC_FLOAT_BND>(home,x0,x1) {}
template<class View>
ExecStatus
Lq<View>::post(Home home, View x0, View x1) {
GECODE_ME_CHECK(x0.lq(home,x1.max()));
GECODE_ME_CHECK(x1.gq(home,x0.min()));
if ((x0 != x1) && (x0.max() > x1.min()))
(void) new (home) Lq<View>(home,x0,x1);
return ES_OK;
}
template<class View>
forceinline
Lq<View>::Lq(Space& home, Lq<View>& p)
: BinaryPropagator<View,PC_FLOAT_BND>(home,p) {}
template<class View>
Actor*
Lq<View>::copy(Space& home) {
return new (home) Lq<View>(home,*this);
}
template<class View>
ExecStatus
Lq<View>::propagate(Space& home, const ModEventDelta&) {
GECODE_ME_CHECK(x0.lq(home,x1.max()));
GECODE_ME_CHECK(x1.gq(home,x0.min()));
return (x0.assigned() || x1.assigned() || (x0.max() <= x1.min())) ? home.ES_SUBSUMED(*this) : ES_FIX;
}
/*
* Less propagator
*
*/
template<class View>
forceinline
Le<View>::Le(Home home, View x0, View x1)
: BinaryPropagator<View,PC_FLOAT_BND>(home,x0,x1) {}
template<class View>
ExecStatus
Le<View>::post(Home home, View x0, View x1) {
GECODE_ME_CHECK(x0.lq(home,x1.max()));
GECODE_ME_CHECK(x1.gq(home,x0.min()));
if (x0.assigned() && x1.assigned()) {
if (x0.max() >= x1.min())
return ES_FAILED;
} else if (x0 == x1)
return ES_FAILED;
if (x0.max() >= x1.min())
(void) new (home) Le<View>(home,x0,x1);
return ES_OK;
}
template<class View>
forceinline
Le<View>::Le(Space& home, Le<View>& p)
: BinaryPropagator<View,PC_FLOAT_BND>(home,p) {}
template<class View>
Actor*
Le<View>::copy(Space& home) {
return new (home) Le<View>(home,*this);
}
template<class View>
ExecStatus
Le<View>::propagate(Space& home, const ModEventDelta&) {
GECODE_ME_CHECK(x0.lq(home,x1.max()));
GECODE_ME_CHECK(x1.gq(home,x0.min()));
if (x0.assigned() && x1.assigned()) {
return (x0.max() >= x1.min()) ? ES_FAILED : home.ES_SUBSUMED(*this);
}
return (x0.max() < x1.min()) ? home.ES_SUBSUMED(*this) : ES_FIX;
}
/*
* Reified less or equal propagator
*
*/
template<class View, class CtrlView, ReifyMode rm>
forceinline
ReLq<View,CtrlView,rm>::ReLq(Home home, View x0, View x1, CtrlView b)
: Int::ReBinaryPropagator<View,PC_FLOAT_BND,CtrlView>(home,x0,x1,b) {}
template<class View, class CtrlView, ReifyMode rm>
ExecStatus
ReLq<View,CtrlView,rm>::post(Home home, View x0, View x1, CtrlView b) {
if (b.one()) {
if (rm == RM_PMI)
return ES_OK;
return Lq<View>::post(home,x0,x1);
}
if (b.zero()) {
if (rm == RM_IMP)
return ES_OK;
return Le<View>::post(home,x1,x0);
}
if (x0 != x1) {
switch (rtest_lq(x0,x1)) {
case RT_TRUE:
if (rm != RM_IMP)
GECODE_ME_CHECK(b.one_none(home));
break;
case RT_FALSE:
if (rm != RM_PMI)
GECODE_ME_CHECK(b.zero_none(home));
break;
case RT_MAYBE:
if (!x0.assigned() || !x1.assigned())
(void) new (home) ReLq<View,CtrlView,rm>(home,x0,x1,b);
else {
if (rm != RM_IMP)
GECODE_ME_CHECK(b.one_none(home));
}
break;
default: GECODE_NEVER;
}
} else if (rm != RM_IMP) {
GECODE_ME_CHECK(b.one_none(home));
}
return ES_OK;
}
template<class View, class CtrlView, ReifyMode rm>
forceinline
ReLq<View,CtrlView,rm>::ReLq(Space& home, ReLq& p)
: Int::ReBinaryPropagator<View,PC_FLOAT_BND,CtrlView>(home,p) {}
template<class View, class CtrlView, ReifyMode rm>
Actor*
ReLq<View,CtrlView,rm>::copy(Space& home) {
return new (home) ReLq<View,CtrlView,rm>(home,*this);
}
template<class View, class CtrlView, ReifyMode rm>
ExecStatus
ReLq<View,CtrlView,rm>::propagate(Space& home, const ModEventDelta&) {
if (b.one()) {
if (rm != RM_PMI)
GECODE_REWRITE(*this,Lq<View>::post(home(*this),x0,x1));
} else if (b.zero()) {
if (rm != RM_IMP)
GECODE_REWRITE(*this,Le<View>::post(home(*this),x1,x0));
} else {
switch (rtest_lq(x0,x1)) {
case RT_TRUE:
if (rm != RM_IMP)
GECODE_ME_CHECK(b.one_none(home));
break;
case RT_FALSE:
if (rm != RM_PMI)
GECODE_ME_CHECK(b.zero_none(home));
break;
case RT_MAYBE:
if (!x0.assigned() || !x1.assigned())
return ES_FIX;
else {
if (rm != RM_IMP)
GECODE_ME_CHECK(b.one_none(home));
break;
}
default: GECODE_NEVER;
}
}
return home.ES_SUBSUMED(*this);
}
/*
* Reified less or equal propagator involving one variable
*
*/
template<class View, class CtrlView, ReifyMode rm>
forceinline
ReLqFloat<View,CtrlView,rm>::ReLqFloat(Home home, View x, FloatVal c0, CtrlView b)
: Int::ReUnaryPropagator<View,PC_FLOAT_BND,CtrlView>(home,x,b), c(c0) {}
template<class View, class CtrlView, ReifyMode rm>
ExecStatus
ReLqFloat<View,CtrlView,rm>::post(Home home, View x, FloatVal c, CtrlView b) {
if (b.one()) {
if (rm != RM_PMI)
GECODE_ME_CHECK(x.lq(home,c.max()));
} if (b.zero()) {
if (rm != RM_IMP) {
GECODE_ME_CHECK(x.gq(home,c.min()));
if (x.assigned() && (x.min() <= c.max()))
return ES_FAILED;
(void) new (home) ReLqFloat<View,CtrlView,rm>(home,x,c,b);
}
} else {
switch (rtest_lq(x,c)) {
case RT_TRUE:
if (rm != RM_IMP)
GECODE_ME_CHECK(b.one(home));
break;
case RT_FALSE:
if (rm != RM_PMI)
GECODE_ME_CHECK(b.zero(home));
break;
case RT_MAYBE:
(void) new (home) ReLqFloat<View,CtrlView,rm>(home,x,c,b);
break;
default: GECODE_NEVER;
}
}
return ES_OK;
}
template<class View, class CtrlView, ReifyMode rm>
forceinline
ReLqFloat<View,CtrlView,rm>::ReLqFloat(Space& home, ReLqFloat& p)
: Int::ReUnaryPropagator<View,PC_FLOAT_BND,CtrlView>(home,p), c(p.c) {}
template<class View, class CtrlView, ReifyMode rm>
Actor*
ReLqFloat<View,CtrlView,rm>::copy(Space& home) {
return new (home) ReLqFloat<View,CtrlView,rm>(home,*this);
}
template<class View, class CtrlView, ReifyMode rm>
ExecStatus
ReLqFloat<View,CtrlView,rm>::propagate(Space& home, const ModEventDelta&) {
if (b.one()) {
if (rm != RM_PMI)
GECODE_ME_CHECK(x0.lq(home,c.max()));
} else if (b.zero()) {
if (rm != RM_IMP)
{
GECODE_ME_CHECK(x0.gq(home,c.min()));
if (x0.assigned()) {
return (x0.min() <= c.max()) ? ES_FAILED : home.ES_SUBSUMED(*this);
}
}
} else {
switch (rtest_lq(x0,c)) {
case RT_TRUE:
if (rm != RM_IMP)
GECODE_ME_CHECK(b.one(home));
break;
case RT_FALSE:
if (rm != RM_PMI)
GECODE_ME_CHECK(b.zero(home));
break;
case RT_MAYBE:
return ES_FIX;
default: GECODE_NEVER;
}
}
return home.ES_SUBSUMED(*this);
}
/*
* Reified less
*
*/
template<class View, class CtrlView, ReifyMode rm>
forceinline
ReLeFloat<View,CtrlView,rm>::ReLeFloat(Home home, View x, FloatVal c0, CtrlView b)
: Int::ReUnaryPropagator<View,PC_FLOAT_BND,CtrlView>(home,x,b), c(c0) {}
template<class View, class CtrlView, ReifyMode rm>
ExecStatus
ReLeFloat<View,CtrlView,rm>::post(Home home, View x, FloatVal c, CtrlView b) {
if (b.one()) {
if (rm != RM_PMI)
{
GECODE_ME_CHECK(x.lq(home,c.max()));
if (x.assigned() && (x.max() >= c.min()))
return ES_FAILED;
(void) new (home) ReLeFloat<View,CtrlView,rm>(home,x,c,b);
}
} else if (b.zero()) {
if (rm != RM_IMP)
GECODE_ME_CHECK(x.gq(home,c.min()));
} else {
switch (rtest_le(x,c)) {
case RT_TRUE:
if (rm != RM_IMP)
GECODE_ME_CHECK(b.one(home));
break;
case RT_FALSE:
if (rm != RM_PMI)
GECODE_ME_CHECK(b.zero(home));
break;
case RT_MAYBE:
(void) new (home) ReLeFloat<View,CtrlView,rm>(home,x,c,b);
break;
default: GECODE_NEVER;
}
}
return ES_OK;
}
template<class View, class CtrlView, ReifyMode rm>
forceinline
ReLeFloat<View,CtrlView,rm>::ReLeFloat(Space& home, ReLeFloat& p)
: Int::ReUnaryPropagator<View,PC_FLOAT_BND,CtrlView>(home,p), c(p.c) {}
template<class View, class CtrlView, ReifyMode rm>
Actor*
ReLeFloat<View,CtrlView,rm>::copy(Space& home) {
return new (home) ReLeFloat<View,CtrlView,rm>(home,*this);
}
template<class View, class CtrlView, ReifyMode rm>
ExecStatus
ReLeFloat<View,CtrlView,rm>::propagate(Space& home, const ModEventDelta&) {
if (b.one()) {
if (rm != RM_PMI)
{
GECODE_ME_CHECK(x0.lq(home,c.max()));
if (x0.assigned()) {
return (x0.max() >= c.min()) ? ES_FAILED : home.ES_SUBSUMED(*this);
}
}
} else if (b.zero()) {
if (rm != RM_IMP)
GECODE_ME_CHECK(x0.gq(home,c.min()));
} else {
switch (rtest_le(x0,c)) {
case RT_TRUE:
if (rm != RM_IMP)
GECODE_ME_CHECK(b.one(home));
break;
case RT_FALSE:
if (rm != RM_PMI)
GECODE_ME_CHECK(b.zero(home));
break;
case RT_MAYBE:
return ES_FIX;
default: GECODE_NEVER;
}
}
return home.ES_SUBSUMED(*this);
}
}}}
// STATISTICS: float-prop
Gecode::Actor
Base-class for both propagators and branchers.
Definition core.hpp:628
Gecode::BinaryPropagator
Binary propagator.
Definition pattern.hpp:84
Gecode::BinaryPropagator< View, PC_FLOAT_BND >::x0
View x0
Definition pattern.hpp:87
Gecode::BinaryPropagator< View, PC_FLOAT_BND >::BinaryPropagator
BinaryPropagator(Space &home, BinaryPropagator &p)
Gecode::BinaryPropagator< View, PC_FLOAT_BND >::x1
View x1
Definition pattern.hpp:87
Gecode::FloatVal
Float value type.
Definition float.hh:334
Gecode::Float::Rel::Le
Less propagator.
Definition rel.hh:267
Gecode::Float::Rel::Le::propagate
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition lq-le.hpp:117
Gecode::Float::Rel::Le::post
static ExecStatus post(Home home, View x0, View x1)
Post propagator .
Definition lq-le.hpp:91
Gecode::Float::Rel::Le::Le
Le(Space &home, Le &p)
Constructor for cloning p.
Gecode::Float::Rel::Le::copy
virtual Actor * copy(Space &home)
Copy propagator during cloning.
Definition lq-le.hpp:111
Gecode::Float::Rel::Lq
Less or equal propagator.
Definition rel.hh:241
Gecode::Float::Rel::Lq::Lq
Lq(Space &home, Lq &p)
Constructor for cloning p.
Gecode::Float::Rel::Lq::copy
virtual Actor * copy(Space &home)
Copy propagator during cloning.
Definition lq-le.hpp:67
Gecode::Float::Rel::Lq::post
static ExecStatus post(Home home, View x0, View x1)
Post propagator .
Definition lq-le.hpp:52
Gecode::Float::Rel::Lq::propagate
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition lq-le.hpp:73
Gecode::Float::Rel::ReLeFloat::post
static ExecStatus post(Home home, View x, FloatVal c, CtrlView b)
Post propagator for .
Definition lq-le.hpp:321
Gecode::Float::Rel::ReLeFloat::propagate
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition lq-le.hpp:366
Gecode::Float::Rel::ReLeFloat::copy
virtual Actor * copy(Space &home)
Copy propagator during cloning.
Definition lq-le.hpp:360
Gecode::Float::Rel::ReLeFloat::ReLeFloat
ReLeFloat(Space &home, ReLeFloat &p)
Constructor for cloning p.
Definition lq-le.hpp:355
Gecode::Float::Rel::ReLeFloat::c
FloatVal c
Float constant to check.
Definition rel.hh:332
Gecode::Float::Rel::ReLqFloat::c
FloatVal c
Float constant to check.
Definition rel.hh:304
Gecode::Float::Rel::ReLqFloat::post
static ExecStatus post(Home home, View x, FloatVal c, CtrlView b)
Post propagator for .
Definition lq-le.hpp:234
Gecode::Float::Rel::ReLqFloat::ReLqFloat
ReLqFloat(Space &home, ReLqFloat &p)
Constructor for cloning p.
Definition lq-le.hpp:267
Gecode::Float::Rel::ReLqFloat::propagate
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition lq-le.hpp:278
Gecode::Float::Rel::ReLqFloat::copy
virtual Actor * copy(Space &home)
Copy propagator during cloning.
Definition lq-le.hpp:272
Gecode::Float::Rel::ReLq::ReLq
ReLq(Space &home, ReLq &p)
Constructor for cloning p.
Definition lq-le.hpp:180
Gecode::Float::Rel::ReLq::post
static ExecStatus post(Home home, View x0, View x1, CtrlView b)
Post propagator for .
Definition lq-le.hpp:141
Gecode::Float::Rel::ReLq::propagate
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition lq-le.hpp:191
Gecode::Float::Rel::ReLq::copy
virtual Actor * copy(Space &home)
Copy propagator during cloning.
Definition lq-le.hpp:185
Gecode::Home
Home class for posting propagators
Definition core.hpp:856
Gecode::Int::ReBinaryPropagator< View, PC_FLOAT_BND, CtrlView >::ReBinaryPropagator
ReBinaryPropagator(Space &home, ReBinaryPropagator &p)
Gecode::Int::ReBinaryPropagator< View, PC_FLOAT_BND, CtrlView >::x0
View x0
Definition propagator.hpp:90
Gecode::Int::ReBinaryPropagator< View, PC_FLOAT_BND, CtrlView >::b
CtrlView b
Definition propagator.hpp:92
Gecode::Int::ReBinaryPropagator< View, PC_FLOAT_BND, CtrlView >::x1
View x1
Definition propagator.hpp:90
Gecode::Int::ReUnaryPropagator< View, PC_FLOAT_BND, CtrlView >::b
CtrlView b
Definition propagator.hpp:59
Gecode::Int::ReUnaryPropagator< View, PC_FLOAT_BND, CtrlView >::ReUnaryPropagator
ReUnaryPropagator(Space &home, ReUnaryPropagator &p)
Gecode::Int::ReUnaryPropagator< View, PC_FLOAT_BND, CtrlView >::x0
View x0
Definition propagator.hpp:57
Gecode::Propagator::Space
friend class Space
Definition core.hpp:1066
Gecode::Space
Computation spaces.
Definition core.hpp:1742
Gecode::View
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::RM_IMP
@ RM_IMP
Implication for reification.
Definition int.hh:862
Gecode::RM_PMI
@ RM_PMI
Inverse implication for reification.
Definition int.hh:869
Gecode::Float::Rel
Simple relation propagators.
Gecode::Float
Floating point numbers.
Gecode::Float::RT_TRUE
@ RT_TRUE
Relation does hold.
Definition view.hpp:536
Gecode::Float::RT_FALSE
@ RT_FALSE
Relation does not hold.
Definition view.hpp:534
Gecode::Float::RT_MAYBE
@ RT_MAYBE
Relation may hold or not.
Definition view.hpp:535
Gecode::Float::rtest_le
RelTest rtest_le(View x, View y)
Test whether view x is less than view y.
Definition rel-test.hpp:70
Gecode::Float::rtest_lq
RelTest rtest_lq(View x, View y)
Test whether view x is less or equal than view y.
Definition rel-test.hpp:54
Gecode::Float::PC_FLOAT_BND
const Gecode::PropCond PC_FLOAT_BND
Propagate when minimum or maximum of a view changes.
Definition var-type.hpp:292
Gecode::Int
Finite domain integers.
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