re-prop.hpp
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/rel.hh>
namespace Gecode { namespace Int { namespace Member {
template<class View, ReifyMode rm>
forceinline
ReProp<View,rm>::ReProp(Home home, ValSet& vs, ViewArray<View>& x, View y,
BoolView b0)
: Prop<View>(home,vs,x,y), b(b0) {
b.subscribe(home,*this,PC_BOOL_VAL);
}
template<class View, ReifyMode rm>
inline ExecStatus
ReProp<View,rm>::post(Home home, ViewArray<View>& x, View y, BoolView b) {
if (x.size() == 0) {
if (rm != RM_PMI)
GECODE_ME_CHECK(b.zero(home));
return ES_OK;
}
x.unique();
if (x.size() == 1)
return Rel::ReEqDom<View,BoolView,rm>::post(home,x[0],y,b);
if (x.same(y)) {
if (rm != RM_IMP)
GECODE_ME_CHECK(b.one(home));
return ES_OK;
}
// Eliminate assigned views and store them into the value set
ValSet vs;
add(home, vs, x);
switch (vs.compare(y)) {
case Iter::Ranges::CS_SUBSET:
if (rm != RM_IMP)
GECODE_ME_CHECK(b.one(home));
return ES_OK;
case Iter::Ranges::CS_DISJOINT:
if (x.size() == 0) {
if (rm != RM_PMI)
GECODE_ME_CHECK(b.zero(home));
return ES_OK;
}
break;
case Iter::Ranges::CS_NONE:
break;
default:
GECODE_NEVER;
}
(void) new (home) ReProp<View,rm>(home, vs, x, y, b);
return ES_OK;
}
template<class View, ReifyMode rm>
forceinline
ReProp<View,rm>::ReProp(Space& home, ReProp<View,rm>& p)
: Prop<View>(home, p) {
b.update(home, p.b);
}
template<class View, ReifyMode rm>
Propagator*
ReProp<View,rm>::copy(Space& home) {
return new (home) ReProp<View,rm>(home, *this);
}
template<class View, ReifyMode rm>
forceinline size_t
ReProp<View,rm>::dispose(Space& home) {
b.cancel(home, *this, PC_BOOL_VAL);
(void) Prop<View>::dispose(home);
return sizeof(*this);
}
template<class View, ReifyMode rm>
ExecStatus
ReProp<View,rm>::propagate(Space& home, const ModEventDelta& med) {
// Add assigned views to value set
if (View::me(med) == ME_INT_VAL)
add(home,vs,x);
if (b.one()) {
if (rm == RM_PMI)
return home.ES_SUBSUMED(*this);
ValSet vsc(vs);
vs.flush();
GECODE_REWRITE(*this,Prop<View>::post(home(*this),vsc,x,y));
}
if (b.zero()) {
if (rm != RM_IMP) {
ValSet::Ranges vsr(vs);
GECODE_ME_CHECK(y.minus_r(home,vsr,false));
for (int i=0; i<x.size(); i++)
GECODE_ES_CHECK((Rel::Nq<View,View>::post(Home(home),x[i],y)));
}
return home.ES_SUBSUMED(*this);
}
// Eliminate views from x
eliminate(home);
switch (vs.compare(y)) {
case Iter::Ranges::CS_SUBSET:
if (rm != RM_IMP)
GECODE_ME_CHECK(b.one(home));
return home.ES_SUBSUMED(*this);
case Iter::Ranges::CS_DISJOINT:
if (x.size() == 0) {
if (rm != RM_PMI)
GECODE_ME_CHECK(b.zero(home));
return home.ES_SUBSUMED(*this);
}
break;
case Iter::Ranges::CS_NONE:
break;
default:
GECODE_NEVER;
}
// Check whether y is in union of x and value set
if (x.size() > 0) {
Region r;
ValSet::Ranges vsr(vs);
ViewRanges<View> xsr(x[0]);
Iter::Ranges::NaryUnion u(r,vsr,xsr);
for (int i=1; i<x.size(); i++) {
ViewRanges<View> xir(x[i]);
u |= xir;
}
ViewRanges<View> yr(y);
if (Iter::Ranges::disjoint(u,yr)) {
if (rm != RM_PMI)
GECODE_ME_CHECK(b.zero(home));
return home.ES_SUBSUMED(*this);
}
}
return ES_FIX;
}
}}}
// STATISTICS: int-prop
Gecode::Home
Home class for posting propagators
Definition core.hpp:856
Gecode::Int::BoolView
Boolean view for Boolean variables.
Definition view.hpp:1380
Gecode::Int::Member::Prop::add
static void add(Space &home, ValSet &vs, ViewArray< View > &x)
Add values of assigned views in x to value set va.
Definition prop.hpp:46
Gecode::Int::Member::Prop::Prop
Prop(Home home, ValSet &vs, ViewArray< View > &x, View y)
Constructor for posting.
Definition prop.hpp:40
Gecode::Int::Member::Prop::vs
ValSet vs
Value set storing the values of already assigned views.
Definition member.hh:59
Gecode::Int::Member::Prop::eliminate
void eliminate(Space &home)
Eliminate views from x that are not equal to y or ar subsumed by vs.
Definition prop.hpp:58
Gecode::Int::Member::Prop::post
static ExecStatus post(Home home, ViewArray< View > &x, View y)
Post propagator for .
Definition prop.hpp:71
Gecode::Int::Member::Prop::dispose
virtual size_t dispose(Space &home)
Delete propagator and return its size.
Definition prop.hpp:119
Gecode::Int::Member::ReProp::copy
virtual Propagator * copy(Space &home)
Copy propagator during cloning.
Definition re-prop.hpp:101
Gecode::Int::Member::ReProp::ReProp
ReProp(Home home, ValSet &vs, ViewArray< View > &x, View y, BoolView b)
Constructor for posting.
Definition re-prop.hpp:40
Gecode::Int::Member::ReProp::propagate
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition re-prop.hpp:115
Gecode::Int::Member::ReProp::b
BoolView b
Boolean control variable.
Definition member.hh:98
Gecode::Int::Member::ReProp::dispose
virtual size_t dispose(Space &home)
Delete propagator and return its size.
Definition re-prop.hpp:107
Gecode::Int::Member::ReProp::post
static ExecStatus post(Home home, ViewArray< View > &x, View y, BoolView b)
Post propagator for .
Definition re-prop.hpp:48
Gecode::Int::Rel::Nq::post
static ExecStatus post(Home home, V0 x0, V1 x1)
Post propagator .
Definition nq.hpp:49
Gecode::Int::Rel::ReEqDom::post
static ExecStatus post(Home home, View x0, View x1, CtrlView b)
Post domain consistent propagator .
Definition eq.hpp:494
Gecode::Int::ValSet::Ranges
Iterator over ranges.
Definition val-set.hh:78
Gecode::Int::ValSet
Class for storing values of already assigned views.
Definition val-set.hh:44
Gecode::Int::ViewRanges
Range iterator for integer views.
Definition view.hpp:54
Gecode::Iter::Ranges::NaryUnion
Range iterator for union of iterators.
Definition ranges-union.hpp:74
Gecode::NaryOnePropagator< View, PC_INT_DOM >::x
ViewArray< View > x
Definition pattern.hpp:175
Gecode::NaryOnePropagator< View, PC_INT_DOM >::y
View y
Definition pattern.hpp:177
Gecode::Propagator
Base-class for propagators.
Definition core.hpp:1064
Gecode::Propagator::Space
friend class Space
Definition core.hpp:1066
Gecode::Propagator::med
ModEventDelta med
A set of modification events (used during propagation).
Definition core.hpp:1075
Gecode::Region
Handle to region.
Definition region.hpp:55
Gecode::View
Gecode::ViewArray
View arrays.
Definition array.hpp:253
Gecode::Space::ES_SUBSUMED
ExecStatus ES_SUBSUMED(Propagator &p)
Definition core.hpp:3563
Gecode::ModEventDelta
int ModEventDelta
Modification event deltas.
Definition core.hpp:89
GECODE_ME_CHECK
#define GECODE_ME_CHECK(me)
Check whether modification event me is failed, and forward failure.
Definition macros.hpp:52
GECODE_REWRITE
#define GECODE_REWRITE(prop, post)
Rewrite propagator by executing post function.
Definition macros.hpp:116
GECODE_ES_CHECK
#define GECODE_ES_CHECK(es)
Check whether execution status es is failed or subsumed, and forward failure or subsumption.
Definition macros.hpp:91
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
rel.hh
Gecode::Int::Member
Membership propagators.
Gecode::Int
Finite domain integers.
Gecode::Int::PC_BOOL_VAL
const Gecode::PropCond PC_BOOL_VAL
Propagate when a view becomes assigned (single value).
Definition var-type.hpp:126
Gecode::Int::ME_INT_VAL
const Gecode::ModEvent ME_INT_VAL
Domain operation has resulted in a value (assigned variable).
Definition var-type.hpp:56
Gecode::Iter::Ranges::CS_NONE
@ CS_NONE
Neither of the above.
Definition ranges-operations.hpp:63
Gecode::Iter::Ranges::CS_SUBSET
@ CS_SUBSET
First is subset of second iterator.
Definition ranges-operations.hpp:61
Gecode::Iter::Ranges::CS_DISJOINT
@ CS_DISJOINT
Intersection is empty.
Definition ranges-operations.hpp:62
Gecode::Iter::Ranges::disjoint
bool disjoint(I &i, J &j)
Check whether range iterators i and j are disjoint.
Definition ranges-operations.hpp:112
Gecode
Gecode toplevel namespace
Gecode::ExecStatus
ExecStatus
Definition core.hpp:472
Gecode::ES_OK
@ ES_OK
Execution is okay.
Definition core.hpp:476
Gecode::ES_FIX
@ ES_FIX
Propagation has computed fixpoint.
Definition core.hpp:477
forceinline
#define forceinline
Definition config.hpp:187
GECODE_NEVER
#define GECODE_NEVER
Assert that this command is never executed.
Definition macros.hpp:56