main page
modules
namespaces
classes
files
Gecode home
Generated on Sun Aug 9 2020 05:34:08 for Gecode by
doxygen
1.8.18
gecode
iter
ranges-scale.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, 2005
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
34
#include <cmath>
35
36
namespace
Gecode
{
namespace
Iter {
namespace
Ranges {
37
48
template
<
class
Val,
class
UnsVal,
class
I>
49
class
ScaleUp
{
50
protected
:
52
I
i
;
54
int
a
;
56
Val
cur
;
58
Val
end
;
59
public
:
61
62
ScaleUp
(
void
);
65
ScaleUp
(I&
i
,
int
a
);
67
void
init
(I&
i
,
int
a
);
69
71
72
bool
operator ()
(
void
)
const
;
75
void
operator ++
(
void
);
77
79
80
Val
min
(
void
)
const
;
83
Val
max
(
void
)
const
;
85
UnsVal
width
(
void
)
const
;
87
};
88
94
template
<
class
I>
95
class
ScaleDown
:
public
MinMax
{
96
protected
:
98
I
i
;
100
int
a
;
101
public
:
103
104
ScaleDown
(
void
);
107
ScaleDown
(I&
i
,
int
a
);
109
void
init
(I&
i
,
int
a
);
111
113
114
void
operator ++
(
void
);
117
};
118
119
120
121
template
<
class
Val,
class
UnsVal,
class
I>
122
forceinline
123
ScaleUp<Val,UnsVal,I>::ScaleUp
(
void
) {}
124
125
template
<
class
Val,
class
UnsVal,
class
I>
126
inline
void
127
ScaleUp<Val,UnsVal,I>::init
(I& i0,
int
a0) {
128
i
= i0;
a
= a0;
129
if
(
i
()) {
130
cur =
a
*
i
.min();
131
end =
a
*
i
.max();
132
}
else
{
133
cur = 1;
134
end = 0;
135
}
136
}
137
138
template
<
class
Val,
class
UnsVal,
class
I>
139
inline
140
ScaleUp<Val,UnsVal,I>::ScaleUp
(I& i0,
int
a0) :
i
(i0),
a
(a0) {
141
if
(
i
()) {
142
cur
=
a
*
i
.min();
143
end
=
a
*
i
.max();
144
}
else
{
145
cur
= 1;
146
end
= 0;
147
}
148
}
149
150
template
<
class
Val,
class
UnsVal,
class
I>
151
forceinline
void
152
ScaleUp<Val,UnsVal,I>::operator ++
(
void
) {
153
if
(
a
== 1) {
154
++
i
;
155
}
else
{
156
cur +=
a
;
157
if
(cur > end) {
158
++
i
;
159
if
(
i
()) {
160
cur =
a
*
i
.min();
161
end =
a
*
i
.max();
162
}
163
}
164
}
165
}
166
template
<
class
Val,
class
UnsVal,
class
I>
167
forceinline
bool
168
ScaleUp<Val,UnsVal,I>::operator ()
(
void
)
const
{
169
return
(
a
== 1) ?
i
() : (cur <= end);
170
}
171
172
template
<
class
Val,
class
UnsVal,
class
I>
173
forceinline
Val
174
ScaleUp<Val,UnsVal,I>::min
(
void
)
const
{
175
return
(
a
== 1) ?
static_cast<
Val
>
(
i
.min()) : cur;
176
}
177
template
<
class
Val,
class
UnsVal,
class
I>
178
forceinline
Val
179
ScaleUp<Val,UnsVal,I>::max
(
void
)
const
{
180
return
(
a
== 1) ?
static_cast<
Val
>
(
i
.max()) : cur;
181
}
182
template
<
class
Val,
class
UnsVal,
class
I>
183
forceinline
UnsVal
184
ScaleUp<Val,UnsVal,I>::width
(
void
)
const
{
185
return
(
a
== 1) ?
186
static_cast<
UnsVal
>
(
i
.width()) :
187
static_cast<
UnsVal
>
(1);
188
}
189
190
191
192
template
<
class
I>
193
forceinline
void
194
ScaleDown<I>::operator ++
(
void
) {
195
finish();
196
while
((mi > ma) &&
i
()) {
197
mi =
static_cast<
int
>
(ceil(
static_cast<
double
>
(
i
.min())/
a
));
198
ma =
static_cast<
int
>
(floor(
static_cast<
double
>
(
i
.max())/
a
));
199
++
i
;
200
}
201
while
(
i
()) {
202
int
n_mi =
static_cast<
int
>
(ceil(
static_cast<
double
>
(
i
.min())/
a
));
203
if
(n_mi-ma > 1)
204
break
;
205
int
n_ma =
static_cast<
int
>
(floor(
static_cast<
double
>
(
i
.max())/
a
));
206
if
(n_mi <= n_ma) {
207
ma = n_ma;
208
}
209
++
i
;
210
}
211
}
212
213
template
<
class
I>
214
forceinline
215
ScaleDown<I>::ScaleDown
(
void
) {}
216
217
template
<
class
I>
218
inline
void
219
ScaleDown<I>::init
(I& i0,
int
a0) {
220
i
= i0;
a
= a0;
221
operator ++();
222
}
223
224
template
<
class
I>
225
inline
226
ScaleDown<I>::ScaleDown
(I& i0,
int
a0) :
i
(i0),
a
(a0) {
227
i
= i0;
a
= a0;
228
operator ++
();
229
}
230
231
}}}
232
233
// STATISTICS: iter-any
234
Gecode::Iter::Ranges::ScaleDown::ScaleDown
ScaleDown(void)
Default constructor.
Definition:
ranges-scale.hpp:215
Gecode::Iter::Ranges::ScaleDown::operator++
void operator++(void)
Move iterator to next range (if possible)
Definition:
ranges-scale.hpp:194
Gecode::Iter::Ranges::ScaleUp::width
UnsVal width(void) const
Return width of range (distance between minimum and maximum)
Definition:
ranges-scale.hpp:184
Gecode::Iter::Ranges::ScaleUp::end
Val end
Last value of scaled range of i.
Definition:
ranges-scale.hpp:58
Gecode::Iter::Ranges::ScaleUp::max
Val max(void) const
Return largest value of range.
Definition:
ranges-scale.hpp:179
Gecode::Iter::Ranges::ScaleDown
Range iterator for pointwise division by a positive integer.
Definition:
ranges-scale.hpp:95
Gecode::Iter::Ranges::ScaleUp::cur
Val cur
Current value of range.
Definition:
ranges-scale.hpp:56
Gecode::Iter::Ranges::ScaleUp::a
int a
Scale-factor.
Definition:
ranges-scale.hpp:54
Gecode::Iter::Ranges::ScaleUp::operator()
bool operator()(void) const
Test whether iterator is still at a range or done.
Definition:
ranges-scale.hpp:168
Gecode::Iter::Ranges::ScaleUp::min
Val min(void) const
Return smallest value of range.
Definition:
ranges-scale.hpp:174
Gecode
Gecode toplevel namespace
Gecode::Iter::Ranges::ScaleUp::ScaleUp
ScaleUp(I &i, int a)
Initialize with ranges from i and scale factor a.
Definition:
ranges-scale.hpp:140
Gecode::Iter::Ranges::MinMax
Base for range iterators with explicit min and max.
Definition:
ranges-minmax.hpp:47
Gecode::Iter::Ranges::ScaleDown::i
I i
Iterator to be scaled down.
Definition:
ranges-scale.hpp:98
Gecode::Iter::Ranges::ScaleUp::ScaleUp
ScaleUp(void)
Default constructor.
Definition:
ranges-scale.hpp:123
Gecode::Iter::Ranges::ScaleDown::init
void init(I &i, int a)
Initialize with ranges from i and scale factor a.
Definition:
ranges-scale.hpp:219
Gecode::Iter::Ranges::ScaleUp
Range iterator for pointwise product with a positive integer.
Definition:
ranges-scale.hpp:49
Gecode::Iter::Ranges::ScaleDown::a
int a
Divide by this factor.
Definition:
ranges-scale.hpp:100
a
struct Gecode::@602::NNF::@65::@67 a
For atomic nodes.
Gecode::Iter::Ranges::ScaleUp::i
I i
Iterator to be scaled.
Definition:
ranges-scale.hpp:52
Gecode::Iter::Ranges::ScaleUp::init
void init(I &i, int a)
Initialize with ranges from i and scale factor a.
Definition:
ranges-scale.hpp:127
forceinline
#define forceinline
Definition:
config.hpp:185
Gecode::Iter::Ranges::ScaleUp::operator++
void operator++(void)
Move iterator to next range (if possible)
Definition:
ranges-scale.hpp:152
Test::Int::Basic::i
Gecode::IntArgs i({1, 2, 3, 4})