Generated on Tue Feb 11 2025 17:33:26 for Gecode by doxygen 1.12.0
ranges-append.hpp
Go to the documentation of this file.
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2/*
3 * Main authors:
4 * Christian Schulte <schulte@gecode.org>
5 *
6 * Copyright:
7 * Christian Schulte, 2004
8 *
9 * This file is part of Gecode, the generic constraint
10 * development environment:
11 * http://www.gecode.org
12 *
13 * Permission is hereby granted, free of charge, to any person obtaining
14 * a copy of this software and associated documentation files (the
15 * "Software"), to deal in the Software without restriction, including
16 * without limitation the rights to use, copy, modify, merge, publish,
17 * distribute, sublicense, and/or sell copies of the Software, and to
18 * permit persons to whom the Software is furnished to do so, subject to
19 * the following conditions:
20 *
21 * The above copyright notice and this permission notice shall be
22 * included in all copies or substantial portions of the Software.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 *
32 */
33
34namespace Gecode { namespace Iter { namespace Ranges {
35
45 template<class I, class J>
46 class Append : public MinMax {
47 protected:
49 I i;
51 J j;
52 public:
54
55
56 Append(void);
58 Append(I& i, J& j);
60 void init(I& i, J& j);
62
64
65
66 void operator ++(void);
68 };
69
70
80 template<class I>
81 class NaryAppend : public MinMax {
82 protected:
84 I* r;
86 int n;
88 int active;
89 public:
91
92
93 NaryAppend(void);
95 NaryAppend(I* i, int n);
97 void init(I* i, int n);
99
101
102
103 void operator ++(void);
105 };
106
107
108 /*
109 * Binary Append
110 *
111 */
112
113 template<class I, class J>
114 inline void
116 if (i()) {
117 mi = i.min(); ma = i.max();
118 ++i;
119 if (!i() && j() && (j.min() == ma+1)) {
120 ma = j.max();
121 ++j;
122 }
123 } else if (j()) {
124 mi = j.min(); ma = j.max();
125 ++j;
126 } else {
127 finish();
128 }
129 }
130
131
132 template<class I, class J>
135
136 template<class I, class J>
139 : i(i0), j(j0) {
140 if (i() || j())
141 operator ++();
142 else
143 finish();
144 }
145
146 template<class I, class J>
147 forceinline void
148 Append<I,J>::init(I& i0, J& j0) {
149 i = i0; j = j0;
150 if (i() || j())
151 operator ++();
152 else
153 finish();
154 }
155
156
157 /*
158 * Nary Append
159 *
160 */
161
162 template<class I>
163 inline void
165 mi = r[active].min();
166 ma = r[active].max();
167 ++r[active];
168 while (!r[active]()) {
169 //Skip empty iterators:
170 do {
171 active++;
172 if (active >= n) {
173 finish(); return;
174 }
175 } while (!r[active]());
176 if (r[active].min() == ma+1){
177 ma = r[active].max();
178 ++r[active];
179 } else {
180 return;
181 }
182 }
183 }
184
185 template<class I>
188
189 template<class I>
190 inline
192 : r(r0), n(n0), active(0) {
193 while (active < n && !r[active]())
194 active++;
195 if (active < n){
196 operator ++();
197 } else {
198 finish();
199 }
200 }
201
202 template<class I>
203 inline void
204 NaryAppend<I>::init(I* r0, int n0) {
205 r = r0; n = n0; active = 0;
206 while (active < n && !r[active]())
207 active++;
208 if (active < n){
209 operator ++();
210 } else {
211 finish();
212 }
213 }
214
215}}}
216
217// STATISTICS: iter-any
218
int n
Number of negative literals for node type.
Range iterator for appending two range iterators
void init(I &i, J &j)
Initialize with iterator i and j.
void operator++(void)
Move iterator to next range (if possible)
Append(void)
Default constructor.
J j
Iterator to be appended.
Base for range iterators with explicit min and max.
void finish(void)
Set range such that iteration stops
Range iterator for appending arbitrarily many iterators.
void operator++(void)
Move iterator to next range (if possible)
NaryAppend(void)
Default constructor.
void init(I *i, int n)
Initialize with n iterators in i.
I * r
The array of iterators to be appended.
int active
Number of current iterator being processed.
Gecode toplevel namespace
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition set.hh:767
void min(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
#define forceinline
Definition config.hpp:187