dom.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>
*
* 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.
*
*/
#include <gecode/int/dom.hh>
#include <gecode/int/rel.hh>
namespace Gecode {
void
dom(Home home, IntVar x, int n, IntPropLevel) {
using namespace Int;
Limits::check(n,"Int::dom");
GECODE_POST;
IntView xv(x);
GECODE_ME_FAIL(xv.eq(home,n));
}
void
dom(Home home, const IntVarArgs& x, int n, IntPropLevel) {
using namespace Int;
Limits::check(n,"Int::dom");
GECODE_POST;
for (int i=0; i<x.size(); i++) {
IntView xv(x[i]);
GECODE_ME_FAIL(xv.eq(home,n));
}
}
void
dom(Home home, IntVar x, int min, int max, IntPropLevel) {
using namespace Int;
Limits::check(min,"Int::dom");
Limits::check(max,"Int::dom");
GECODE_POST;
IntView xv(x);
GECODE_ME_FAIL(xv.gq(home,min));
GECODE_ME_FAIL(xv.lq(home,max));
}
void
dom(Home home, const IntVarArgs& x, int min, int max, IntPropLevel) {
using namespace Int;
Limits::check(min,"Int::dom");
Limits::check(max,"Int::dom");
GECODE_POST;
for (int i=0; i<x.size(); i++) {
IntView xv(x[i]);
GECODE_ME_FAIL(xv.gq(home,min));
GECODE_ME_FAIL(xv.lq(home,max));
}
}
void
dom(Home home, IntVar x, const IntSet& is, IntPropLevel) {
using namespace Int;
Limits::check(is.min(),"Int::dom");
Limits::check(is.max(),"Int::dom");
GECODE_POST;
IntView xv(x);
IntSetRanges ris(is);
GECODE_ME_FAIL(xv.inter_r(home,ris,false));
}
void
dom(Home home, const IntVarArgs& x, const IntSet& is, IntPropLevel) {
using namespace Int;
Limits::check(is.min(),"Int::dom");
Limits::check(is.max(),"Int::dom");
GECODE_POST;
for (int i=0; i<x.size(); i++) {
IntSetRanges ris(is);
IntView xv(x[i]);
GECODE_ME_FAIL(xv.inter_r(home,ris,false));
}
}
void
dom(Home home, IntVar x, int n, Reify r, IntPropLevel) {
using namespace Int;
Limits::check(n,"Int::dom");
GECODE_POST;
switch (r.mode()) {
case RM_EQV:
GECODE_ES_FAIL((Rel::ReEqDomInt<IntView,BoolView,RM_EQV>
::post(home,x,n,r.var())));
break;
case RM_IMP:
GECODE_ES_FAIL((Rel::ReEqDomInt<IntView,BoolView,RM_IMP>
::post(home,x,n,r.var())));
break;
case RM_PMI:
GECODE_ES_FAIL((Rel::ReEqDomInt<IntView,BoolView,RM_PMI>
::post(home,x,n,r.var())));
break;
default: throw UnknownReifyMode("Int::dom");
}
}
void
dom(Home home, IntVar x, int min, int max, Reify r, IntPropLevel) {
using namespace Int;
Limits::check(min,"Int::dom");
Limits::check(max,"Int::dom");
GECODE_POST;
switch (r.mode()) {
case RM_EQV:
GECODE_ES_FAIL((Dom::ReRange<IntView,RM_EQV>
::post(home,x,min,max,r.var())));
break;
case RM_IMP:
GECODE_ES_FAIL((Dom::ReRange<IntView,RM_IMP>
::post(home,x,min,max,r.var())));
break;
case RM_PMI:
GECODE_ES_FAIL((Dom::ReRange<IntView,RM_PMI>
::post(home,x,min,max,r.var())));
break;
default: throw UnknownReifyMode("Int::dom");
}
}
void
dom(Home home, IntVar x, const IntSet& is, Reify r, IntPropLevel) {
using namespace Int;
Limits::check(is.min(),"Int::dom");
Limits::check(is.max(),"Int::dom");
GECODE_POST;
switch (r.mode()) {
case RM_EQV:
GECODE_ES_FAIL((Dom::ReIntSet<IntView,RM_EQV>::post(home,x,is,r.var())));
break;
case RM_IMP:
GECODE_ES_FAIL((Dom::ReIntSet<IntView,RM_IMP>::post(home,x,is,r.var())));
break;
case RM_PMI:
GECODE_ES_FAIL((Dom::ReIntSet<IntView,RM_PMI>::post(home,x,is,r.var())));
break;
default: throw UnknownReifyMode("Int::dom");
}
}
void
dom(Home home, IntVar x, IntVar d, IntPropLevel) {
using namespace Int;
GECODE_POST;
IntView xv(x), dv(d);
if (xv != dv) {
ViewRanges<IntView> r(dv);
GECODE_ME_FAIL(xv.inter_r(home,r,false));
}
}
void
dom(Home home, BoolVar x, BoolVar d, IntPropLevel) {
using namespace Int;
GECODE_POST;
if (d.one())
GECODE_ME_FAIL(BoolView(x).one(home));
else if (d.zero())
GECODE_ME_FAIL(BoolView(x).zero(home));
}
void
dom(Home home, const IntVarArgs& x, const IntVarArgs& d, IntPropLevel) {
using namespace Int;
if (x.size() != d.size())
throw ArgumentSizeMismatch("Int::dom");
for (int i=0; i<x.size(); i++) {
GECODE_POST;
IntView xv(x[i]), dv(d[i]);
if (xv != dv) {
ViewRanges<IntView> r(dv);
GECODE_ME_FAIL(xv.inter_r(home,r,false));
}
}
}
void
dom(Home home, const BoolVarArgs& x, const BoolVarArgs& d, IntPropLevel) {
using namespace Int;
if (x.size() != d.size())
throw ArgumentSizeMismatch("Int::dom");
for (int i=0; i<x.size(); i++) {
GECODE_POST;
if (d[i].one())
GECODE_ME_FAIL(BoolView(x[i]).one(home));
else if (d[i].zero())
GECODE_ME_FAIL(BoolView(x[i]).zero(home));
}
}
}
// STATISTICS: int-post
Gecode::ArgArrayBase::size
int size(void) const
Return size of array (number of elements).
Definition array.hpp:1607
Gecode::BoolVarArgs
Passing Boolean variables.
Definition int.hh:712
Gecode::BoolVar
Boolean integer variables.
Definition int.hh:512
Gecode::Home
Home class for posting propagators
Definition core.hpp:856
Gecode::IntSetRanges
Range iterator for integer sets.
Definition int.hh:292
Gecode::IntSet
Integer sets.
Definition int.hh:174
Gecode::IntSet::min
int min(int i) const
Return minimum of range at position i.
Definition int-set-1.hpp:152
Gecode::IntSet::max
int max(int i) const
Return maximum of range at position i.
Definition int-set-1.hpp:158
Gecode::IntSet::size
unsigned int size(void) const
Return size (cardinality) of set.
Definition int-set-1.hpp:198
Gecode::IntVarArgs
Passing integer variables.
Definition int.hh:656
Gecode::IntVar
Integer variables.
Definition int.hh:371
Gecode::Int::ArgumentSizeMismatch
Exception: Arguments are of different size
Definition exception.hpp:73
Gecode::Int::BoolView
Boolean view for Boolean variables.
Definition view.hpp:1380
Gecode::Int::Dom::ReIntSet::post
static ExecStatus post(Home home, View x, const IntSet &s, BoolView b)
Post propagator for .
Definition set.hpp:55
Gecode::Int::Dom::ReRange
Reified range dom-propagator.
Definition dom.hh:56
Gecode::Int::IntView
Integer view for integer variables.
Definition view.hpp:129
Gecode::Int::IntView::inter_r
ModEvent inter_r(Space &home, I &i, bool depends=true)
Intersect domain with ranges described by i.
Definition int.hpp:186
Gecode::Int::IntView::lq
ModEvent lq(Space &home, int n)
Restrict domain values to be less or equal than n.
Definition int.hpp:121
Gecode::Int::IntView::gq
ModEvent gq(Space &home, int n)
Restrict domain values to be greater or equal than n.
Definition int.hpp:139
Gecode::Int::IntView::eq
ModEvent eq(Space &home, int n)
Restrict domain values to be equal to n.
Definition int.hpp:166
Gecode::Int::Rel::ReEqDomInt
Reified domain consistent equality with integer propagator.
Definition rel.hh:398
Gecode::Int::UnknownReifyMode
Exception: Unknown reification mode passed as argument
Definition exception.hpp:115
Gecode::Int::ViewRanges
Range iterator for integer views.
Definition view.hpp:54
Gecode::Reify
Reification specification.
Definition int.hh:876
dom.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::IntPropLevel
IntPropLevel
Propagation levels for integer propagators.
Definition int.hh:974
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
rel.hh
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::Int
Finite domain integers.
Gecode
Gecode toplevel namespace
Gecode::min
void min(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition arithmetic.cpp:67
Gecode::dom
void dom(Home home, FloatVar x, FloatVal n)
Propagates .
Definition dom.cpp:40
Gecode::post
TFE post(PropagatorGroup g)
Only post functions (but not propagators) from g are considered.
Definition filter.cpp:138
Gecode::max
void max(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition arithmetic.cpp:49