nvalues.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, 2011
*
* 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/nvalues.hh>
#include <gecode/int/rel.hh>
namespace Gecode {
void
nvalues(Home home, const IntVarArgs& x, IntRelType irt, int y,
IntPropLevel) {
using namespace Int;
Limits::check(y,"Int::nvalues");
// Due to the quadratic Boolean matrix used in propagation
long long int n = x.size();
Limits::check(n*n,"Int::nvalues");
GECODE_POST;
ViewArray<IntView> xv(home,x);
switch (irt) {
case IRT_EQ:
{
ConstIntView yv(y);
GECODE_ES_FAIL(NValues::EqInt<ConstIntView>::post(home,xv,yv));
}
break;
case IRT_NQ:
{
IntVar z(home,0,x.size());
GECODE_ME_FAIL(IntView(z).nq(home,y));
GECODE_ES_FAIL(NValues::EqInt<IntView>::post(home,xv,z));
}
break;
case IRT_LE:
y--;
// Fall through
case IRT_LQ:
{
ConstIntView yv(y);
GECODE_ES_FAIL(NValues::LqInt<ConstIntView>::post(home,xv,yv));
}
break;
case IRT_GR:
y++;
// Fall through
case IRT_GQ:
{
ConstIntView yv(y);
GECODE_ES_FAIL(NValues::GqInt<ConstIntView>::post(home,xv,yv));
}
break;
default:
throw UnknownRelation("Int::nvalues");
}
}
void
nvalues(Home home, const IntVarArgs& x, IntRelType irt, IntVar y,
IntPropLevel) {
using namespace Int;
// Due to the quadratic Boolean matrix used in propagation
long long int n = x.size();
Limits::check(n*n,"Int::nvalues");
GECODE_POST;
if (y.assigned()) {
nvalues(home, x, irt, y.val());
return;
}
ViewArray<IntView> xv(home,x);
switch (irt) {
case IRT_EQ:
GECODE_ES_FAIL(NValues::EqInt<IntView>::post(home,xv,y));
break;
case IRT_NQ:
{
IntVar z(home,0,x.size());
GECODE_ES_FAIL((Rel::Nq<IntView,IntView>::post(home,y,z)));
GECODE_ES_FAIL(NValues::EqInt<IntView>::post(home,xv,z));
}
break;
case IRT_LE:
{
OffsetView z(y,-1);
GECODE_ES_FAIL(NValues::LqInt<OffsetView>::post(home,xv,z));
}
break;
case IRT_LQ:
GECODE_ES_FAIL(NValues::LqInt<IntView>::post(home,xv,y));
break;
case IRT_GR:
{
OffsetView z(y,1);
GECODE_ES_FAIL(NValues::GqInt<OffsetView>::post(home,xv,z));
}
break;
case IRT_GQ:
GECODE_ES_FAIL(NValues::GqInt<IntView>::post(home,xv,y));
break;
default:
throw UnknownRelation("Int::nvalues");
}
}
void
nvalues(Home home, const BoolVarArgs& x, IntRelType irt, int y,
IntPropLevel) {
using namespace Int;
Limits::check(y,"Int::nvalues");
GECODE_POST;
Region region;
ViewArray<BoolView> xv(region,x);
switch (irt) {
case IRT_EQ:
{
ConstIntView yv(y);
GECODE_ES_FAIL(NValues::EqBool<ConstIntView>::post(home,xv,yv));
}
break;
case IRT_NQ:
{
IntVar z(home,0,2);
GECODE_ME_FAIL(IntView(z).nq(home,y));
GECODE_ES_FAIL(NValues::EqBool<IntView>::post(home,xv,z));
}
break;
case IRT_LE:
y--;
// Fall through
case IRT_LQ:
{
ConstIntView yv(y);
GECODE_ES_FAIL(NValues::LqBool<ConstIntView>::post(home,xv,yv));
}
break;
case IRT_GR:
y++;
// Fall through
case IRT_GQ:
{
ConstIntView yv(y);
GECODE_ES_FAIL(NValues::GqBool<ConstIntView>::post(home,xv,yv));
}
break;
default:
throw UnknownRelation("Int::nvalues");
}
}
void
nvalues(Home home, const BoolVarArgs& x, IntRelType irt, IntVar y,
IntPropLevel) {
using namespace Int;
GECODE_POST;
if (y.assigned()) {
nvalues(home, x, irt, y.val());
return;
}
Region region;
ViewArray<BoolView> xv(region,x);
switch (irt) {
case IRT_EQ:
GECODE_ES_FAIL(NValues::EqBool<IntView>::post(home,xv,y));
break;
case IRT_NQ:
{
IntVar z(home,0,2);
GECODE_ES_FAIL((Rel::Nq<IntView,IntView>::post(home,y,z)));
GECODE_ES_FAIL(NValues::EqBool<IntView>::post(home,xv,z));
}
break;
case IRT_LE:
{
OffsetView z(y,-1);
GECODE_ES_FAIL(NValues::LqBool<OffsetView>::post(home,xv,z));
}
break;
case IRT_LQ:
GECODE_ES_FAIL(NValues::LqBool<IntView>::post(home,xv,y));
break;
case IRT_GR:
{
OffsetView z(y,1);
GECODE_ES_FAIL(NValues::GqBool<OffsetView>::post(home,xv,z));
}
break;
case IRT_GQ:
GECODE_ES_FAIL(NValues::GqBool<IntView>::post(home,xv,y));
break;
default:
throw UnknownRelation("Int::nvalues");
}
}
}
// 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::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::IntVar::val
int val(void) const
Return assigned value.
Definition int.hpp:56
Gecode::Int::ConstIntView
Constant integer view.
Definition view.hpp:851
Gecode::Int::IntView
Integer view for integer variables.
Definition view.hpp:129
Gecode::Int::NValues::EqBool::post
static ExecStatus post(Home home, ViewArray< BoolView > &x, VY y)
Post propagator for .
Definition bool-eq.hpp:57
Gecode::Int::NValues::EqInt::post
static ExecStatus post(Home home, ViewArray< IntView > &x, VY y)
Post propagator for .
Definition int-eq.hpp:48
Gecode::Int::NValues::GqBool::post
static ExecStatus post(Home home, ViewArray< BoolView > &x, VY y)
Post propagator for .
Definition bool-gq.hpp:56
Gecode::Int::NValues::GqInt::post
static ExecStatus post(Home home, ViewArray< IntView > &x, VY y)
Post propagator for .
Definition int-gq.hpp:46
Gecode::Int::NValues::LqBool::post
static ExecStatus post(Home home, ViewArray< BoolView > &x, VY y)
Post propagator for .
Definition bool-lq.hpp:56
Gecode::Int::NValues::LqInt::post
static ExecStatus post(Home home, ViewArray< IntView > &x, VY y)
Post propagator for .
Definition int-lq.hpp:48
Gecode::Int::OffsetView
Offset integer view.
Definition view.hpp:443
Gecode::Int::Rel::Nq::post
static ExecStatus post(Home home, V0 x0, V1 x1)
Post propagator .
Definition nq.hpp:49
Gecode::Int::UnknownRelation
Exception: Unknown relation passed as argument
Definition exception.hpp:87
Gecode::Region
Handle to region.
Definition region.hpp:55
Gecode::VarImpVar::assigned
bool assigned(void) const
Test whether view is assigned.
Definition var.hpp:111
Gecode::ViewArray
View arrays.
Definition array.hpp:253
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::IntRelType
IntRelType
Relation types for integers.
Definition int.hh:925
Gecode::IntPropLevel
IntPropLevel
Propagation levels for integer propagators.
Definition int.hh:974
Gecode::IRT_EQ
@ IRT_EQ
Equality ( ).
Definition int.hh:926
Gecode::IRT_NQ
@ IRT_NQ
Disequality ( ).
Definition int.hh:927
Gecode::IRT_GQ
@ IRT_GQ
Greater or equal ( ).
Definition int.hh:930
Gecode::IRT_LE
@ IRT_LE
Less ( ).
Definition int.hh:929
Gecode::IRT_GR
@ IRT_GR
Greater ( ).
Definition int.hh:931
Gecode::IRT_LQ
@ IRT_LQ
Less or equal ( ).
Definition int.hh:928
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::nvalues
void nvalues(Home home, const IntVarArgs &x, IntRelType irt, int y, IntPropLevel ipl=IPL_DEF)
Post propagator for .
Definition nvalues.cpp:40
nvalues.hh