main page
modules
namespaces
classes
files
Gecode home
Generated on Thu Mar 7 2013 10:21:36 for Gecode by
doxygen
1.8.3.1
gecode
iter
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
* Last modified:
12
* $Date: 2010-07-29 01:35:33 +1000 (Thu, 29 Jul 2010) $ by $Author: schulte $
13
* $Revision: 11294 $
14
*
15
* This file is part of Gecode, the generic constraint
16
* development environment:
17
* http://www.gecode.org
18
*
19
* Permission is hereby granted, free of charge, to any person obtaining
20
* a copy of this software and associated documentation files (the
21
* "Software"), to deal in the Software without restriction, including
22
* without limitation the rights to use, copy, modify, merge, publish,
23
* distribute, sublicense, and/or sell copies of the Software, and to
24
* permit persons to whom the Software is furnished to do so, subject to
25
* the following conditions:
26
*
27
* The above copyright notice and this permission notice shall be
28
* included in all copies or substantial portions of the Software.
29
*
30
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
31
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
32
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
33
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
34
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
35
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
36
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37
*
38
*/
39
40
namespace
Gecode {
namespace
Iter {
namespace
Ranges {
41
52
template
<
int
UMIN,
int
UMAX,
class
I>
53
class
Compl
:
public
MinMax
{
54
protected
:
56
I
i
;
58
void
start
(
void
);
59
public
:
61
62
63
Compl
(
void
);
65
Compl
(I&
i
);
67
void
init
(I&
i
);
69
71
72
73
void
operator ++
(
void
);
75
};
76
77
88
template
<
class
I>
89
class
ComplVal
:
public
MinMax
{
90
protected
:
92
int
UMIN
,
UMAX
;
94
I
i
;
96
void
start
(
void
);
97
public
:
99
100
101
ComplVal
(
void
);
103
ComplVal
(
int
umin,
int
umax, I&
i
);
105
void
init
(
int
umin,
int
umax, I&
i
);
107
109
110
111
void
operator ++
(
void
);
113
};
114
115
116
template
<
int
UMIN,
int
UMAX,
class
I>
117
forceinline
void
118
Compl<UMIN,UMAX,I>::start
(
void
) {
119
if
(
i
()) {
120
assert((
i
.min() >= UMIN) && (
i
.max() <= UMAX));
121
if
(
i
.min() > UMIN) {
122
mi = UMIN;
123
ma =
i
.min()-1;
124
}
else
if
(
i
.max() < UMAX) {
125
mi =
i
.max()+1;
126
++
i
;
127
ma =
i
() ? (
i
.min()-1) : UMAX;
128
}
else
{
129
finish();
130
}
131
}
else
{
132
mi = UMIN;
133
ma = UMAX;
134
}
135
}
136
137
template
<
int
UMIN,
int
UMAX,
class
I>
138
forceinline
139
Compl<UMIN,UMAX,I>::Compl
(
void
) {}
140
141
template
<
int
UMIN,
int
UMAX,
class
I>
142
forceinline
143
Compl<UMIN,UMAX,I>::Compl
(I& i0) :
i
(i0) {
144
start
();
145
}
146
147
template
<
int
UMIN,
int
UMAX,
class
I>
148
forceinline
void
149
Compl<UMIN,UMAX,I>::init
(I& i0) {
150
i
=i0; start();
151
}
152
153
template
<
int
UMIN,
int
UMAX,
class
I>
154
forceinline
void
155
Compl<UMIN,UMAX,I>::operator ++
(
void
) {
156
assert(!
i
() || (
i
.max() <= UMAX));
157
if
(
i
() && (
i
.max() < UMAX)) {
158
mi =
i
.max()+1;
159
++
i
;
160
ma =
i
() ? (
i
.min()-1) : UMAX;
161
}
else
{
162
finish();
163
}
164
}
165
166
template
<
class
I>
167
forceinline
void
168
ComplVal<I>::start
(
void
) {
169
if
(
i
()) {
170
assert((
i
.min() >= UMIN) && (
i
.max() <= UMAX));
171
if
(
i
.min() > UMIN) {
172
mi = UMIN;
173
ma =
i
.min()-1;
174
}
else
if
(
i
.max() < UMAX) {
175
mi =
i
.max()+1;
176
++
i
;
177
ma =
i
() ? (
i
.min()-1) : UMAX;
178
}
else
{
179
finish();
180
}
181
}
else
{
182
mi = UMIN;
183
ma = UMAX;
184
}
185
}
186
187
template
<
class
I>
188
forceinline
189
ComplVal<I>::ComplVal
(
void
) {}
190
191
template
<
class
I>
192
forceinline
193
ComplVal<I>::ComplVal
(
int
umin,
int
umax, I& i0)
194
: UMIN(umin), UMAX(umax),
i
(i0) {
195
start
();
196
}
197
198
template
<
class
I>
199
forceinline
void
200
ComplVal<I>::init
(
int
umin,
int
umax, I& i0) {
201
UMIN=umin; UMAX=umax;
i
=i0; start();
202
}
203
204
template
<
class
I>
205
forceinline
void
206
ComplVal<I>::operator ++
(
void
) {
207
assert(!
i
() || (
i
.max() <= UMAX));
208
if
(
i
() && (
i
.max() < UMAX)) {
209
mi =
i
.max()+1;
210
++
i
;
211
ma =
i
() ? (
i
.min()-1) : UMAX;
212
}
else
{
213
finish();
214
}
215
}
216
217
}}}
218
219
// STATISTICS: iter-any
220