main page
modules
namespaces
classes
files
Gecode home
Generated on Sat Nov 9 2013 19:18:27 for Gecode by
doxygen
1.8.4
gecode
int
view
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, 2002
8
*
9
* Last modified:
10
* $Date: 2013-02-14 16:29:11 +0100 (Thu, 14 Feb 2013) $ by $Author: schulte $
11
* $Revision: 13292 $
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 <
gecode/int/div.hh
>
39
40
namespace
Gecode {
namespace
Int {
41
42
/*
43
* Constructors and initialization
44
*
45
*/
46
template
<
class
Val,
class
UnsVal>
47
forceinline
48
ScaleView<Val,UnsVal>::ScaleView
(
void
) {}
49
50
template
<
class
Val,
class
UnsVal>
51
forceinline
52
ScaleView<Val,UnsVal>::ScaleView
(
int
b
,
const
IntView
& y)
53
:
DerivedView
<
IntView
>(y),
a
(b) {}
54
55
56
/*
57
* Value access
58
*
59
*/
60
template
<
class
Val,
class
UnsVal>
61
forceinline
int
62
ScaleView<Val,UnsVal>::scale
(
void
)
const
{
63
return
a
;
64
}
65
template
<
class
Val,
class
UnsVal>
66
forceinline
Val
67
ScaleView<Val,UnsVal>::min
(
void
)
const
{
68
return
static_cast<
Val
>
(
x
.min()) *
a
;
69
}
70
71
template
<
class
Val,
class
UnsVal>
72
forceinline
Val
73
ScaleView<Val,UnsVal>::max
(
void
)
const
{
74
return
static_cast<
Val
>
(
x
.max()) *
a
;
75
}
76
77
template
<
class
Val,
class
UnsVal>
78
forceinline
Val
79
ScaleView<Val,UnsVal>::med
(
void
)
const
{
80
return
static_cast<
Val
>
(
x
.med()) *
a
;
81
}
82
83
template
<
class
Val,
class
UnsVal>
84
forceinline
Val
85
ScaleView<Val,UnsVal>::val
(
void
)
const
{
86
return
static_cast<
Val
>
(
x
.val()) *
a
;
87
}
88
89
template
<
class
Val,
class
UnsVal>
90
forceinline
UnsVal
91
ScaleView<Val,UnsVal>::size
(
void
)
const
{
92
return
static_cast<
UnsVal
>
(
x
.size());
93
}
94
95
template
<
class
Val,
class
UnsVal>
96
forceinline
UnsVal
97
ScaleView<Val,UnsVal>::width
(
void
)
const
{
98
return
static_cast<
UnsVal
>
(
x
.width()) *
a
;
99
}
100
101
template
<
class
Val,
class
UnsVal>
102
forceinline
UnsVal
103
ScaleView<Val,UnsVal>::regret_min
(
void
)
const
{
104
return
static_cast<
UnsVal
>
(
x
.regret_min()) *
a
;
105
}
106
107
template
<
class
Val,
class
UnsVal>
108
forceinline
UnsVal
109
ScaleView<Val,UnsVal>::regret_max
(
void
)
const
{
110
return
static_cast<
UnsVal
>
(
x
.regret_max()) *
a
;
111
}
112
113
114
/*
115
* Domain tests
116
*
117
*/
118
template
<
class
Val,
class
UnsVal>
119
forceinline
bool
120
ScaleView<Val,UnsVal>::range
(
void
)
const
{
121
return
x
.range();
122
}
123
template
<
class
Val,
class
UnsVal>
124
forceinline
bool
125
ScaleView<Val,UnsVal>::in
(Val
n
)
const
{
126
return
((n %
a
) == 0) &&
x
.in(n / a);
127
}
128
129
130
131
132
/*
133
* Domain update by value
134
*
135
*/
136
template
<
class
Val,
class
UnsVal>
137
forceinline
ModEvent
138
ScaleView<Val,UnsVal>::lq
(
Space
& home, Val
n
) {
139
return
(n >=
max
()) ?
ME_INT_NONE
:
140
x
.lq(home,
floor_div_xp
(n,static_cast<Val>(
a
)));
141
}
142
143
template
<
class
Val,
class
UnsVal>
144
forceinline
ModEvent
145
ScaleView<Val,UnsVal>::le
(
Space
& home, Val
n
) {
146
return
(n >
max
()) ?
ME_INT_NONE
:
147
x
.le(home,
floor_div_xp
(n,static_cast<Val>(
a
)));
148
}
149
150
template
<
class
Val,
class
UnsVal>
151
forceinline
ModEvent
152
ScaleView<Val,UnsVal>::gq
(
Space
& home, Val
n
) {
153
return
(n <=
min
()) ?
ME_INT_NONE
:
154
x
.gq(home,
ceil_div_xp
(n,static_cast<Val>(
a
)));
155
}
156
template
<
class
Val,
class
UnsVal>
157
forceinline
ModEvent
158
ScaleView<Val,UnsVal>::gr
(
Space
& home, Val
n
) {
159
return
(n <
min
()) ?
ME_INT_NONE
:
160
x
.gr(home,
ceil_div_xp
(n,static_cast<Val>(
a
)));
161
}
162
163
template
<
class
Val,
class
UnsVal>
164
forceinline
ModEvent
165
ScaleView<Val,UnsVal>::nq
(
Space
& home, Val
n
) {
166
return
((n %
a
) == 0) ?
x
.nq(home,n/a) :
ME_INT_NONE
;
167
}
168
169
template
<
class
Val,
class
UnsVal>
170
forceinline
ModEvent
171
ScaleView<Val,UnsVal>::eq
(
Space
& home, Val
n
) {
172
return
((n %
a
) == 0) ?
x
.eq(home,n/a) :
ME_INT_FAILED
;
173
}
174
175
176
/*
177
* Propagator modification events
178
*
179
*/
180
template
<
class
Val,
class
UnsVal>
181
forceinline
ModEventDelta
182
ScaleView<Val,UnsVal>::med
(
ModEvent
me) {
183
return
IntView::med
(me);
184
}
185
186
187
188
/*
189
* Delta information for advisors
190
*
191
*/
192
template
<
class
Val,
class
UnsVal>
193
forceinline
Val
194
ScaleView<Val,UnsVal>::min
(
const
Delta
&
d
)
const
{
195
return
static_cast<
Val
>
(
x
.min(d)) *
a
;
196
}
197
template
<
class
Val,
class
UnsVal>
198
forceinline
Val
199
ScaleView<Val,UnsVal>::max
(
const
Delta
&
d
)
const
{
200
return
static_cast<
Val
>
(
x
.max(d)) *
a
;
201
}
202
template
<
class
Val,
class
UnsVal>
203
forceinline
bool
204
ScaleView<Val,UnsVal>::any
(
const
Delta
&
d
)
const
{
205
return
x
.any(d);
206
}
207
208
209
210
/*
211
* Cloning
212
*
213
*/
214
template
<
class
Val,
class
UnsVal>
215
forceinline
void
216
ScaleView<Val,UnsVal>::update
(
Space
& home,
bool
share,
217
ScaleView<Val,UnsVal>
& y) {
218
DerivedView<IntView>::update
(home,share,y);
219
a
=y.
a
;
220
}
221
222
223
228
template
<>
229
class
ViewRanges
<
IntScaleView
>
230
:
public
Iter::Ranges::ScaleUp
<int,unsigned int,ViewRanges<IntView> > {
231
public
:
233
234
ViewRanges
(
void
);
237
ViewRanges
(
const
IntScaleView
&
x
);
239
void
init
(
const
IntScaleView
& x);
241
};
242
243
forceinline
244
ViewRanges<IntScaleView>::ViewRanges
(
void
) {}
245
forceinline
246
ViewRanges<IntScaleView>::ViewRanges
(
const
IntScaleView
&
x
) {
247
ViewRanges<IntView>
xi(x.
base
());
248
Iter::Ranges::ScaleUp<int,unsigned int,ViewRanges<IntView>
>
::init
249
(xi,x.
scale
());
250
}
251
forceinline
void
252
ViewRanges<IntScaleView>::init
(
const
IntScaleView
&
x
) {
253
ViewRanges<IntView>
xi(x.
base
());
254
Iter::Ranges::ScaleUp<int,unsigned int,ViewRanges<IntView>
>
::init
255
(xi,x.
scale
());
256
}
257
258
263
template
<>
264
class
ViewRanges
<
LLongScaleView
>
265
:
public
Iter::Ranges::ScaleUp
<long long int,unsigned long long int,
266
ViewRanges<IntView> > {
267
public
:
269
270
ViewRanges
(
void
);
273
ViewRanges
(
const
LLongScaleView
&
x
);
275
void
init
(
const
LLongScaleView
& x);
277
};
278
279
forceinline
280
ViewRanges<LLongScaleView>::ViewRanges
(
void
) {}
281
forceinline
282
ViewRanges<LLongScaleView>::ViewRanges
(
const
LLongScaleView
&
x
) {
283
ViewRanges<IntView>
xi(x.
base
());
284
Iter::Ranges::ScaleUp
<
long
long
int,
unsigned
long
long
int,
285
ViewRanges<IntView>
>
::init
(xi,x.
scale
());
286
}
287
forceinline
void
288
ViewRanges<LLongScaleView>::init
(
const
LLongScaleView
&
x
) {
289
ViewRanges<IntView>
xi(x.
base
());
290
Iter::Ranges::ScaleUp
<
long
long
int,
unsigned
long
long
int,
291
ViewRanges<IntView>
>
::init
(xi,x.
scale
());
292
}
293
294
295
/*
296
* View comparison
297
*
298
*/
299
template
<
class
Val,
class
UnsVal>
300
forceinline
bool
301
same
(
const
ScaleView<Val,UnsVal>
&
x
,
const
ScaleView<Val,UnsVal>
& y) {
302
return
same
(x.
base
(),y.
base
()) && (x.
scale
() == y.
scale
());
303
}
304
template
<
class
Val,
class
UnsVal>
305
forceinline
bool
306
before
(
const
ScaleView<Val,UnsVal>
&
x
,
const
ScaleView<Val,UnsVal>
& y) {
307
return
before
(x.
base
(),y.
base
())
308
|| (
same
(x.
base
(),y.
base
()) && (x.
scale
() < y.
scale
()));
309
}
310
311
}}
312
313
// STATISTICS: int-var
314