rel.cpp
Go to the documentation of this file.
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
* Main authors:
* Guido Tack <tack@gecode.org>
*
* Contributing authors:
* Gabor Szokoli <szokoli@gecode.org>
*
* Copyright:
* Guido Tack, 2004, 2005
*
* 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/set/rel.hh>
#include <gecode/set/rel-op.hh>
#include <gecode/set/int.hh>
namespace Gecode { namespace Set {
template<class View0, class View1>
forceinline void
rel_post(Home home, View0 x0, SetRelType r, View1 x1) {
using namespace Set::Rel;
using namespace Set::RelOp;
GECODE_POST;
switch (r) {
case SRT_EQ:
GECODE_ES_FAIL((Eq<View0,View1>::post(home,x0,x1)));
break;
case SRT_NQ:
GECODE_ES_FAIL((Distinct<View0,View1>::post(home,x0,x1)));
break;
case SRT_SUB:
GECODE_ES_FAIL((Subset<View0,View1>::post(home, x0,x1)));
break;
case SRT_SUP:
GECODE_ES_FAIL((Subset<View1,View0>::post(home, x1,x0)));
break;
case SRT_DISJ:
{
EmptyView emptyset;
GECODE_ES_FAIL((SuperOfInter<View0,View1,EmptyView>
::post(home, x0, x1, emptyset)));
}
break;
case SRT_CMPL:
{
ComplementView<View0> cx0(x0);
GECODE_ES_FAIL((Eq<ComplementView<View0>, View1>
::post(home, cx0, x1)));
}
break;
case SRT_LQ:
GECODE_ES_FAIL((Lq<View0,View1,false>::post(home,x0,x1)));
break;
case SRT_LE:
GECODE_ES_FAIL((Lq<View0,View1,true>::post(home,x0,x1)));
break;
case SRT_GQ:
GECODE_ES_FAIL((Lq<View1,View0,false>::post(home,x1,x0)));
break;
case SRT_GR:
GECODE_ES_FAIL((Lq<View1,View0,true>::post(home,x1,x0)));
break;
default:
throw UnknownRelation("Set::rel");
}
}
template<class View0, class View1, ReifyMode rm>
forceinline void
rel_re(Home home, View0 x, SetRelType r, View1 y, BoolVar b) {
using namespace Set::Rel;
using namespace Set::RelOp;
GECODE_POST;
switch (r) {
case SRT_EQ:
GECODE_ES_FAIL((ReEq<View0,View1,Gecode::Int::BoolView,rm>
::post(home, x,y,b)));
break;
case SRT_NQ:
{
Gecode::Int::NegBoolView notb(b);
switch (rm) {
case RM_EQV:
GECODE_ES_FAIL((ReEq<View0,View1,Gecode::Int::NegBoolView,RM_EQV>
::post(home,x,y,notb)));
break;
case RM_IMP:
GECODE_ES_FAIL((ReEq<View0,View1,Gecode::Int::NegBoolView,RM_PMI>
::post(home,x,y,notb)));
break;
case RM_PMI:
GECODE_ES_FAIL((ReEq<View0,View1,Gecode::Int::NegBoolView,RM_IMP>
::post(home,x,y,notb)));
break;
default: throw Gecode::Int::UnknownReifyMode("Set::rel");
}
}
break;
case SRT_SUB:
GECODE_ES_FAIL((ReSubset<View0,View1,Gecode::Int::BoolView,rm>::post(home, x,y,b)));
break;
case SRT_SUP:
GECODE_ES_FAIL((ReSubset<View1,View0,Gecode::Int::BoolView,rm>::post(home, y,x,b)));
break;
case SRT_DISJ:
{
// x||y <=> b is equivalent to
// ( y <= complement(x) ) <=> b
ComplementView<View0> xc(x);
GECODE_ES_FAIL((ReSubset<View1,ComplementView<View0>,
Gecode::Int::BoolView,rm>
::post(home, y, xc, b)));
}
break;
case SRT_CMPL:
{
ComplementView<View0> xc(x);
GECODE_ES_FAIL((ReEq<ComplementView<View0>,View1,
Gecode::Int::BoolView,rm>
::post(home, xc, y, b)));
}
break;
case SRT_LQ:
GECODE_ES_FAIL((ReLq<View0,View1,rm,false>::post(home,x,y,b)));
break;
case SRT_LE:
GECODE_ES_FAIL((ReLq<View0,View1,rm,true>::post(home,x,y,b)));
break;
case SRT_GQ:
GECODE_ES_FAIL((ReLq<View1,View0,rm,false>::post(home,y,x,b)));
break;
case SRT_GR:
GECODE_ES_FAIL((ReLq<View1,View0,rm,true>::post(home,y,x,b)));
break;
default:
throw UnknownRelation("Set::rel");
}
}
}}
namespace Gecode {
void
rel(Home home, SetVar x, SetRelType r, SetVar y) {
using namespace Set;
rel_post<SetView,SetView>(home,x,r,y);
}
void
rel(Home home, SetVar s, SetRelType r, IntVar x) {
using namespace Set;
Gecode::Int::IntView xv(x);
SingletonView xsingle(xv);
rel_post<SetView,SingletonView>(home,s,r,xv);
}
void
rel(Home home, IntVar x, SetRelType r, SetVar s) {
using namespace Set;
switch (r) {
case SRT_SUB:
rel(home, s, SRT_SUP, x);
break;
case SRT_SUP:
rel(home, s, SRT_SUB, x);
break;
default:
rel(home, s, r, x);
}
}
void
rel(Home home, SetVar x, SetRelType rt, SetVar y, Reify r) {
using namespace Set;
switch (r.mode()) {
case RM_EQV:
rel_re<SetView,SetView,RM_EQV>(home,x,rt,y,r.var());
break;
case RM_IMP:
rel_re<SetView,SetView,RM_IMP>(home,x,rt,y,r.var());
break;
case RM_PMI:
rel_re<SetView,SetView,RM_PMI>(home,x,rt,y,r.var());
break;
default: throw Gecode::Int::UnknownReifyMode("Set::rel");
}
}
void
rel(Home home, SetVar s, SetRelType rt, IntVar x, Reify r) {
using namespace Set;
Gecode::Int::IntView xv(x);
SingletonView xsingle(xv);
switch (r.mode()) {
case RM_EQV:
rel_re<SetView,SingletonView,RM_EQV>(home,s,rt,xsingle,r.var());
break;
case RM_IMP:
rel_re<SetView,SingletonView,RM_IMP>(home,s,rt,xsingle,r.var());
break;
case RM_PMI:
rel_re<SetView,SingletonView,RM_PMI>(home,s,rt,xsingle,r.var());
break;
default: throw Gecode::Int::UnknownReifyMode("Set::rel");
}
}
void
rel(Home home, IntVar x, SetRelType rt, SetVar s, Reify r) {
using namespace Set;
switch (rt) {
case SRT_SUB:
rel(home, s, SRT_SUP, x, r);
break;
case SRT_SUP:
rel(home, s, SRT_SUB, x, r);
break;
default:
rel(home, s, rt, x, r);
}
}
}
// STATISTICS: set-post
Gecode::BoolVar
Boolean integer variables.
Definition int.hh:512
Gecode::Home
Home class for posting propagators
Definition core.hpp:856
Gecode::IntVar
Integer variables.
Definition int.hh:371
Gecode::Int::BoolView
Boolean view for Boolean variables.
Definition view.hpp:1380
Gecode::Int::IntView
Integer view for integer variables.
Definition view.hpp:129
Gecode::Int::NegBoolView
Negated Boolean view.
Definition view.hpp:1574
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::SetVar
Set variables
Definition set.hh:127
Gecode::Set::ComplementView
Complement set view.
Definition view.hpp:769
Gecode::Set::EmptyView
Constant view for the empty set.
Definition view.hpp:336
Gecode::Set::RelOp::SuperOfInter
Propagator for the superset of intersection
Definition rel-op.hh:63
Gecode::Set::Rel::Distinct::post
static ExecStatus post(Home home, View0 x, View1 y)
Post propagator .
Definition nq.hpp:55
Gecode::Set::Rel::Eq
Propagator for set equality
Definition rel.hh:150
Gecode::Set::Rel::Eq::post
static ExecStatus post(Home home, View0 x, View1 y)
Post propagator .
Definition eq.hpp:54
Gecode::Set::Rel::Lq::post
static ExecStatus post(Home home, View0 x, View1 y)
Post propagator .
Definition lq.hpp:325
Gecode::Set::Rel::ReEq
Reified equality propagator
Definition rel.hh:174
Gecode::Set::Rel::ReLq::post
static ExecStatus post(Home home, View0 x, View1 y, Gecode::Int::BoolView b)
Post propagator for .
Definition re-lq.hpp:82
Gecode::Set::Rel::ReSubset
Reified subset propagator
Definition rel.hh:115
Gecode::Set::Rel::ReSubset::post
static ExecStatus post(Home home, View0 x, View1 y, CtrlView b)
Post propagator for .
Definition re-subset.hpp:85
Gecode::Set::Rel::Subset::post
static ExecStatus post(Home home, View0 x, View1 y)
Post propagator .
Definition subset.hpp:55
Gecode::Set::SingletonView
Singleton set view.
Definition view.hpp:594
int.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::rel
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVar x1)
Post propagator for .
Definition rel.cpp:68
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::SetRelType
SetRelType
Common relation types for sets.
Definition set.hh:643
Gecode::SRT_GQ
@ SRT_GQ
Greater or equal ( ).
Definition set.hh:652
Gecode::SRT_CMPL
@ SRT_CMPL
Complement.
Definition set.hh:649
Gecode::SRT_GR
@ SRT_GR
Greater ( ).
Definition set.hh:653
Gecode::SRT_LQ
@ SRT_LQ
Less or equal ( ).
Definition set.hh:650
Gecode::SRT_NQ
@ SRT_NQ
Disequality ( ).
Definition set.hh:645
Gecode::SRT_LE
@ SRT_LE
Less ( ).
Definition set.hh:651
Gecode::SRT_EQ
@ SRT_EQ
Equality ( ).
Definition set.hh:644
Gecode::SRT_SUP
@ SRT_SUP
Superset ( ).
Definition set.hh:647
Gecode::SRT_DISJ
@ SRT_DISJ
Disjoint ( ).
Definition set.hh:648
Gecode::SRT_SUB
@ SRT_SUB
Subset ( ).
Definition set.hh:646
Gecode::Int::Rel
Simple relation propagators.
Gecode::Set::RelOp
Standard set operation propagators.
Definition rel-op.hh:46
Gecode::Set
Finite integer sets.
Definition var-imp.hpp:137
Gecode::Set::rel_post
void rel_post(Home home, View0 x0, SetRelType r, View1 x1)
Definition rel.cpp:45
Gecode::Set::rel_re
void rel_re(Home home, View0 x, SetRelType r, View1 y, BoolVar b)
Definition rel.cpp:95
Gecode
Gecode toplevel namespace
Gecode::post
TFE post(PropagatorGroup g)
Only post functions (but not propagators) from g are considered.
Definition filter.cpp:138
rel-op.hh
rel.hh
forceinline
#define forceinline
Definition config.hpp:187