extensional-tuple-set.cpp
Go to the documentation of this file.
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
* Main authors:
* Linnea Ingmar <linnea.ingmar@hotmail.com>
* Mikael Lagerkvist <lagerkvist@gecode.org>
* Christian Schulte <schulte@gecode.org>
*
* Copyright:
* Linnea Ingmar, 2017
* Mikael Lagerkvist, 2007
* Christian Schulte, 2017
*
* 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/extensional.hh>
namespace Gecode {
void
extensional(Home home, const IntVarArgs& x, const TupleSet& t, bool pos,
IntPropLevel) {
using namespace Int;
if (!t.finalized())
throw NotYetFinalized("Int::extensional");
if (t.arity() != x.size())
throw ArgumentSizeMismatch("Int::extensional");
GECODE_POST;
ViewArray<IntView> xv(home,x);
if (pos)
GECODE_ES_FAIL((Extensional::postposcompact<IntView>(home,xv,t)));
else
GECODE_ES_FAIL((Extensional::postnegcompact<IntView>(home,xv,t)));
}
void
extensional(Home home, const IntVarArgs& x, const TupleSet& t, bool pos,
Reify r,
IntPropLevel) {
using namespace Int;
if (!t.finalized())
throw NotYetFinalized("Int::extensional");
if (t.arity() != x.size())
throw ArgumentSizeMismatch("Int::extensional");
GECODE_POST;
ViewArray<IntView> xv(home,x);
if (pos) {
switch (r.mode()) {
case RM_EQV:
GECODE_ES_FAIL((Extensional::postrecompact<IntView,BoolView,RM_EQV>
(home,xv,t,r.var())));
break;
case RM_IMP:
GECODE_ES_FAIL((Extensional::postrecompact<IntView,BoolView,RM_IMP>
(home,xv,t,r.var())));
break;
case RM_PMI:
GECODE_ES_FAIL((Extensional::postrecompact<IntView,BoolView,RM_PMI>
(home,xv,t,r.var())));
break;
default: throw UnknownReifyMode("Int::extensional");
}
} else {
NegBoolView n(r.var());
switch (r.mode()) {
case RM_EQV:
GECODE_ES_FAIL((Extensional::postrecompact<IntView,NegBoolView,RM_EQV>
(home,xv,t,n)));
break;
case RM_IMP:
GECODE_ES_FAIL((Extensional::postrecompact<IntView,NegBoolView,RM_PMI>
(home,xv,t,n)));
break;
case RM_PMI:
GECODE_ES_FAIL((Extensional::postrecompact<IntView,NegBoolView,RM_IMP>
(home,xv,t,n)));
break;
default: throw UnknownReifyMode("Int::extensional");
}
}
}
void
extensional(Home home, const BoolVarArgs& x, const TupleSet& t, bool pos,
IntPropLevel) {
using namespace Int;
if (!t.finalized())
throw NotYetFinalized("Int::extensional");
if (t.arity() != x.size())
throw ArgumentSizeMismatch("Int::extensional");
if ((t.min() < 0) || (t.max() > 1))
throw NotZeroOne("Int::extensional");
GECODE_POST;
ViewArray<BoolView> xv(home,x);
if (pos)
GECODE_ES_FAIL((Extensional::postposcompact<BoolView>(home,xv,t)));
else
GECODE_ES_FAIL((Extensional::postnegcompact<BoolView>(home,xv,t)));
}
void
extensional(Home home, const BoolVarArgs& x, const TupleSet& t, bool pos,
Reify r,
IntPropLevel) {
using namespace Int;
if (!t.finalized())
throw NotYetFinalized("Int::extensional");
if (t.arity() != x.size())
throw ArgumentSizeMismatch("Int::extensional");
if ((t.min() < 0) || (t.max() > 1))
throw NotZeroOne("Int::extensional");
GECODE_POST;
ViewArray<BoolView> xv(home,x);
if (pos) {
switch (r.mode()) {
case RM_EQV:
GECODE_ES_FAIL((Extensional::postrecompact<BoolView,BoolView,RM_EQV>
(home,xv,t,r.var())));
break;
case RM_IMP:
GECODE_ES_FAIL((Extensional::postrecompact<BoolView,BoolView,RM_IMP>
(home,xv,t,r.var())));
break;
case RM_PMI:
GECODE_ES_FAIL((Extensional::postrecompact<BoolView,BoolView,RM_PMI>
(home,xv,t,r.var())));
break;
default: throw UnknownReifyMode("Int::extensional");
}
} else {
NegBoolView n(r.var());
switch (r.mode()) {
case RM_EQV:
GECODE_ES_FAIL((Extensional::postrecompact<BoolView,NegBoolView,RM_EQV>
(home,xv,t,n)));
break;
case RM_IMP:
GECODE_ES_FAIL((Extensional::postrecompact<BoolView,NegBoolView,RM_PMI>
(home,xv,t,n)));
break;
case RM_PMI:
GECODE_ES_FAIL((Extensional::postrecompact<BoolView,NegBoolView,RM_IMP>
(home,xv,t,n)));
break;
default: throw UnknownReifyMode("Int::extensional");
}
}
}
}
// 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::Int::ArgumentSizeMismatch
Exception: Arguments are of different size
Definition exception.hpp:73
Gecode::Int::NegBoolView
Negated Boolean view.
Definition view.hpp:1574
Gecode::Int::NotYetFinalized
Exception: Tuple set not yet finalized
Definition exception.hpp:136
Gecode::Int::NotZeroOne
Exception: Not 0/1 integer
Definition exception.hpp:51
Gecode::Int::UnknownReifyMode
Exception: Unknown reification mode passed as argument
Definition exception.hpp:115
Gecode::Reify
Reification specification.
Definition int.hh:876
Gecode::TupleSet
Class represeting a set of tuples.
Definition int.hh:2191
Gecode::TupleSet::max
int max(void) const
Return maximal value in all tuples.
Definition tuple-set.hpp:197
Gecode::TupleSet::finalized
bool finalized(void) const
Is tuple set finalized.
Definition tuple-set.hpp:162
Gecode::TupleSet::min
int min(void) const
Return minimal value in all tuples.
Definition tuple-set.hpp:193
Gecode::TupleSet::arity
int arity(void) const
Arity of tuple set.
Definition tuple-set.hpp:181
Gecode::ViewArray
View arrays.
Definition array.hpp:253
extensional.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::extensional
void extensional(Home home, const IntVarArgs &x, DFA d, IntPropLevel ipl=IPL_DEF)
Post domain consistent propagator for extensional constraint described by a DFA.
Definition extensional-regular.cpp:39
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
Gecode::Int::Extensional::postnegcompact
ExecStatus postnegcompact(Home home, ViewArray< View > &x, const TupleSet &ts)
Post function for compact table propagator.
Definition compact.hpp:955
Gecode::Int::Extensional::postposcompact
ExecStatus postposcompact(Home home, ViewArray< View > &x, const TupleSet &ts)
Post function for positive compact table propagator.
Definition compact.hpp:685
Gecode::Int::Extensional::postrecompact
ExecStatus postrecompact(Home home, ViewArray< View > &x, const TupleSet &ts, CtrlView b)
Post function for compact table propagator.
Definition compact.hpp:1192
Gecode::Int
Finite domain integers.
Gecode
Gecode toplevel namespace