view-base.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>
forceinline
ViewBase<VX,VY,VZ>::ViewBase(Home home,
ViewArray<VX>& x0, VY y0, VZ z0, int c0)
: Propagator(home), x(x0), y(y0), z(z0), c(c0) {
if (isintset(y))
home.notice(*this,AP_DISPOSE);
x.subscribe(home,*this,PC_INT_DOM);
subscribe(home,*this,y);
z.subscribe(home,*this,PC_INT_BND);
}
template<class VX, class VY, class VZ>
forceinline
ViewBase<VX,VY,VZ>::ViewBase(Space& home, ViewBase<VX,VY,VZ>& p)
: Propagator(home,p), c(p.c) {
x.update(home,p.x);
update(y,home,p.y);
z.update(home,p.z);
}
template<class VX, class VY, class VZ>
PropCost
ViewBase<VX,VY,VZ>::cost(const Space&, const ModEventDelta&) const {
return PropCost::linear(PropCost::LO,x.size()+1);
}
template<class VX, class VY, class VZ>
void
ViewBase<VX,VY,VZ>::reschedule(Space& home) {
x.reschedule(home,*this,PC_INT_DOM);
Gecode::Int::Count::reschedule(home,*this,y);
z.reschedule(home,*this,PC_INT_BND);
}
template<class VX, class VY, class VZ>
forceinline size_t
ViewBase<VX,VY,VZ>::dispose(Space& home) {
if (isintset(y))
home.ignore(*this,AP_DISPOSE);
x.cancel(home,*this,PC_INT_DOM);
cancel(home,*this,y);
z.cancel(home,*this,PC_INT_BND);
(void) Propagator::dispose(home);
return sizeof(*this);
}
template<class VX, class VY, class VZ>
forceinline void
ViewBase<VX,VY,VZ>::count(Space& home) {
int n = x.size();
for (int i=n; i--; )
switch (holds(x[i],y)) {
case RT_FALSE:
x[i].cancel(home,*this,PC_INT_DOM); x[i]=x[--n];
break;
case RT_TRUE:
x[i].cancel(home,*this,PC_INT_DOM); x[i]=x[--n];
c--;
break;
case RT_MAYBE:
break;
default:
GECODE_NEVER;
}
x.size(n);
}
template<class VX, class VY, class VZ>
forceinline int
ViewBase<VX,VY,VZ>::atleast(void) const {
return -c;
}
template<class VX, class VY, class VZ>
forceinline int
ViewBase<VX,VY,VZ>::atmost(void) const {
return x.size()-c;
}
template<class VX>
forceinline bool
shared(const IntSet&, VX) {
return false;
}
template<class VX, class VY, class VZ>
forceinline bool
ViewBase<VX,VY,VZ>::sharing(const ViewArray<VX>& x,
const VY& y, const VZ& z) {
if (shared(y,z))
return true;
for (int i=0; i<x.size(); i++)
if (shared(x[i],z))
return true;
return false;
}
}}}
// STATISTICS: int-prop
Gecode::Actor::dispose
virtual size_t dispose(Space &home)
Delete actor and return its size.
Definition core.hpp:3252
Gecode::Home
Home class for posting propagators
Definition core.hpp:856
Gecode::Home::notice
void notice(Actor &a, ActorProperty p, bool duplicate=false)
Notice actor property.
Definition core.hpp:3219
Gecode::IntSet
Integer sets.
Definition int.hh:174
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::count
void count(Space &home)
Count how many views are equal now.
Definition view-base.hpp:85
Gecode::Int::Count::ViewBase::reschedule
virtual void reschedule(Space &home)
Schedule function.
Definition view-base.hpp:65
Gecode::Int::Count::ViewBase::z
VZ z
View which yields result of counting.
Definition count.hh:273
Gecode::Int::Count::ViewBase::dispose
virtual size_t dispose(Space &home)
Delete propagator and return its size.
Definition view-base.hpp:73
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::cost
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function (defined as low linear).
Definition view-base.hpp:59
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::PropCost
Propagation cost.
Definition core.hpp:486
Gecode::PropCost::linear
static PropCost linear(PropCost::Mod m, unsigned int n)
Linear complexity for modifier pcm and size measure n.
Definition core.hpp:4796
Gecode::PropCost::LO
@ LO
Cheap.
Definition core.hpp:513
Gecode::Propagator::Space
friend class Space
Definition core.hpp:1066
Gecode::Propagator::Propagator
Propagator(Home home)
Constructor for posting.
Definition core.hpp:3498
Gecode::ViewArray
View arrays.
Definition array.hpp:253
Gecode::Space::ignore
void ignore(Actor &a, ActorProperty p, bool duplicate=false)
Ignore actor property.
Definition core.hpp:4074
Gecode::ModEventDelta
int ModEventDelta
Modification event deltas.
Definition core.hpp:89
Gecode::AP_DISPOSE
@ AP_DISPOSE
Actor must always be disposed.
Definition core.hpp:562
Gecode::Int::Count
Counting propagators.
Gecode::Int::Count::cancel
void cancel(Space &home, Propagator &p, VY y)
Cancel propagator p for view y.
Definition rel.hpp:87
Gecode::Int::Count::update
void update(VY &y, Space &home, bool shared, VY py)
Update view y from py.
Gecode::Int::Count::isintset
bool isintset(VY y)
Return whether y is an integer set.
Definition rel.hpp:45
Gecode::Int::Count::subscribe
void subscribe(Space &home, Propagator &p, VY y)
Subscribe propagator p to view y.
Definition rel.hpp:76
Gecode::Int::Count::reschedule
void reschedule(Space &home, Propagator &p, VY y)
Schedule propagator p for view y.
Definition rel.hpp:97
Gecode::Int::Count::shared
bool shared(const IntSet &, VX)
Definition view-base.hpp:118
Gecode::Int::Count::holds
RelTest holds(VX x, VX y)
Test whether x and y are equal.
Definition rel.hpp:145
Gecode::Int
Finite domain integers.
Gecode::Int::PC_INT_BND
const Gecode::PropCond PC_INT_BND
Propagate when minimum or maximum of a view changes.
Definition var-type.hpp:91
Gecode::Int::PC_INT_DOM
const Gecode::PropCond PC_INT_DOM
Propagate when domain changes.
Definition var-type.hpp:100
Gecode::Int::RT_TRUE
@ RT_TRUE
Relation does hold.
Definition view.hpp:1737
Gecode::Int::RT_MAYBE
@ RT_MAYBE
Relation may hold or not.
Definition view.hpp:1736
Gecode::Int::RT_FALSE
@ RT_FALSE
Relation does not hold.
Definition view.hpp:1735
Gecode
Gecode toplevel namespace
forceinline
#define forceinline
Definition config.hpp:187
GECODE_NEVER
#define GECODE_NEVER
Assert that this command is never executed.
Definition macros.hpp:56