element.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/element.hh>
namespace Gecode {
void
element(Home home, IntSharedArray c, IntVar x0, IntVar x1,
IntPropLevel) {
using namespace Int;
if (c.size() == 0)
throw TooFewArguments("Int::element");
GECODE_POST;
for (int i=0; i<c.size(); i++)
Limits::check(c[i],"Int::element");
GECODE_ES_FAIL((Element::post_int<IntView,IntView>(home,c,x0,x1)));
}
void
element(Home home, IntSharedArray c, IntVar x0, BoolVar x1,
IntPropLevel) {
using namespace Int;
if (c.size() == 0)
throw TooFewArguments("Int::element");
GECODE_POST;
for (int i=0; i<c.size(); i++)
Limits::check(c[i],"Int::element");
GECODE_ES_FAIL((Element::post_int<IntView,BoolView>(home,c,x0,x1)));
}
void
element(Home home, IntSharedArray c, IntVar x0, int x1,
IntPropLevel) {
using namespace Int;
if (c.size() == 0)
throw TooFewArguments("Int::element");
Limits::check(x1,"Int::element");
GECODE_POST;
for (int i=0; i<c.size(); i++)
Limits::check(c[i],"Int::element");
ConstIntView cx1(x1);
GECODE_ES_FAIL(
(Element::post_int<IntView,ConstIntView>(home,c,x0,cx1)));
}
void
element(Home home, const IntVarArgs& c, IntVar x0, IntVar x1,
IntPropLevel ipl) {
using namespace Int;
if (c.size() == 0)
throw TooFewArguments("Int::element");
GECODE_POST;
IdxViewArray<IntView> iv(home,c);
if ((vbd(ipl) == IPL_DOM) || (vbd(ipl) == IPL_DEF)) {
GECODE_ES_FAIL((Element::ViewDom<IntView,IntView,IntView>
::post(home,iv,x0,x1)));
} else {
GECODE_ES_FAIL((Element::ViewBnd<IntView,IntView,IntView>
::post(home,iv,x0,x1)));
}
}
void
element(Home home, const IntVarArgs& c, IntVar x0, int x1,
IntPropLevel ipl) {
using namespace Int;
if (c.size() == 0)
throw TooFewArguments("Int::element");
Limits::check(x1,"Int::element");
GECODE_POST;
IdxViewArray<IntView> iv(home,c);
ConstIntView v1(x1);
if ((vbd(ipl) == IPL_DOM) || (vbd(ipl) == IPL_DEF)) {
GECODE_ES_FAIL((Element::ViewDom<IntView,IntView,ConstIntView>
::post(home,iv,x0,v1)));
} else {
GECODE_ES_FAIL((Element::ViewBnd<IntView,IntView,ConstIntView>
::post(home,iv,x0,v1)));
}
}
void
element(Home home, const BoolVarArgs& c, IntVar x0, BoolVar x1,
IntPropLevel) {
using namespace Int;
if (c.size() == 0)
throw TooFewArguments("Int::element");
GECODE_POST;
IdxViewArray<BoolView> iv(home,c);
GECODE_ES_FAIL((Element::ViewBnd<BoolView,IntView,BoolView>
::post(home,iv,x0,x1)));
}
void
element(Home home, const BoolVarArgs& c, IntVar x0, int x1,
IntPropLevel) {
using namespace Int;
if (c.size() == 0)
throw TooFewArguments("Int::element");
Limits::check(x1,"Int::element");
GECODE_POST;
IdxViewArray<BoolView> iv(home,c);
ConstIntView v1(x1);
GECODE_ES_FAIL((Element::ViewBnd<BoolView,IntView,ConstIntView>
::post(home,iv,x0,v1)));
}
namespace {
IntVar
pair(Home home, IntVar x, int w, IntVar y, int h) {
IntVar xy(home,0,w*h-1);
if (Int::Element::Pair::post(home,x,y,xy,w,h) != ES_OK)
home.fail();
return xy;
}
}
void
element(Home home, IntSharedArray a,
IntVar x, int w, IntVar y, int h, IntVar z,
IntPropLevel ipl) {
using namespace Int;
if (a.size() != w*h)
throw Int::ArgumentSizeMismatch("Int::element");
GECODE_POST;
element(home, a, pair(home,x,w,y,h), z, ipl);
}
void
element(Home home, IntSharedArray a,
IntVar x, int w, IntVar y, int h, BoolVar z,
IntPropLevel ipl) {
using namespace Int;
if (a.size() != w*h)
throw Int::ArgumentSizeMismatch("Int::element");
GECODE_POST;
element(home, a, pair(home,x,w,y,h), z, ipl);
}
void
element(Home home, const IntVarArgs& a,
IntVar x, int w, IntVar y, int h, IntVar z,
IntPropLevel ipl) {
using namespace Int;
if (a.size() != w*h)
throw Int::ArgumentSizeMismatch("Int::element");
GECODE_POST;
element(home, a, pair(home,x,w,y,h), z, ipl);
}
void
element(Home home, const BoolVarArgs& a,
IntVar x, int w, IntVar y, int h, BoolVar z,
IntPropLevel ipl) {
using namespace Int;
if (a.size() != w*h)
throw Int::ArgumentSizeMismatch("Int::element");
GECODE_POST;
element(home, a, pair(home,x,w,y,h), z, ipl);
}
}
// STATISTICS: int-post
Gecode::BoolVarArgs
Passing Boolean variables.
Definition int.hh:712
Gecode::BoolVar
Boolean integer variables.
Definition int.hh:512
Gecode::FloatVal::size
FloatNum size(void) const
Return size of float value (distance between maximum and minimum).
Definition val.hpp:78
Gecode::Home
Home class for posting propagators
Definition core.hpp:856
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::ConstIntView
Constant integer view.
Definition view.hpp:851
Gecode::Int::Element::Pair::post
static ExecStatus post(Home home, IntView x0, IntView x1, IntView x2, int w, int h)
Post propagator .
Definition pair.hpp:43
Gecode::Int::Element::ViewBnd
Bounds consistent element propagator for array of views.
Definition element.hh:232
Gecode::Int::Element::ViewDom
Domain consistent element propagator for array of views.
Definition element.hh:262
Gecode::Int::IdxViewArray
An array of IdxView pairs.
Definition idx-view.hh:67
Gecode::Int::TooFewArguments
Exception: Too few arguments available in argument array
Definition exception.hpp:66
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::IntPropLevel
IntPropLevel
Propagation levels for integer propagators.
Definition int.hh:974
Gecode::IPL_DOM
@ IPL_DOM
Domain propagation Options: basic versus advanced propagation.
Definition int.hh:979
Gecode::IPL_DEF
@ IPL_DEF
Simple propagation levels.
Definition int.hh:976
element.hh
Gecode::Int::Element::post_int
ExecStatus post_int(Home home, IntSharedArray &c, V0 x0, V1 x1)
Post propagator with apropriate index and value types.
Definition int.hpp:405
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::IntSharedArray
SharedArray< int > IntSharedArray
Arrays of integers that can be shared among several element constraints.
Definition int.hh:1477
Gecode::vbd
IntPropLevel vbd(IntPropLevel ipl)
Extract value, bounds, or domain propagation from propagation level.
Definition ipl.hpp:37
Gecode::element
void element(Home home, IntSharedArray n, IntVar x0, IntVar x1, IntPropLevel ipl=IPL_DEF)
Post domain consistent propagator for .
Definition element.cpp:39
Gecode::post
TFE post(PropagatorGroup g)
Only post functions (but not propagators) from g are considered.
Definition filter.cpp:138
Gecode::ES_OK
@ ES_OK
Execution is okay.
Definition core.hpp:476