view-eq.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, 2003
*
* 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.
*
*/
namespace Gecode { namespace Int { namespace Count {
template<class VX, class VY, class VZ, bool shr, bool dom>
forceinline
EqView<VX,VY,VZ,shr,dom>::EqView(Home home,
ViewArray<VX>& x, VY y, VZ z, int c)
: ViewBase<VX,VY,VZ>(home,x,y,z,c) {}
template<class VX, class VY, class VZ, bool shr, bool dom>
ExecStatus
EqView<VX,VY,VZ,shr,dom>::post(Home home,
ViewArray<VX>& x, VY y, VZ z, int c) {
GECODE_ME_CHECK(z.gq(home,-c));
GECODE_ME_CHECK(z.lq(home,x.size()-c));
if (isval(y) && z.assigned())
return EqInt<VX,VY>::post(home,x,y,z.val()+c);
if (sharing(x,y,z))
(void) new (home) EqView<VX,VY,VZ,true,dom>(home,x,y,z,c);
else
(void) new (home) EqView<VX,VY,VZ,false,dom>(home,x,y,z,c);
return ES_OK;
}
template<class VX, class VY, class VZ, bool shr, bool dom>
forceinline
EqView<VX,VY,VZ,shr,dom>::EqView(Space& home, EqView<VX,VY,VZ,shr,dom>& p)
: ViewBase<VX,VY,VZ>(home,p) {}
template<class VX, class VY, class VZ, bool shr, bool dom>
Actor*
EqView<VX,VY,VZ,shr,dom>::copy(Space& home) {
return new (home) EqView<VX,VY,VZ,shr,dom>(home,*this);
}
template<class VX, class VY, class VZ, bool shr, bool dom>
ExecStatus
EqView<VX,VY,VZ,shr,dom>::propagate(Space& home, const ModEventDelta&) {
count(home);
GECODE_ME_CHECK(z.gq(home,atleast()));
GECODE_ME_CHECK(z.lq(home,atmost()));
if (z.assigned()) {
if (z.val() == atleast()) {
GECODE_ES_CHECK(post_false(home,x,y));
return home.ES_SUBSUMED(*this);
}
if (z.val() == atmost()) {
GECODE_ES_CHECK(post_true(home,x,y));
return home.ES_SUBSUMED(*this);
}
if (!dom || isval(y)) {
VY yc(y);
GECODE_REWRITE(*this,(EqInt<VX,VY>
::post(home(*this),x,yc,z.val()+c)));
}
}
if (dom && !isval(y) && (z.min() > 0)) {
/*
* Only if the propagator is at fixpoint here, continue
* when things are shared: the reason is that prune
* requires that the views in x overlap with y!
*/
if (shr && (VX::me(Propagator::modeventdelta()) != ME_INT_NONE))
return ES_NOFIX;
GECODE_ES_CHECK(prune(home,x,y));
return ES_NOFIX;
}
return shr ? ES_NOFIX : ES_FIX;
}
}}}
// STATISTICS: int-prop
Gecode::Actor
Base-class for both propagators and branchers.
Definition core.hpp:628
Gecode::Home
Home class for posting propagators
Definition core.hpp:856
Gecode::Int::Count::EqInt
Propagator for counting views (equal integer to number of equal views)
Definition count.hh:172
Gecode::Int::Count::EqInt::post
static ExecStatus post(Home home, ViewArray< VX > &x, VY y, int c)
Post propagator for .
Definition int-eq.hpp:43
Gecode::Int::Count::EqView::post
static ExecStatus post(Home home, ViewArray< VX > &x, VY y, VZ z, int c)
Post propagator for .
Definition view-eq.hpp:44
Gecode::Int::Count::EqView::propagate
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition view-eq.hpp:70
Gecode::Int::Count::EqView::copy
virtual Actor * copy(Space &home)
Create copy during cloning.
Definition view-eq.hpp:64
Gecode::Int::Count::EqView::EqView
EqView(Space &home, EqView &p)
Constructor for cloning p.
Definition view-eq.hpp:59
Gecode::Int::Count::ViewBase::atleast
int atleast(void) const
How many views are at least equal.
Definition view-base.hpp:106
Gecode::Int::Count::ViewBase::x
ViewArray< VX > x
Views still to count.
Definition count.hh:269
Gecode::Int::Count::ViewBase::z
VZ z
View which yields result of counting.
Definition count.hh:273
Gecode::Int::Count::ViewBase::atmost
int atmost(void) const
How many views are at most equal.
Definition view-base.hpp:112
Gecode::Int::Count::ViewBase::c
int c
Number of views which are equal and have been eliminated.
Definition count.hh:275
Gecode::Int::Count::ViewBase::y
VY y
View to compare to.
Definition count.hh:271
Gecode::Int::Count::ViewBase::ViewBase
ViewBase(Space &home, ViewBase &p)
Constructor for cloning p.
Definition view-base.hpp:50
Gecode::Int::Count::ViewBase::sharing
static bool sharing(const ViewArray< VX > &x, const VY &y, const VZ &z)
Test whether there is sharing of z with x or y.
Definition view-base.hpp:123
Gecode::Propagator::Space
friend class Space
Definition core.hpp:1066
Gecode::Propagator::modeventdelta
ModEventDelta modeventdelta(void) const
Return the modification event delta.
Definition core.hpp:3520
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::Int::Count
Counting propagators.
Gecode::Int::Count::prune
ExecStatus prune(Home home, ViewArray< VX > &x, VX y)
Prune that y is the union of x.
Gecode::Int::Count::isval
bool isval(VY y)
Return whether y is a value.
Definition rel.hpp:59
Gecode::Int::Count::post_false
ExecStatus post_false(Home home, ViewArray< VX > &x, VX y)
Post that all views in x are not equal to y.
Definition rel.hpp:251
Gecode::Int::Count::post_true
ExecStatus post_true(Home home, ViewArray< VX > &x, VX y)
Post that all views in x are equal to y.
Definition rel.hpp:237
Gecode::Int
Finite domain integers.
Gecode::Int::ME_INT_NONE
const Gecode::ModEvent ME_INT_NONE
Domain operation has not changed domain.
Definition var-type.hpp:54
Gecode
Gecode toplevel namespace
Gecode::count
void count(Home home, const IntVarArgs &x, int n, IntRelType irt, int m, IntPropLevel ipl=IPL_DEF)
Post propagator for .
Definition count.cpp:40
Gecode::dom
void dom(Home home, FloatVar x, FloatVal n)
Propagates .
Definition dom.cpp:40
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
Gecode::ES_NOFIX
@ ES_NOFIX
Propagation has not computed fixpoint.
Definition core.hpp:475
forceinline
#define forceinline
Definition config.hpp:187