element.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>
* Christian Schulte <schulte@gecode.org>
*
* Copyright:
* Guido Tack, 2004
* 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/set/element.hh>
namespace Gecode {
namespace Int {
template<>
class ViewToVarArg<Gecode::Set::ConstSetView> {
public:
typedef IntSetArgs argtype;
};
}
using namespace Gecode::Set;
void
element(Home home, SetOpType op, const SetVarArgs& x, SetVar y, SetVar z,
const IntSet& universe) {
GECODE_POST;
switch (op) {
case SOT_DUNION:
{
Set::Element::ElementDisjoint<SetView,SetView>::IdxViewArray
iv(home, x);
GECODE_ES_FAIL((Element::ElementDisjoint<SetView,SetView>::
post(home,iv,y)));
}
// fall through
case SOT_UNION:
{
Set::Element::ElementUnion<SetView,SetView,SetView>::IdxViewArray
iv(home, x);
GECODE_ES_FAIL(
(Element::ElementUnion<SetView,SetView,SetView>::
post(home,iv,y,z)));
}
break;
case SOT_INTER:
{
Set::Element::ElementIntersection<SetView,SetView,SetView>::IdxViewArray
iv(home, x);
GECODE_ES_FAIL(
(Element::ElementIntersection<SetView,SetView,SetView>::
post(home,iv,y,z,universe)));
}
break;
case SOT_MINUS:
throw IllegalOperation("Set::element");
break;
default:
throw UnknownOperation("Set::element");
}
}
void
element(Home home, SetOpType op, const IntVarArgs& x, SetVar y, SetVar z,
const IntSet& universe) {
GECODE_POST;
switch (op) {
case SOT_DUNION:
{
Set::Element::ElementDisjoint<SingletonView,SetView>::IdxViewArray
iv(home, x);
GECODE_ES_FAIL((Element::ElementDisjoint<SingletonView,SetView>
::post(home,iv,y)));
}
// fall through
case SOT_UNION:
{
Set::Element::ElementUnion<SingletonView,SetView,SetView>::IdxViewArray
iv(home, x);
GECODE_ES_FAIL(
(Element::ElementUnion<SingletonView,SetView,SetView>::
post(home,iv,y,z)));
}
break;
case SOT_INTER:
{
Set::Element::ElementIntersection<SingletonView,SetView,
SetView>::IdxViewArray iv(home, x);
GECODE_ES_FAIL(
(Element::ElementIntersection<SingletonView,SetView,
SetView>::post(home,iv,y,z,universe)));
}
break;
case SOT_MINUS:
throw IllegalOperation("Set::element");
break;
default:
throw UnknownOperation("Set::element");
}
}
void
element(Home home, SetOpType op, const IntSetArgs& x, SetVar y, SetVar z,
const IntSet& universe) {
GECODE_POST;
switch (op) {
case SOT_DUNION:
{
Set::Element::ElementDisjoint<ConstSetView,SetView>::IdxViewArray
iv(home, x.size());
for (int i=x.size(); i--;) {
iv[i].idx = i; iv[i].view = ConstSetView(home, x[i]);
}
GECODE_ES_FAIL((Element::ElementDisjoint<ConstSetView,SetView>::
post(home,iv,y)));
}
// fall through
case SOT_UNION:
{
GECODE_ES_FAIL(
(Element::ElementUnionConst<SetView,SetView>::
post(home,z,x,y)));
}
break;
case SOT_INTER:
{
Set::Element::ElementIntersection<ConstSetView,
SetView,SetView>::IdxViewArray iv(home, x.size());
for (int i=x.size(); i--;) {
iv[i].idx = i; iv[i].view = ConstSetView(home, x[i]);
}
GECODE_ES_FAIL(
(Element::ElementIntersection<ConstSetView,SetView,SetView>::
post(home,iv,y,z,universe)));
}
break;
case SOT_MINUS:
throw IllegalOperation("Set::element");
break;
default:
throw UnknownOperation("Set::element");
}
}
void
element(Home home, SetOpType op, const IntArgs& x, SetVar y, SetVar z,
const IntSet& universe) {
IntSetArgs xs(x.size());
for (int i=x.size(); i--;)
xs[i]=IntSet(x[i],x[i]);
element(home,op,xs,y,z,universe);
}
void
element(Home home, const SetVarArgs& x, IntVar y, SetVar z) {
if (x.size() == 0)
throw Set::TooFewArguments("Set::element");
GECODE_POST;
Set::Element::ElementUnion<SetView,SingletonView,SetView>::IdxViewArray
iv(home, x);
SetView zv(z);
Int::IntView yv(y);
SingletonView single(yv);
GECODE_ES_FAIL((Element::ElementUnion<SetView,SingletonView,SetView>
::post(home, iv, single,zv)));
}
void
element(Home home, const IntSetArgs& x, IntVar y, SetVar z) {
if (x.size() == 0)
throw Set::TooFewArguments("Set::element");
for (int i=x.size(); i--;)
Set::Limits::check(x[i], "Set::element");
GECODE_POST;
SetView zv(z);
Int::IntView yv(y);
SingletonView single(yv);
GECODE_ES_FAIL((Element::ElementUnionConst<SetView,
SingletonView>::post(home, z, x, single)));
}
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, const IntSetArgs& a,
IntVar x, int w, IntVar y, int h, SetVar z) {
if (a.size() == 0)
throw Set::TooFewArguments("Set::element");
if (a.size() != w*h)
throw Set::ArgumentSizeMismatch("Set::element");
GECODE_POST;
element(home, a, pair(home,x,w,y,h), z);
}
void
element(Home home, const SetVarArgs& a,
IntVar x, int w, IntVar y, int h, SetVar z) {
if (a.size() == 0)
throw Set::TooFewArguments("Set::element");
if (a.size() != w*h)
throw Set::ArgumentSizeMismatch("Set::element");
GECODE_POST;
element(home, a, pair(home,x,w,y,h), z);
}
}
// STATISTICS: set-post
Gecode::ArgArrayBase::size
int size(void) const
Return size of array (number of elements).
Definition array.hpp:1607
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::Home::fail
void fail(void)
Mark space as failed.
Definition core.hpp:4039
Gecode::IntArgs
Passing integer arguments.
Definition int.hh:628
Gecode::IntSet
Integer sets.
Definition int.hh:174
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::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::IdxViewArray
An array of IdxView pairs.
Definition idx-view.hh:67
Gecode::Int::IllegalOperation
Exception: Illegal operation passed as argument
Definition exception.hpp:101
Gecode::Int::IntView
Integer view for integer variables.
Definition view.hpp:129
Gecode::Int::TooFewArguments
Exception: Too few arguments available in argument array
Definition exception.hpp:66
Gecode::Int::UnknownOperation
Exception: Unknown operation passed as argument
Definition exception.hpp:94
Gecode::Int::ViewToVarArg< Gecode::Set::ConstSetView >::argtype
IntSetArgs argtype
Definition element.cpp:45
Gecode::Int::ViewToVarArg
Class to map VarArg type to view.
Definition idx-view.hh:60
Gecode::SetVarArgs
Passing set variables.
Definition set.hh:488
Gecode::SetVar
Set variables
Definition set.hh:127
Gecode::Set::ConstSetView
Constant view.
Definition view.hpp:186
Gecode::Set::Element::ElementDisjoint
Propagator for element with disjointness
Definition element.hh:194
Gecode::Set::Element::ElementDisjoint::IdxViewArray
Gecode::Int::IdxViewArray< SView > IdxViewArray
Definition element.hh:196
Gecode::Set::Element::ElementIntersection
Propagator for element with intersection
Definition element.hh:78
Gecode::Set::Element::ElementIntersection::IdxViewArray
Gecode::Int::IdxViewArray< View > IdxViewArray
Definition element.hh:80
Gecode::Set::Element::ElementUnionConst
Propagator for element with union of constant sets
Definition element.hh:157
Gecode::Set::Element::ElementUnion
Propagator for element with union
Definition element.hh:119
Gecode::Set::Element::ElementUnion::IdxViewArray
Gecode::Int::IdxViewArray< View > IdxViewArray
Definition element.hh:121
Gecode::Set::SetView
Set view for set variables
Definition view.hpp:56
Gecode::Set::SingletonView
Singleton set view.
Definition view.hpp:594
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::SetOpType
SetOpType
Common operations for sets.
Definition set.hh:660
Gecode::SOT_MINUS
@ SOT_MINUS
Difference.
Definition set.hh:664
Gecode::SOT_DUNION
@ SOT_DUNION
Disjoint union.
Definition set.hh:662
Gecode::SOT_UNION
@ SOT_UNION
Union.
Definition set.hh:661
Gecode::SOT_INTER
@ SOT_INTER
Intersection
Definition set.hh:663
Gecode::Int
Finite domain integers.
Gecode::Set::Limits::check
void check(int n, const char *l)
Check whether integer n is in range, otherwise throw overflow exception with information l.
Definition limits.hpp:37
Gecode::Set
Finite integer sets.
Definition var-imp.hpp:137
Gecode
Gecode toplevel namespace
Gecode::IntSetArgs
ArgArray< IntSet > IntSetArgs
Passing set arguments.
Definition int.hh:619
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
element.hh