main page
modules
namespaces
classes
files
Gecode home
Generated on Tue Jan 28 2020 00:00:00 for Gecode by
doxygen
1.8.17
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
* Last modified:
10
* $Date: 2012-02-17 02:33:03 +0100 (Fri, 17 Feb 2012) $ by $Author: tack $
11
* $Revision: 12528 $
12
*
13
* This file is part of Gecode, the generic constraint
14
* development environment:
15
* http://www.gecode.org
16
*
17
* Permission is hereby granted, free of charge, to any person obtaining
18
* a copy of this software and associated documentation files (the
19
* "Software"), to deal in the Software without restriction, including
20
* without limitation the rights to use, copy, modify, merge, publish,
21
* distribute, sublicense, and/or sell copies of the Software, and to
22
* permit persons to whom the Software is furnished to do so, subject to
23
* the following conditions:
24
*
25
* The above copyright notice and this permission notice shall be
26
* included in all copies or substantial portions of the Software.
27
*
28
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35
*
36
*/
37
38
#include <cmath>
39
40
namespace
Gecode
{
namespace
Iter {
namespace
Ranges {
41
52
template
<
class
Val,
class
UnsVal,
class
I>
53
class
ScaleUp
{
54
protected
:
56
I
i
;
58
int
a
;
60
Val
cur
;
62
Val
end
;
63
public
:
65
66
ScaleUp
(
void
);
69
ScaleUp
(I&
i
,
int
a
);
71
void
init
(I&
i
,
int
a
);
73
75
76
bool
operator ()
(
void
)
const
;
79
void
operator ++
(
void
);
81
83
84
Val
min
(
void
)
const
;
87
Val
max
(
void
)
const
;
89
UnsVal
width
(
void
)
const
;
91
};
92
98
template
<
class
I>
99
class
ScaleDown
:
public
MinMax
{
100
protected
:
102
I
i
;
104
int
a
;
105
public
:
107
108
ScaleDown
(
void
);
111
ScaleDown
(I&
i
,
int
a
);
113
void
init
(I&
i
,
int
a
);
115
117
118
void
operator ++
(
void
);
121
};
122
123
124
125
template
<
class
Val,
class
UnsVal,
class
I>
126
forceinline
127
ScaleUp<Val,UnsVal,I>::ScaleUp
(
void
) {}
128
129
template
<
class
Val,
class
UnsVal,
class
I>
130
inline
void
131
ScaleUp<Val,UnsVal,I>::init
(I& i0,
int
a0) {
132
i
= i0;
a
= a0;
133
if
(
i
()) {
134
cur =
a
*
i
.min();
135
end =
a
*
i
.max();
136
}
else
{
137
cur = 1;
138
end = 0;
139
}
140
}
141
142
template
<
class
Val,
class
UnsVal,
class
I>
143
inline
144
ScaleUp<Val,UnsVal,I>::ScaleUp
(I& i0,
int
a0) :
i
(i0),
a
(a0) {
145
if
(
i
()) {
146
cur =
a
*
i
.min();
147
end =
a
*
i
.max();
148
}
else
{
149
cur = 1;
150
end = 0;
151
}
152
}
153
154
template
<
class
Val,
class
UnsVal,
class
I>
155
forceinline
void
156
ScaleUp<Val,UnsVal,I>::operator ++
(
void
) {
157
if
(
a
== 1) {
158
++
i
;
159
}
else
{
160
cur +=
a
;
161
if
(cur > end) {
162
++
i
;
163
if
(
i
()) {
164
cur =
a
*
i
.min();
165
end =
a
*
i
.max();
166
}
167
}
168
}
169
}
170
template
<
class
Val,
class
UnsVal,
class
I>
171
forceinline
bool
172
ScaleUp<Val,UnsVal,I>::operator ()
(
void
)
const
{
173
return
(
a
== 1) ?
i
() : (cur <= end);
174
}
175
176
template
<
class
Val,
class
UnsVal,
class
I>
177
forceinline
Val
178
ScaleUp<Val,UnsVal,I>::min
(
void
)
const
{
179
return
(
a
== 1) ?
static_cast<
Val
>
(
i
.min()) : cur;
180
}
181
template
<
class
Val,
class
UnsVal,
class
I>
182
forceinline
Val
183
ScaleUp<Val,UnsVal,I>::max
(
void
)
const
{
184
return
(
a
== 1) ?
static_cast<
Val
>
(
i
.max()) : cur;
185
}
186
template
<
class
Val,
class
UnsVal,
class
I>
187
forceinline
UnsVal
188
ScaleUp<Val,UnsVal,I>::width
(
void
)
const
{
189
return
(
a
== 1) ?
190
static_cast<
UnsVal
>
(
i
.width()) :
191
static_cast<
UnsVal
>
(1);
192
}
193
194
195
196
template
<
class
I>
197
forceinline
void
198
ScaleDown<I>::operator ++
(
void
) {
199
finish();
200
while
((mi > ma) &&
i
()) {
201
mi =
static_cast<
int
>
(ceil(
static_cast<
double
>
(
i
.min())/
a
));
202
ma =
static_cast<
int
>
(floor(
static_cast<
double
>
(
i
.max())/
a
));
203
++
i
;
204
}
205
while
(
i
()) {
206
int
n_mi =
static_cast<
int
>
(ceil(
static_cast<
double
>
(
i
.min())/
a
));
207
if
(n_mi-ma > 1)
208
break
;
209
int
n_ma =
static_cast<
int
>
(floor(
static_cast<
double
>
(
i
.max())/
a
));
210
if
(n_mi <= n_ma) {
211
ma = n_ma;
212
}
213
++
i
;
214
}
215
}
216
217
template
<
class
I>
218
forceinline
219
ScaleDown<I>::ScaleDown
(
void
) {}
220
221
template
<
class
I>
222
inline
void
223
ScaleDown<I>::init
(I& i0,
int
a0) {
224
i
= i0;
a
= a0;
225
operator ++();
226
}
227
228
template
<
class
I>
229
inline
230
ScaleDown<I>::ScaleDown
(I& i0,
int
a0) :
i
(i0),
a
(a0) {
231
i
= i0;
a
= a0;
232
operator ++
();
233
}
234
235
}}}
236
237
// STATISTICS: iter-any
238
forceinline
#define forceinline
Definition:
config.hpp:173
Gecode::Iter::Ranges::ScaleDown::ScaleDown
ScaleDown(void)
Default constructor.
Definition:
ranges-scale.hpp:219
Gecode::Iter::Ranges::ScaleDown::operator++
void operator++(void)
Move iterator to next range (if possible)
Definition:
ranges-scale.hpp:198
Gecode::Iter::Ranges::ScaleUp::width
UnsVal width(void) const
Return width of range (distance between minimum and maximum)
Definition:
ranges-scale.hpp:188
Test::Int::Basic::i
Gecode::IntArgs i(4, 1, 2, 3, 4)
Gecode::Iter::Ranges::ScaleUp::end
Val end
Last value of scaled range of i.
Definition:
ranges-scale.hpp:62
Gecode::Iter::Ranges::ScaleUp::max
Val max(void) const
Return largest value of range.
Definition:
ranges-scale.hpp:183
Gecode::Float::Limits::min
const FloatNum min
Smallest allowed float value.
Definition:
float.hh:850
Gecode::Iter::Ranges::ScaleDown
Range iterator for pointwise division by a positive integer.
Definition:
ranges-scale.hpp:99
Gecode::Iter::Ranges::ScaleUp::cur
Val cur
Current value of range.
Definition:
ranges-scale.hpp:60
Gecode::Iter::Ranges::ScaleUp::a
int a
Scale-factor.
Definition:
ranges-scale.hpp:58
Gecode::Iter::Ranges::ScaleUp::operator()
bool operator()(void) const
Test whether iterator is still at a range or done.
Definition:
ranges-scale.hpp:172
Gecode::Iter::Ranges::ScaleUp::min
Val min(void) const
Return smallest value of range.
Definition:
ranges-scale.hpp:178
Gecode
Gecode toplevel namespace
Gecode::Iter::Ranges::MinMax
Base for range iterators with explicit min and max.
Definition:
ranges-minmax.hpp:51
Gecode::Iter::Ranges::ScaleDown::i
I i
Iterator to be scaled down.
Definition:
ranges-scale.hpp:102
a
struct Gecode::@579::NNF::@61::@63 a
For atomic nodes.
Gecode::Iter::Ranges::ScaleUp::ScaleUp
ScaleUp(void)
Default constructor.
Definition:
ranges-scale.hpp:127
Gecode::Iter::Ranges::ScaleDown::init
void init(I &i, int a)
Initialize with ranges from i and scale factor a.
Definition:
ranges-scale.hpp:223
Gecode::Iter::Ranges::ScaleUp
Range iterator for pointwise product with a positive integer.
Definition:
ranges-scale.hpp:53
Gecode::Iter::Ranges::ScaleDown::a
int a
Divide by this factor.
Definition:
ranges-scale.hpp:104
Gecode::Iter::Ranges::ScaleUp::i
I i
Iterator to be scaled.
Definition:
ranges-scale.hpp:56
Gecode::Iter::Ranges::ScaleUp::init
void init(I &i, int a)
Initialize with ranges from i and scale factor a.
Definition:
ranges-scale.hpp:131
Gecode::Iter::Ranges::ScaleUp::operator++
void operator++(void)
Move iterator to next range (if possible)
Definition:
ranges-scale.hpp:156
Gecode::Float::Limits::max
const FloatNum max
Largest allowed float value.
Definition:
float.hh:848