count.hh
Go to the documentation of this file.
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
* Main authors:
* Christian Schulte <schulte@gecode.org>
* Guido Tack <tack@gecode.org>
*
* Copyright:
* Christian Schulte, 2002
* Guido Tack, 2004
*
* 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.
*
*/
#ifndef __GECODE_INT_COUNT_HH__
#define __GECODE_INT_COUNT_HH__
#include <gecode/int.hh>
namespace Gecode { namespace Int { namespace Count {
template<class VY>
bool isintset(VY y);
template<class VY>
bool isval(VY y);
template<class VY>
void subscribe(Space& home, Propagator& p, VY y);
template<class VY>
void cancel(Space& home, Propagator& p, VY y);
template<class VY>
void reschedule(Space& home, Propagator& p, VY y);
template<class VY>
void update(VY& y, Space& home, bool shared, VY py);
template<class VX>
RelTest holds(VX x, VX y);
template<class VX>
RelTest holds(VX x, ConstIntView y);
template<class VX>
RelTest holds(VX x, ZeroIntView y);
template<class VX>
RelTest holds(VX x, const IntSet& y);
template<class VX>
ExecStatus post_true(Home home, ViewArray<VX>& x, VX y);
template<class VX>
ExecStatus post_true(Home home, ViewArray<VX>& x, ConstIntView y);
template<class VX>
ExecStatus post_true(Home home, ViewArray<VX>& x, ZeroIntView y);
template<class VX>
ExecStatus post_true(Home home, ViewArray<VX>& x, const IntSet& y);
template<class VX>
ExecStatus post_false(Home home, ViewArray<VX>& x, VX y);
template<class VX>
ExecStatus post_false(Home home, ViewArray<VX>& x, ConstIntView y);
template<class VX>
ExecStatus post_false(Home home, ViewArray<VX>& x, ZeroIntView y);
template<class VX>
ExecStatus post_false(Home home, ViewArray<VX>& x, const IntSet& y);
template<class VX>
ExecStatus prune(Home home, ViewArray<VX>& x, VX y);
template<class VX>
ExecStatus prune(Home home, ViewArray<VX>& x, ConstIntView y);
template<class VX>
ExecStatus prune(Home home, ViewArray<VX>& x, ZeroIntView y);
template<class VX>
ExecStatus prune(Home home, ViewArray<VX>& x, const IntSet& y);
}}}
#include <gecode/int/count/rel.hpp>
namespace Gecode { namespace Int { namespace Count {
template<class VX, class VY>
class IntBase : public Propagator {
protected:
ViewArray<VX> x;
int n_s;
VY y;
int c;
IntBase(Space& home, IntBase& p);
IntBase(Home home, ViewArray<VX>& x, int n_s, VY y, int c);
public:
virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
virtual void reschedule(Space& home);
virtual size_t dispose(Space& home);
};
template<class VX, class VY>
class EqInt : public IntBase<VX,VY> {
protected:
using IntBase<VX,VY>::x;
using IntBase<VX,VY>::n_s;
using IntBase<VX,VY>::y;
using IntBase<VX,VY>::c;
EqInt(Space& home, EqInt& p);
EqInt(Home home, ViewArray<VX>& x, int n_s, VY y, int c);
public:
virtual Actor* copy(Space& home);
virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
static ExecStatus post(Home home, ViewArray<VX>& x, VY y, int c);
};
template<class VX, class VY>
class GqInt : public IntBase<VX,VY> {
protected:
using IntBase<VX,VY>::x;
using IntBase<VX,VY>::n_s;
using IntBase<VX,VY>::y;
using IntBase<VX,VY>::c;
GqInt(Space& home, GqInt& p);
GqInt(Home home, ViewArray<VX>& x, int n_s, VY y, int c);
public:
virtual Actor* copy(Space& home);
virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
static ExecStatus post(Home home, ViewArray<VX>& x, VY y, int c);
};
template<class VX, class VY>
class LqInt : public IntBase<VX,VY> {
protected:
using IntBase<VX,VY>::x;
using IntBase<VX,VY>::n_s;
using IntBase<VX,VY>::y;
using IntBase<VX,VY>::c;
LqInt(Space& home, LqInt& p);
LqInt(Home home, ViewArray<VX>& x, int n_s, VY y, int c);
public:
virtual Actor* copy(Space& home);
virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
static ExecStatus post(Home home, ViewArray<VX>& x, VY y, int c);
};
}}}
#include <gecode/int/count/int-base.hpp>
#include <gecode/int/count/int-eq.hpp>
#include <gecode/int/count/int-gq.hpp>
#include <gecode/int/count/int-lq.hpp>
namespace Gecode { namespace Int { namespace Count {
template<class VX, class VY, class VZ>
class ViewBase : public Propagator {
protected:
ViewArray<VX> x;
VY y;
VZ z;
int c;
ViewBase(Space& home, ViewBase& p);
ViewBase(Home home, ViewArray<VX>& x, VY y, VZ z, int c);
public:
virtual size_t dispose(Space& home);
virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
virtual void reschedule(Space& home);
protected:
void count(Space& home);
int atleast(void) const;
int atmost(void) const;
static bool sharing(const ViewArray<VX>& x, const VY& y, const VZ& z);
};
template<class VX, class VY, class VZ, bool shr, bool dom>
class EqView : public ViewBase<VX,VY,VZ> {
protected:
using ViewBase<VX,VY,VZ>::x;
using ViewBase<VX,VY,VZ>::z;
using ViewBase<VX,VY,VZ>::c;
using ViewBase<VX,VY,VZ>::y;
using ViewBase<VX,VY,VZ>::count;
using ViewBase<VX,VY,VZ>::atleast;
using ViewBase<VX,VY,VZ>::atmost;
using ViewBase<VX,VY,VZ>::sharing;
EqView(Space& home, EqView& p);
public:
EqView(Home home, ViewArray<VX>& x, VY y, VZ z, int c);
virtual Actor* copy(Space& home);
virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
static ExecStatus post(Home home, ViewArray<VX>& x, VY y, VZ z, int c);
};
template<class VX, class VY, class VZ, bool shr>
class LqView : public ViewBase<VX,VY,VZ> {
protected:
using ViewBase<VX,VY,VZ>::x;
using ViewBase<VX,VY,VZ>::z;
using ViewBase<VX,VY,VZ>::c;
using ViewBase<VX,VY,VZ>::y;
using ViewBase<VX,VY,VZ>::count;
using ViewBase<VX,VY,VZ>::atleast;
using ViewBase<VX,VY,VZ>::atmost;
using ViewBase<VX,VY,VZ>::sharing;
LqView(Space& home, LqView& p);
public:
LqView(Home home, ViewArray<VX>& x, VY y, VZ z, int c);
virtual Actor* copy(Space& home);
virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
static ExecStatus post(Home home, ViewArray<VX>& x, VY y, VZ z, int c);
};
template<class VX, class VY, class VZ, bool shr, bool dom>
class GqView : public ViewBase<VX,VY,VZ> {
protected:
using ViewBase<VX,VY,VZ>::x;
using ViewBase<VX,VY,VZ>::z;
using ViewBase<VX,VY,VZ>::c;
using ViewBase<VX,VY,VZ>::y;
using ViewBase<VX,VY,VZ>::count;
using ViewBase<VX,VY,VZ>::atleast;
using ViewBase<VX,VY,VZ>::atmost;
using ViewBase<VX,VY,VZ>::sharing;
GqView(Space& home, GqView& p);
public:
GqView(Home home, ViewArray<VX>& x, VY y, VZ z, int c);
virtual Actor* copy(Space& home);
virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
static ExecStatus post(Home home, ViewArray<VX>& x, VY y, VZ z, int c);
};
}}}
#include <gecode/int/count/view-base.hpp>
#include <gecode/int/count/view-eq.hpp>
#include <gecode/int/count/view-gq.hpp>
#include <gecode/int/count/view-lq.hpp>
#endif
// STATISTICS: int-prop
Gecode::ActorLink::Actor
friend class Actor
Definition core.hpp:590
Gecode::Home
Home class for posting propagators
Definition core.hpp:856
Gecode::IntSet
Integer sets.
Definition int.hh:174
Gecode::Int::ConstIntView
Constant integer view.
Definition view.hpp:851
Gecode::Int::Count::EqInt::propagate
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition int-eq.hpp:87
Gecode::Int::Count::EqInt::copy
virtual Actor * copy(Space &home)
Create copy during cloning.
Definition int-eq.hpp:81
Gecode::Int::Count::EqInt::EqInt
EqInt(Space &home, EqInt &p)
Constructor for cloning p.
Definition int-eq.hpp:76
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::GqInt::GqInt
GqInt(Space &home, GqInt &p)
Constructor for cloning p.
Definition int-gq.hpp:73
Gecode::Int::Count::GqInt::post
static ExecStatus post(Home home, ViewArray< VX > &x, VY y, int c)
Post propagator for .
Definition int-gq.hpp:43
Gecode::Int::Count::GqInt::propagate
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition int-gq.hpp:84
Gecode::Int::Count::GqInt::copy
virtual Actor * copy(Space &home)
Create copy during cloning.
Definition int-gq.hpp:78
Gecode::Int::Count::GqView::propagate
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition view-gq.hpp:68
Gecode::Int::Count::GqView::post
static ExecStatus post(Home home, ViewArray< VX > &x, VY y, VZ z, int c)
Post propagator for .
Definition view-gq.hpp:43
Gecode::Int::Count::GqView::copy
virtual Actor * copy(Space &home)
Create copy during cloning.
Definition view-gq.hpp:62
Gecode::Int::Count::GqView::GqView
GqView(Space &home, GqView &p)
Constructor for cloning p.
Definition view-gq.hpp:57
Gecode::Int::Count::IntBase::IntBase
IntBase(Space &home, IntBase &p)
Constructor for cloning p.
Definition int-base.hpp:62
Gecode::Int::Count::IntBase::n_s
int n_s
Views from x[0] ... x[n_s-1] have subscriptions.
Definition count.hh:143
Gecode::Int::Count::IntBase::x
ViewArray< VX > x
Views still to count.
Definition count.hh:141
Gecode::Int::Count::IntBase::cost
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function (defined as low linear).
Definition int-base.hpp:70
Gecode::Int::Count::IntBase::c
int c
Number of views which are equal and have been eliminated.
Definition count.hh:147
Gecode::Int::Count::IntBase::dispose
virtual size_t dispose(Space &home)
Delete propagator and return its size.
Definition int-base.hpp:50
Gecode::Int::Count::IntBase::y
VY y
View to compare to.
Definition count.hh:145
Gecode::Int::Count::IntBase::reschedule
virtual void reschedule(Space &home)
Schedule function.
Definition int-base.hpp:76
Gecode::Int::Count::LqInt::post
static ExecStatus post(Home home, ViewArray< VX > &x, VY y, int c)
Post propagator for .
Definition int-lq.hpp:43
Gecode::Int::Count::LqInt::LqInt
LqInt(Space &home, LqInt &p)
Constructor for cloning p.
Definition int-lq.hpp:71
Gecode::Int::Count::LqInt::copy
virtual Actor * copy(Space &home)
Create copy during cloning.
Definition int-lq.hpp:76
Gecode::Int::Count::LqInt::propagate
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition int-lq.hpp:82
Gecode::Int::Count::LqView::post
static ExecStatus post(Home home, ViewArray< VX > &x, VY y, VZ z, int c)
Post propagator for .
Definition view-lq.hpp:44
Gecode::Int::Count::LqView::copy
virtual Actor * copy(Space &home)
Create copy during cloning.
Definition view-lq.hpp:63
Gecode::Int::Count::LqView::LqView
LqView(Space &home, LqView &p)
Constructor for cloning p.
Definition view-lq.hpp:58
Gecode::Int::Count::LqView::propagate
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition view-lq.hpp:69
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::Int::ZeroIntView
Zero integer view.
Definition view.hpp:1014
Gecode::PropCost
Propagation cost.
Definition core.hpp:486
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::Propagator::Propagator
Propagator(Home home)
Constructor for posting.
Definition core.hpp:3498
Gecode::Space
Computation spaces.
Definition core.hpp:1742
Gecode::ViewArray
View arrays.
Definition array.hpp:253
int-base.hpp
int-eq.hpp
int-gq.hpp
int-lq.hpp
int.hh
Gecode::ModEventDelta
int ModEventDelta
Modification event deltas.
Definition core.hpp:89
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::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::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::RelTest
RelTest
Result of testing relation.
Definition view.hpp:1734
Gecode
Gecode toplevel namespace
Gecode::ExecStatus
ExecStatus
Definition core.hpp:472
rel.hpp
view-base.hpp
view-eq.hpp
view-gq.hpp
view-lq.hpp