3
* Christian Schulte <schulte@gecode.org>
6
* Christian Schulte, 2004
9
* $Date: 2005-07-29 21:55:06 +0200 (Fri, 29 Jul 2005) $ by $Author: schulte $
12
* This file is part of Gecode, the generic constraint
13
* development environment:
14
* http://www.gecode.org
16
* See the file "LICENSE" for information on usage and
17
* redistribution of this file, and for a
18
* DISCLAIMER OF ALL WARRANTIES.
22
#include "support/static-pqueue.hh"
24
namespace Gecode { namespace Iter { namespace Ranges {
27
* \brief Range iterator for computing union (binary)
29
* Requires \code #include "iter.hh" \endcode
30
* \ingroup FuncIterRanges
33
template <class I, class J>
34
class Union : public MinMax {
40
/// \name Constructors and initialization
42
/// Default constructor
44
/// Initialize with iterator \a i and \a j
46
/// Initialize with iterator \a i and \a j
47
void init(I& i, J& j);
50
/// \name Iteration control
52
/// Move iterator to next range (if possible)
53
void operator++(void);
59
* \brief Range iterator for union for any number of iterators
60
* \ingroup FuncIterRanges
64
class NaryUnion : public MinMax {
66
/// Order for iterators: by increasing minimum of next range
67
class RangeUnionOrder {
69
bool operator()(const I&, const I&) const;
71
/// Instance for order
72
RangeUnionOrder order;
73
/// Priority queue to give access to next range
74
Support::PQueue<I,RangeUnionOrder> r;
76
/// \name Constructors and initialization
78
/// Default constructor
80
/// Initialize with \a n iterators in \a i
81
NaryUnion(I* i, int n);
82
/// Initialize with \a n iterators in \a i
83
void init(I* i, int n);
86
/// \name Iteration control
88
/// Move iterator to next range (if possible)
89
void operator++(void);
100
template <class I, class J>
102
Union<I,J>::operator++(void) {
107
mi = j.min(); ma = j.max(); ++j; return;
110
mi = i.min(); ma = i.max(); ++i; return;
112
if (i.min() < j.min()) {
113
mi = i.min(); ma = i.max(); ++i;
115
mi = j.min(); ma = j.max(); ++j;
120
if (i() && (i.min() <= ma+1)) {
121
ma = std::max(ma,i.max()); ++i; goOn=true;
123
if (j() && (j.min() <= ma+1)) {
124
ma = std::max(ma,j.max()); ++j; goOn=true;
130
template <class I, class J>
132
Union<I,J>::Union(void) {}
134
template <class I, class J>
136
Union<I,J>::Union(I& i0, J& j0)
141
template <class I, class J>
143
Union<I,J>::init(I& i0, J& j0) {
157
NaryUnion<I>::RangeUnionOrder::operator()(const I& a, const I& b) const {
158
return a.min() > b.min();
163
NaryUnion<I>::operator++(void) {
170
if (ma < r.top().max())
180
} while (ma+1 >= r.top().min());
186
NaryUnion<I>::NaryUnion(void) {}
190
NaryUnion<I>::NaryUnion(I* r0, int n)
192
for (int i = n; i--; )
200
NaryUnion<I>::init(I* r0, int n) {
202
for (int i = n; i--; )
210
// STATISTICS: iter-any