element.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, 2004
* 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_ELEMENT_HH__
#define __GECODE_INT_ELEMENT_HH__
#include <gecode/int.hh>
#include <gecode/int/rel.hh>
#include <gecode/int/idx-view.hh>
namespace Gecode { namespace Int { namespace Element {
template<class V0, class V1, class Idx, class Val>
class Int : public Propagator {
protected:
class IdxVal {
public:
Idx idx_next;
Idx val_next;
Idx idx;
Val val;
void mark(void);
bool marked(void) const;
};
class IterIdxUnmark {
private:
IdxVal* iv;
Idx i;
public:
IterIdxUnmark(IdxVal* iv);
bool operator ()(void) const;
void operator ++(void);
Idx val(void) const;
};
class IterVal {
private:
IdxVal* iv;
Idx i;
public:
IterVal(IdxVal* iv);
bool operator ()(void) const;
void operator ++(void);
Val val(void) const;
};
class IterValUnmark {
private:
IdxVal* iv;
Idx i;
public:
IterValUnmark(IdxVal* iv);
bool operator ()(void) const;
void operator ++(void);
Val val(void) const;
};
class ByVal {
protected:
const IdxVal* iv;
public:
ByVal(const IdxVal* iv);
bool operator ()(Idx& i, Idx& j);
};
V0 x0;
typedef typename Gecode::Support::IntTypeTraits<Idx>::utype IdxSize;
IdxSize s0;
V1 x1;
typedef typename Gecode::Support::IntTypeTraits<Val>::utype ValSize;
ValSize s1;
IntSharedArray c;
IdxVal* iv;
void prune_idx(void);
void prune_val(void);
static ExecStatus assigned_val(Space& home, IntSharedArray& c,
V0 x0, V1 x1);
Int(Space& home, Int& p);
Int(Home home, IntSharedArray& i, V0 x0, V1 x1);
public:
virtual Actor* copy(Space& home);
virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
virtual void reschedule(Space& home);
virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
static ExecStatus post(Home home, IntSharedArray& i, V0 x0, V1 x1);
virtual size_t dispose(Space& home);
};
template<class V0, class V1>
ExecStatus post_int(Home home, IntSharedArray& c, V0 x0, V1 x1);
template<class VA, class VB, class VC, PropCond pc_ac>
class View : public Propagator {
protected:
IdxViewArray<VA> iv;
VB x0;
VC x1;
View(Space& home, View& p);
View(Home home, IdxViewArray<VA>& iv, VB x0, VC x1);
public:
// Cost function (defined as low linear)
virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
virtual void reschedule(Space& home);
virtual size_t dispose(Space& home);
};
template<class VA, class VB, class VC>
class ViewBnd : public View<VA,VB,VC,PC_INT_BND> {
protected:
using View<VA,VB,VC,PC_INT_BND>::iv;
using View<VA,VB,VC,PC_INT_BND>::x0;
using View<VA,VB,VC,PC_INT_BND>::x1;
ViewBnd(Space& home, ViewBnd& p);
ViewBnd(Home home, IdxViewArray<VA>& iv, VB x0, VC x1);
public:
virtual Actor* copy(Space& home);
virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
static ExecStatus post(Home home, IdxViewArray<VA>& iv, VB x0, VC x1);
};
template<class VA, class VB, class VC>
class ViewDom : public View<VA,VB,VC,PC_INT_DOM> {
protected:
using View<VA,VB,VC,PC_INT_DOM>::iv;
using View<VA,VB,VC,PC_INT_DOM>::x0;
using View<VA,VB,VC,PC_INT_DOM>::x1;
ViewDom(Space& home, ViewDom& p);
ViewDom(Home home, IdxViewArray<VA>& iv, VB x0, VC x1);
public:
virtual Actor* copy(Space& home);
virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
static ExecStatus post(Home home, IdxViewArray<VA>& iv,
VB x0, VC x1);
};
class GECODE_VTABLE_EXPORT Pair
: public TernaryPropagator<IntView,PC_INT_DOM> {
protected:
using TernaryPropagator<IntView,PC_INT_DOM>::x0;
using TernaryPropagator<IntView,PC_INT_DOM>::x1;
using TernaryPropagator<IntView,PC_INT_DOM>::x2;
int w;
Pair(Space& home, Pair& p);
public:
Pair(Home home, IntView x0, IntView x1, IntView x2, int w);
static ExecStatus post(Home home, IntView x0, IntView x1, IntView x2,
int w, int h);
GECODE_INT_EXPORT virtual Actor* copy(Space& home);
GECODE_INT_EXPORT virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
};
}}}
#include <gecode/int/element/int.hpp>
#include <gecode/int/element/view.hpp>
#include <gecode/int/element/pair.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::Int::Element::Int::ByVal::operator()
bool operator()(Idx &i, Idx &j)
Compare pairs at positions i and j.
Definition int.hpp:147
Gecode::Int::Element::Int::ByVal::iv
const IdxVal * iv
Index-value pairs.
Definition element.hh:143
Gecode::Int::Element::Int::ByVal::ByVal
ByVal(const IdxVal *iv)
Initialize with index value pairs.
Definition int.hpp:143
Gecode::Int::Element::Int::IdxVal
Linked index-value pairs.
Definition element.hh:67
Gecode::Int::Element::Int::IdxVal::idx
Idx idx
The index.
Definition element.hh:71
Gecode::Int::Element::Int::IdxVal::val_next
Idx val_next
The position of the next pair in value order.
Definition element.hh:70
Gecode::Int::Element::Int::IdxVal::mark
void mark(void)
Definition int.hpp:40
Gecode::Int::Element::Int::IdxVal::val
Val val
The value Mark that this pair should be removed.
Definition element.hh:72
Gecode::Int::Element::Int::IdxVal::marked
bool marked(void) const
Return whether this pair is marked for removal.
Definition int.hpp:45
Gecode::Int::Element::Int::IdxVal::idx_next
Idx idx_next
The position of the next pair in index order.
Definition element.hh:69
Gecode::Int::Element::Int::IterIdxUnmark::val
Idx val(void) const
Return index of current index value pair.
Definition int.hpp:77
Gecode::Int::Element::Int::IterIdxUnmark::operator++
void operator++(void)
Move to next index value pair (next index).
Definition int.hpp:68
Gecode::Int::Element::Int::IterIdxUnmark::IterIdxUnmark
IterIdxUnmark(IdxVal *iv)
Initialize with start.
Definition int.hpp:53
Gecode::Int::Element::Int::IterIdxUnmark::operator()
bool operator()(void) const
Test whether more pairs to be iterated.
Definition int.hpp:63
Gecode::Int::Element::Int::IterValUnmark::operator++
void operator++(void)
Move to next index value pair (next value).
Definition int.hpp:124
Gecode::Int::Element::Int::IterValUnmark::operator()
bool operator()(void) const
Test whether more pairs to be iterated.
Definition int.hpp:119
Gecode::Int::Element::Int::IterValUnmark::val
Val val(void) const
Return value of current index value pair.
Definition int.hpp:133
Gecode::Int::Element::Int::IterValUnmark::IterValUnmark
IterValUnmark(IdxVal *iv)
Initialize with start.
Definition int.hpp:109
Gecode::Int::Element::Int::IterVal::operator()
bool operator()(void) const
Test whether more pairs to be iterated.
Definition int.hpp:90
Gecode::Int::Element::Int::IterVal::IterVal
IterVal(IdxVal *iv)
Initialize with start.
Definition int.hpp:86
Gecode::Int::Element::Int::IterVal::val
Val val(void) const
Return value of current index value pair.
Definition int.hpp:100
Gecode::Int::Element::Int::IterVal::operator++
void operator++(void)
Move to next index value pair (next value).
Definition int.hpp:95
Gecode::Int::Element::Int
Element propagator for array of integers
Definition element.hh:57
Gecode::Int::Element::Int::Int
Int(Space &home, Int &p)
Constructor for cloning p.
Definition int.hpp:191
Gecode::Int::Element::Int::s1
ValSize s1
Size of x1 at last execution.
Definition element.hh:162
Gecode::Int::Element::Int::prune_val
void prune_val(void)
Prune values according to x1.
Definition int.hpp:244
Gecode::Int::Element::Int::c
IntSharedArray c
Shared array of integer values.
Definition element.hh:164
Gecode::Int::Element::Int::x1
V1 x1
View for result.
Definition element.hh:158
Gecode::Int::Element::Int::post
static ExecStatus post(Home home, IntSharedArray &i, V0 x0, V1 x1)
Post propagator for .
Definition int.hpp:178
Gecode::Int::Element::Int::copy
virtual Actor * copy(Space &home)
Perform copying during cloning.
Definition int.hpp:199
Gecode::Int::Element::Int::reschedule
virtual void reschedule(Space &home)
Schedule function.
Definition int.hpp:215
Gecode::Int::Element::Int::assigned_val
static ExecStatus assigned_val(Space &home, IntSharedArray &c, V0 x0, V1 x1)
Prune when x1 is assigned.
Definition int.hpp:267
Gecode::Int::Element::Int::s0
IdxSize s0
Size of x0 at last execution.
Definition element.hh:156
Gecode::Int::Element::Int::propagate
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition int.hpp:282
Gecode::Int::Element::Int::iv
IdxVal * iv
The index-value data structure.
Definition element.hh:166
Gecode::Int::Element::Int::IdxSize
Gecode::Support::IntTypeTraits< Idx >::utype IdxSize
Type for index size.
Definition element.hh:154
Gecode::Int::Element::Int::ValSize
Gecode::Support::IntTypeTraits< Val >::utype ValSize
Type for value size.
Definition element.hh:160
Gecode::Int::Element::Int::x0
V0 x0
View for index.
Definition element.hh:152
Gecode::Int::Element::Int::cost
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function (defined as high binary).
Definition int.hpp:205
Gecode::Int::Element::Int::prune_idx
void prune_idx(void)
Prune index according to x0.
Definition int.hpp:222
Gecode::Int::Element::Int::dispose
virtual size_t dispose(Space &home)
Delete propagator and return its size.
Definition int.hpp:167
Gecode::Int::Element::Pair::Pair
Pair(Space &home, Pair &p)
Constructor for cloning p.
Definition pair.hpp:64
Gecode::Int::Element::Pair::propagate
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition pair.cpp:97
Gecode::Int::Element::Pair::w
int w
Width.
Definition element.hh:304
Gecode::Int::Element::Pair::post
static ExecStatus post(Home home, IntView x0, IntView x1, IntView x2, int w, int h)
Post propagator .
Definition pair.hpp:43
Gecode::Int::Element::Pair::copy
virtual Actor * copy(Space &home)
Copy propagator during cloning.
Definition pair.cpp:39
Gecode::Int::Element::ViewBnd::ViewBnd
ViewBnd(Space &home, ViewBnd &p)
Constructor for cloning p.
Definition view.hpp:301
Gecode::Int::Element::ViewBnd::copy
virtual Actor * copy(Space &home)
Perform copying during cloning.
Definition view.hpp:306
Gecode::Int::Element::ViewBnd::propagate
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition view.hpp:312
Gecode::Int::Element::ViewBnd::post
static ExecStatus post(Home home, IdxViewArray< VA > &iv, VB x0, VC x1)
Post propagator for .
Definition view.hpp:284
Gecode::Int::Element::ViewDom::copy
virtual Actor * copy(Space &home)
Perform copying during cloning.
Definition view.hpp:388
Gecode::Int::Element::ViewDom::propagate
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition view.hpp:402
Gecode::Int::Element::ViewDom::cost
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function.
Definition view.hpp:395
Gecode::Int::Element::ViewDom::post
static ExecStatus post(Home home, IdxViewArray< VA > &iv, VB x0, VC x1)
Post propagator for .
Definition view.hpp:366
Gecode::Int::Element::ViewDom::ViewDom
ViewDom(Space &home, ViewDom &p)
Constructor for cloning p.
Definition view.hpp:383
Gecode::Int::Element::View::iv
IdxViewArray< VA > iv
Current index-view map.
Definition element.hh:206
Gecode::Int::Element::View::cost
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function.
Definition view.hpp:131
Gecode::Int::Element::View::reschedule
virtual void reschedule(Space &home)
Schedule function.
Definition view.hpp:140
Gecode::Int::Element::View::View
View(Space &home, View &p)
Constructor for cloning p.
Definition view.hpp:122
Gecode::Int::Element::View::dispose
virtual size_t dispose(Space &home)
Delete propagator and return its size.
Definition view.hpp:148
Gecode::Int::Element::View::x1
VC x1
View for result.
Definition element.hh:210
Gecode::Int::Element::View::x0
VB x0
View for index.
Definition element.hh:208
Gecode::Int::IdxViewArray
An array of IdxView pairs.
Definition idx-view.hh:67
Gecode::Int::IntView
Integer view for integer variables.
Definition view.hpp:129
Gecode::PropCost
Propagation cost.
Definition core.hpp:486
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::Support::IntTypeTraits
Traits to for information about integer types.
Definition int-type.hpp:52
Gecode::TernaryPropagator< IntView, PC_INT_DOM >::x2
IntView x2
Definition pattern.hpp:116
Gecode::TernaryPropagator< IntView, PC_INT_DOM >::x1
IntView x1
Definition pattern.hpp:116
Gecode::TernaryPropagator< IntView, PC_INT_DOM >::x0
IntView x0
Definition pattern.hpp:116
Gecode::TernaryPropagator< IntView, PC_INT_DOM >::TernaryPropagator
TernaryPropagator(Space &home, TernaryPropagator &p)
Gecode::Val
int.hpp
int.hh
GECODE_INT_EXPORT
#define GECODE_INT_EXPORT
Definition int.hh:81
Gecode::ModEventDelta
int ModEventDelta
Modification event deltas.
Definition core.hpp:89
idx-view.hh
view.hpp
rel.hh
Gecode::Int::Element
Element propagators
Gecode::Int::Element::post_int
ExecStatus post_int(Home home, IntSharedArray &c, V0 x0, V1 x1)
Post propagator with apropriate index and value types.
Definition int.hpp:405
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
Gecode toplevel namespace
Gecode::IntSharedArray
SharedArray< int > IntSharedArray
Arrays of integers that can be shared among several element constraints.
Definition int.hh:1477
Gecode::ExecStatus
ExecStatus
Definition core.hpp:472
pair.hpp
GECODE_VTABLE_EXPORT
#define GECODE_VTABLE_EXPORT
Definition support.hh:72