Generated on Thu Jan 16 2025 00:00:00 for Gecode by doxygen 1.14.0
ranges-compl.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 * Guido Tack <tack@gecode.org>
6 *
7 * Copyright:
8 * Guido Tack, 2004
9 * Christian Schulte, 2005
10 *
11 * This file is part of Gecode, the generic constraint
12 * development environment:
13 * http://www.gecode.org
14 *
15 * Permission is hereby granted, free of charge, to any person obtaining
16 * a copy of this software and associated documentation files (the
17 * "Software"), to deal in the Software without restriction, including
18 * without limitation the rights to use, copy, modify, merge, publish,
19 * distribute, sublicense, and/or sell copies of the Software, and to
20 * permit persons to whom the Software is furnished to do so, subject to
21 * the following conditions:
22 *
23 * The above copyright notice and this permission notice shall be
24 * included in all copies or substantial portions of the Software.
25 *
26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
30 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
31 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
32 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 *
34 */
35
36namespace Gecode { namespace Iter { namespace Ranges {
37
47
48 template<int UMIN, int UMAX, class I>
49 class Compl : public MinMax {
50 protected:
52 I i;
54 void start(void);
55 public:
57
58
59 Compl(void);
61 Compl(I& i);
63 void init(I& i);
65
67
68
69 void operator ++(void);
71 };
72
73
83
84 template<class I>
85 class ComplVal : public MinMax {
86 protected:
88 int UMIN, UMAX;
90 I i;
92 void start(void);
93 public:
95
96
97 ComplVal(void);
99 ComplVal(int umin, int umax, I& i);
101 void init(int umin, int umax, I& i);
103
105
106
107 void operator ++(void);
109 };
110
111
112 template<int UMIN, int UMAX, class I>
113 forceinline void
115 if (i()) {
116 assert((i.min() >= UMIN) && (i.max() <= UMAX));
117 if (i.min() > UMIN) {
118 mi = UMIN;
119 ma = i.min()-1;
120 } else if (i.max() < UMAX) {
121 mi = i.max()+1;
122 ++i;
123 ma = i() ? (i.min()-1) : UMAX;
124 } else {
125 finish();
126 }
127 } else {
128 mi = UMIN;
129 ma = UMAX;
130 }
131 }
132
133 template<int UMIN, int UMAX, class I>
136
137 template<int UMIN, int UMAX, class I>
140 start();
141 }
142
143 template<int UMIN, int UMAX, class I>
144 forceinline void
146 i=i0; start();
147 }
148
149 template<int UMIN, int UMAX, class I>
150 forceinline void
152 assert(!i() || (i.max() <= UMAX));
153 if (i() && (i.max() < UMAX)) {
154 mi = i.max()+1;
155 ++i;
156 ma = i() ? (i.min()-1) : UMAX;
157 } else {
158 finish();
159 }
160 }
161
162 template<class I>
163 forceinline void
165 if (i()) {
166 assert((i.min() >= UMIN) && (i.max() <= UMAX));
167 if (i.min() > UMIN) {
168 mi = UMIN;
169 ma = i.min()-1;
170 } else if (i.max() < UMAX) {
171 mi = i.max()+1;
172 ++i;
173 ma = i() ? (i.min()-1) : UMAX;
174 } else {
175 finish();
176 }
177 } else {
178 mi = UMIN;
179 ma = UMAX;
180 }
181 }
182
183 template<class I>
186
187 template<class I>
189 ComplVal<I>::ComplVal(int umin, int umax, I& i0)
190 : UMIN(umin), UMAX(umax), i(i0) {
191 start();
192 }
193
194 template<class I>
195 forceinline void
196 ComplVal<I>::init(int umin, int umax, I& i0) {
197 UMIN=umin; UMAX=umax; i=i0; start();
198 }
199
200 template<class I>
201 forceinline void
203 assert(!i() || (i.max() <= UMAX));
204 if (i() && (i.max() < UMAX)) {
205 mi = i.max()+1;
206 ++i;
207 ma = i() ? (i.min()-1) : UMAX;
208 } else {
209 finish();
210 }
211 }
212
213}}}
214
215// STATISTICS: iter-any
216
I i
Iterator to compute complement for.
void init(int umin, int umax, I &i)
Initialize with iterator i.
void start(void)
Initialize.
ComplVal(void)
Default constructor.
void operator++(void)
Move iterator to next range (if possible)
int UMIN
Values describing the universe set.
void start(void)
Initialize.
I i
Iterator to compute complement for.
void init(I &i)
Initialize with iterator i.
Compl(void)
Default constructor.
void operator++(void)
Move iterator to next range (if possible)
int ma
Maximum of current range.
int mi
Minimum of current range.
MinMax(void)
Default constructor.
void finish(void)
Set range such that iteration stops
Range iterators.
Definition iter.hh:43
Range and value iterators.
Definition iter.hh:41
Gecode toplevel namespace
#define forceinline
Definition config.hpp:194