rel.cpp
Go to the documentation of this file.
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
* Main authors:
* Christian Schulte <schulte@gecode.org>
* Vincent Barichard <Vincent.Barichard@univ-angers.fr>
*
* Copyright:
* Christian Schulte, 2002
* 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.
*
*/
#include <gecode/float/rel.hh>
#include <algorithm>
namespace Gecode {
void
rel(Home home, FloatVar x0, FloatRelType frt, FloatVal n) {
using namespace Float;
Limits::check(n,"Float::rel");
GECODE_POST;
FloatView x(x0);
switch (frt) {
case FRT_EQ: GECODE_ME_FAIL(x.eq(home,n)); break;
case FRT_NQ:
GECODE_ES_FAIL((Rel::NqFloat<FloatView>::post(home,x,n)));
break;
case FRT_LQ: GECODE_ME_FAIL(x.lq(home,n)); break;
case FRT_LE:
GECODE_ME_FAIL(x.lq(home,n));
GECODE_ES_FAIL((Rel::NqFloat<FloatView>::post(home,x,n)));
break;
case FRT_GQ: GECODE_ME_FAIL(x.gq(home,n)); break;
case FRT_GR:
GECODE_ME_FAIL(x.gq(home,n));
GECODE_ES_FAIL((Rel::NqFloat<FloatView>::post(home,x,n)));
break;
default: throw UnknownRelation("Float::rel");
}
}
void
rel(Home home, FloatVar x0, FloatRelType frt, FloatVar x1) {
using namespace Float;
GECODE_POST;
switch (frt) {
case FRT_EQ:
GECODE_ES_FAIL((Rel::Eq<FloatView,FloatView>::post(home,x0,x1)));
break;
case FRT_NQ:
GECODE_ES_FAIL((Rel::Nq<FloatView,FloatView>::post(home,x0,x1)));
break;
case FRT_GQ:
std::swap(x0,x1); // Fall through
case FRT_LQ:
GECODE_ES_FAIL((Rel::Lq<FloatView>::post(home,x0,x1))); break;
case FRT_GR:
std::swap(x0,x1); // Fall through
case FRT_LE:
GECODE_ES_FAIL((Rel::Le<FloatView>::post(home,x0,x1))); break;
default:
throw UnknownRelation("Float::rel");
}
}
void
rel(Home home, FloatVar x0, FloatRelType frt, FloatVar x1, Reify r) {
using namespace Float;
GECODE_POST;
switch (frt) {
case FRT_EQ:
switch (r.mode()) {
case RM_EQV:
GECODE_ES_FAIL((Rel::ReEq<FloatView,Int::BoolView,RM_EQV>::
post(home,x0,x1,r.var())));
break;
case RM_IMP:
GECODE_ES_FAIL((Rel::ReEq<FloatView,Int::BoolView,RM_IMP>::
post(home,x0,x1,r.var())));
break;
case RM_PMI:
GECODE_ES_FAIL((Rel::ReEq<FloatView,Int::BoolView,RM_PMI>::
post(home,x0,x1,r.var())));
break;
default: throw Int::UnknownReifyMode("Float::rel");
}
break;
case FRT_NQ:
{
Int::NegBoolView n(r.var());
switch (r.mode()) {
case RM_EQV:
GECODE_ES_FAIL((Rel::ReEq<FloatView,Int::NegBoolView,RM_EQV>::
post(home,x0,x1,n)));
break;
case RM_IMP:
GECODE_ES_FAIL((Rel::ReEq<FloatView,Int::NegBoolView,RM_PMI>::
post(home,x0,x1,n)));
break;
case RM_PMI:
GECODE_ES_FAIL((Rel::ReEq<FloatView,Int::NegBoolView,RM_IMP>::
post(home,x0,x1,n)));
break;
default: throw Int::UnknownReifyMode("Float::rel");
}
break;
}
case FRT_GQ:
std::swap(x0,x1); // Fall through
case FRT_LQ:
switch (r.mode()) {
case RM_EQV:
GECODE_ES_FAIL((Rel::ReLq<FloatView,Int::BoolView,RM_EQV>::
post(home,x0,x1,r.var())));
break;
case RM_IMP:
GECODE_ES_FAIL((Rel::ReLq<FloatView,Int::BoolView,RM_IMP>::
post(home,x0,x1,r.var())));
break;
case RM_PMI:
GECODE_ES_FAIL((Rel::ReLq<FloatView,Int::BoolView,RM_PMI>::
post(home,x0,x1,r.var())));
break;
default: throw Int::UnknownReifyMode("Float::rel");
}
break;
case FRT_LE:
std::swap(x0,x1); // Fall through
case FRT_GR:
{
Int::NegBoolView n(r.var());
switch (r.mode()) {
case RM_EQV:
GECODE_ES_FAIL((Rel::ReLq<FloatView,Int::NegBoolView,RM_EQV>::
post(home,x0,x1,n)));
break;
case RM_IMP:
GECODE_ES_FAIL((Rel::ReLq<FloatView,Int::NegBoolView,RM_PMI>::
post(home,x0,x1,n)));
break;
case RM_PMI:
GECODE_ES_FAIL((Rel::ReLq<FloatView,Int::NegBoolView,RM_IMP>::
post(home,x0,x1,n)));
break;
default: throw Int::UnknownReifyMode("Float::rel");
}
break;
}
default:
throw Int::UnknownRelation("Float::rel");
}
}
void
rel(Home home, FloatVar x, FloatRelType frt, FloatVal n, Reify r) {
using namespace Float;
Limits::check(n,"Float::rel");
GECODE_POST;
switch (frt) {
case FRT_EQ:
switch (r.mode()) {
case RM_EQV:
GECODE_ES_FAIL((Rel::ReEqFloat<FloatView,Int::BoolView,RM_EQV>::
post(home,x,n,r.var())));
break;
case RM_IMP:
GECODE_ES_FAIL((Rel::ReEqFloat<FloatView,Int::BoolView,RM_IMP>::
post(home,x,n,r.var())));
break;
case RM_PMI:
GECODE_ES_FAIL((Rel::ReEqFloat<FloatView,Int::BoolView,RM_PMI>::
post(home,x,n,r.var())));
break;
default: throw Int::UnknownReifyMode("Float::rel");
}
break;
case FRT_NQ:
{
Int::NegBoolView nb(r.var());
switch (r.mode()) {
case RM_EQV:
GECODE_ES_FAIL((Rel::ReEqFloat<FloatView,Int::NegBoolView,RM_EQV>::
post(home,x,n,nb)));
break;
case RM_IMP:
GECODE_ES_FAIL((Rel::ReEqFloat<FloatView,Int::NegBoolView,RM_PMI>::
post(home,x,n,nb)));
break;
case RM_PMI:
GECODE_ES_FAIL((Rel::ReEqFloat<FloatView,Int::NegBoolView,RM_IMP>::
post(home,x,n,nb)));
break;
default: throw Int::UnknownReifyMode("Float::rel");
}
break;
}
case FRT_LQ:
switch (r.mode()) {
case RM_EQV:
GECODE_ES_FAIL((Rel::ReLqFloat<FloatView,Int::BoolView,RM_EQV>::
post(home,x,n,r.var())));
break;
case RM_IMP:
GECODE_ES_FAIL((Rel::ReLqFloat<FloatView,Int::BoolView,RM_IMP>::
post(home,x,n,r.var())));
break;
case RM_PMI:
GECODE_ES_FAIL((Rel::ReLqFloat<FloatView,Int::BoolView,RM_PMI>::
post(home,x,n,r.var())));
break;
default: throw Int::UnknownReifyMode("Float::rel");
}
break;
case FRT_LE:
switch (r.mode()) {
case RM_EQV:
GECODE_ES_FAIL((Rel::ReLeFloat<FloatView,Int::BoolView,RM_EQV>::
post(home,x,n,r.var())));
break;
case RM_IMP:
GECODE_ES_FAIL((Rel::ReLeFloat<FloatView,Int::BoolView,RM_IMP>::
post(home,x,n,r.var())));
break;
case RM_PMI:
GECODE_ES_FAIL((Rel::ReLeFloat<FloatView,Int::BoolView,RM_PMI>::
post(home,x,n,r.var())));
break;
default: throw Int::UnknownReifyMode("Float::rel");
}
break;
case FRT_GQ:
{
Int::NegBoolView nb(r.var());
switch (r.mode()) {
case RM_EQV:
GECODE_ES_FAIL((Rel::ReLeFloat<FloatView,Int::NegBoolView,RM_EQV>::
post(home,x,n,nb)));
break;
case RM_IMP:
GECODE_ES_FAIL((Rel::ReLeFloat<FloatView,Int::NegBoolView,RM_PMI>::
post(home,x,n,nb)));
break;
case RM_PMI:
GECODE_ES_FAIL((Rel::ReLeFloat<FloatView,Int::NegBoolView,RM_IMP>::
post(home,x,n,nb)));
break;
default: throw Int::UnknownReifyMode("Float::rel");
}
break;
}
case FRT_GR:
{
Int::NegBoolView nb(r.var());
switch (r.mode()) {
case RM_EQV:
GECODE_ES_FAIL((Rel::ReLqFloat<FloatView,Int::NegBoolView,RM_EQV>::
post(home,x,n,nb)));
break;
case RM_IMP:
GECODE_ES_FAIL((Rel::ReLqFloat<FloatView,Int::NegBoolView,RM_PMI>::
post(home,x,n,nb)));
break;
case RM_PMI:
GECODE_ES_FAIL((Rel::ReLqFloat<FloatView,Int::NegBoolView,RM_IMP>::
post(home,x,n,nb)));
break;
default: throw Int::UnknownReifyMode("Float::rel");
}
break;
}
default:
throw Int::UnknownRelation("Float::rel");
}
}
void
rel(Home home, const FloatVarArgs& x, FloatRelType frt, FloatVal c) {
using namespace Float;
Limits::check(c,"Float::rel");
GECODE_POST;
switch (frt) {
case FRT_EQ:
for (int i=x.size(); i--; ) {
FloatView xi(x[i]); GECODE_ME_FAIL(xi.eq(home,c));
}
break;
case FRT_NQ:
for (int i=x.size(); i--; ) {
FloatView xi(x[i]); GECODE_ES_FAIL((Rel::NqFloat<FloatView>::post(home,xi,c)));
}
break;
case FRT_LQ:
for (int i=x.size(); i--; ) {
FloatView xi(x[i]); GECODE_ME_FAIL(xi.lq(home,c));
}
break;
case FRT_LE:
for (int i=x.size(); i--; ) {
FloatView xi(x[i]); GECODE_ME_FAIL(xi.lq(home,c));
GECODE_ES_FAIL((Rel::NqFloat<FloatView>::post(home,xi,c)));
}
break;
case FRT_GQ:
for (int i=x.size(); i--; ) {
FloatView xi(x[i]); GECODE_ME_FAIL(xi.gq(home,c));
}
break;
case FRT_GR:
for (int i=x.size(); i--; ) {
FloatView xi(x[i]); GECODE_ME_FAIL(xi.gq(home,c));
GECODE_ES_FAIL((Rel::NqFloat<FloatView>::post(home,xi,c)));
}
break;
default:
throw UnknownRelation("Float::rel");
}
}
void
rel(Home home, const FloatVarArgs& x, FloatRelType frt, FloatVar y) {
using namespace Float;
GECODE_POST;
switch (frt) {
case FRT_EQ:
for (int i=x.size(); i--; ) {
GECODE_ES_FAIL((Rel::Eq<FloatView,FloatView>::post(home,y,x[i])));
}
break;
case FRT_NQ:
for (int i=x.size(); i--; ) {
GECODE_ES_FAIL((Rel::Nq<FloatView,FloatView>::post(home,y,x[i])));
}
break;
case FRT_GQ:
for (int i=x.size(); i--; ) {
GECODE_ES_FAIL((Rel::Lq<FloatView>::post(home,y,x[i])));
}
break;
case FRT_GR:
for (int i=x.size(); i--; ) {
GECODE_ES_FAIL((Rel::Le<FloatView>::post(home,y,x[i])));
}
break;
case FRT_LQ:
for (int i=x.size(); i--; ) {
GECODE_ES_FAIL((Rel::Lq<FloatView>::post(home,x[i],y)));
}
break;
case FRT_LE:
for (int i=x.size(); i--; ) {
GECODE_ES_FAIL((Rel::Le<FloatView>::post(home,x[i],y)));
}
break;
default:
throw UnknownRelation("Float::rel");
}
}
}
// STATISTICS: float-post
Gecode::ArgArrayBase::size
int size(void) const
Return size of array (number of elements).
Definition array.hpp:1607
Gecode::FloatVal
Float value type.
Definition float.hh:334
Gecode::FloatVarArgs
Passing float variables.
Definition float.hh:979
Gecode::FloatVar
Float variables.
Definition float.hh:870
Gecode::Home
Home class for posting propagators
Definition core.hpp:856
Gecode::Int::NegBoolView
Negated Boolean view.
Definition view.hpp:1574
Gecode::Int::Rel::Le::post
static ExecStatus post(Home home, V0 x0, V1 x1)
Post propagator .
Definition lq-le.hpp:91
Gecode::Int::Rel::Lq::post
static ExecStatus post(Home home, V0 x0, V1 x1)
Post propagator .
Definition lq-le.hpp:50
Gecode::Int::Rel::Nq::post
static ExecStatus post(Home home, V0 x0, V1 x1)
Post propagator .
Definition nq.hpp:49
Gecode::Int::Rel::ReLq
Reified less or equal propagator.
Definition rel.hh:548
Gecode::Int::UnknownReifyMode
Exception: Unknown reification mode passed as argument
Definition exception.hpp:115
Gecode::Int::UnknownRelation
Exception: Unknown relation passed as argument
Definition exception.hpp:87
Gecode::Reify
Reification specification.
Definition int.hh:876
Gecode::Set::Rel::Eq::post
static ExecStatus post(Home home, View0 x, View1 y)
Post propagator .
Definition eq.hpp:54
Gecode::Set::Rel::ReEq
Reified equality propagator
Definition rel.hh:174
rel.hh
GECODE_POST
#define GECODE_POST
Check for failure in a constraint post function.
Definition macros.hpp:40
GECODE_ES_FAIL
#define GECODE_ES_FAIL(es)
Check whether execution status es is failed, and fail space home.
Definition macros.hpp:103
GECODE_ME_FAIL
#define GECODE_ME_FAIL(me)
Check whether modification event me is failed, and fail space home.
Definition macros.hpp:77
Gecode::rel
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVar x1)
Post propagator for .
Definition rel.cpp:68
Gecode::FloatRelType
FloatRelType
Relation types for floats.
Definition float.hh:1068
Gecode::FRT_EQ
@ FRT_EQ
Equality ( ).
Definition float.hh:1069
Gecode::FRT_GR
@ FRT_GR
Greater ( ).
Definition float.hh:1074
Gecode::FRT_NQ
@ FRT_NQ
Disequality ( ).
Definition float.hh:1070
Gecode::FRT_LE
@ FRT_LE
Less ( ).
Definition float.hh:1072
Gecode::FRT_LQ
@ FRT_LQ
Less or equal ( ).
Definition float.hh:1071
Gecode::FRT_GQ
@ FRT_GQ
Greater or equal ( ).
Definition float.hh:1073
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::RM_EQV
@ RM_EQV
Equivalence for reification (default).
Definition int.hh:855
Gecode::Float
Floating point numbers.
Gecode::Int::Limits::check
void check(int n, const char *l)
Check whether n is in range, otherwise throw out of limits with information l.
Definition limits.hpp:46
Gecode
Gecode toplevel namespace
Gecode::post
TFE post(PropagatorGroup g)
Only post functions (but not propagators) from g are considered.
Definition filter.cpp:138