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
int
support-values.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, 2008
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
namespace
Gecode
{
namespace
Int {
39
40
template
<
class
View,
class
A>
41
forceinline
void
42
SupportValues<View,A>::reset
(
void
) {
43
rp = rp_fst;
v
= rp->min;
44
max
= rp->min +
static_cast<
int
>
((rp+1)->
pos
- rp->pos) - 1;
45
}
46
47
template
<
class
View,
class
A>
48
inline
49
SupportValues<View,A>::SupportValues
(A& a0, View x0)
50
:
a
(a0),
x
(x0), bs(
a
,
x
.
size
(),true) {
51
unsigned
int
n
= 0;
52
for
(
ViewRanges<View>
r
(x);
r
(); ++
r
)
53
n
++;
54
rp_fst = a.template alloc<RangePos>(
n
+1);
55
rp_lst = rp_fst +
n
;
56
unsigned
int
p
= 0;
57
int
i
= 0;
58
for
(
ViewRanges<View>
r
(x);
r
(); ++
r
) {
59
rp_fst[
i
].min =
r
.min();
60
rp_fst[
i
].pos =
p
;
61
p
+=
r
.width();
i
++;
62
}
63
rp_fst[
i
].pos=
p
;
64
reset
();
65
}
66
67
template
<
class
View,
class
A>
68
forceinline
69
SupportValues<View,A>::~SupportValues
(
void
) {
70
bs.dispose(
a
);
71
a
.free(rp_fst,
static_cast<
unsigned
long
int
>
(rp_lst-rp_fst+1));
72
}
73
74
template
<
class
View,
class
A>
75
forceinline
void
76
SupportValues<View,A>::operator ++
(
void
) {
77
if
(++
v
>
max
)
78
if
(++rp < rp_lst) {
79
v
= rp->min;
80
max
= rp->min +
static_cast<
int
>
((rp+1)->
pos
- rp->pos) - 1;
81
}
82
}
83
84
template
<
class
View,
class
A>
85
forceinline
bool
86
SupportValues<View,A>::operator ()
(
void
)
const
{
87
return
rp < rp_lst;
88
}
89
90
template
<
class
View,
class
A>
91
forceinline
int
92
SupportValues<View,A>::val
(
void
)
const
{
93
return
v
;
94
}
95
96
template
<
class
View,
class
A>
97
forceinline
void
98
SupportValues<View,A>::support
(
void
) {
99
bs.clear(rp->pos +
static_cast<
unsigned
int
>
(
v
-rp->min));
100
}
101
102
template
<
class
View,
class
A>
103
forceinline
bool
104
SupportValues<View,A>::_support
(
int
n
) {
105
RangePos*
l
= rp_fst;
106
RangePos*
r
= rp_lst-1;
107
while
(
true
) {
108
if
(
l
>
r
)
return
false
;
109
RangePos* m =
l
+ (
r
-
l
)/2;
110
int
max
= m->min +
static_cast<
int
>
((m+1)->
pos
- m->pos) - 1;
111
if
((
n
>= m->min) && (
n
<=
max
)) {
112
bs.clear(m->pos +
static_cast<
unsigned
int
>
(
n
-m->min));
113
return
true
;
114
}
115
if
(
l
==
r
)
return
false
;
116
if
(n < m->
min
)
117
r
=m-1;
118
else
119
l
=m+1;
120
}
121
GECODE_NEVER
;
122
return
false
;
123
}
124
125
template
<
class
View,
class
A>
126
forceinline
bool
127
SupportValues<View,A>::support
(
int
n
) {
128
if
((
n
<
x
.min()) || (
n
>
x
.max()))
129
return
false
;
130
return
_support(
n
);
131
}
132
133
template
<
class
View,
class
A>
134
forceinline
bool
135
SupportValues<View,A>::support
(
long
long
int
n
) {
136
if
((
n
<
x
.min()) || (
n
>
x
.max()))
137
return
false
;
138
return
_support(
static_cast<
int
>
(
n
));
139
}
140
141
template
<
class
View,
class
A>
142
forceinline
void
143
SupportValues<View,A>::Unsupported::find
(
void
) {
144
// Skip all supported positions
145
while
((
p
< sv.x.size()) && !sv.bs.get(
p
))
146
p
= sv.bs.next(
p
);
147
// Move to matching range
148
while
((rp < sv.rp_lst) && (
p
>= (rp+1)->pos))
149
rp++;
150
}
151
152
template
<
class
View,
class
A>
153
forceinline
154
SupportValues<View,A>::Unsupported::Unsupported
(
SupportValues
& sv0)
155
: rp(sv0.rp_fst),
p
(0), sv(sv0) {
156
find();
157
}
158
159
template
<
class
View,
class
A>
160
forceinline
void
161
SupportValues<View,A>::Unsupported::operator ++(
void
) {
162
p
++; find();
163
}
164
165
template
<
class
View,
class
A>
166
forceinline
bool
167
SupportValues<View,A>::Unsupported::operator ()(
void
)
const
{
168
return
rp < sv.rp_lst;
169
}
170
171
template
<
class
View,
class
A>
172
forceinline
int
173
SupportValues<View,A>::Unsupported::val(
void
)
const
{
174
return
static_cast<
int
>
(rp->min+(
p
-rp->pos));
175
}
176
177
template
<
class
View,
class
A>
178
inline
ModEvent
179
SupportValues<View,A>::tell
(
Space
& home) {
180
Unsupported
u
(*
this
);
181
return
x
.minus_v(home,
u
,
false
);
182
}
183
184
}}
185
186
// STATISTICS: int-prop
187
Gecode::Int::SupportValues::SupportValues
SupportValues(A &a, View x)
Initialize for view x.
Definition:
support-values.hpp:49
Gecode::x
Post propagator for SetVar x
Definition:
set.hh:784
Gecode::Int::SupportValues::val
int val(void) const
Return current value.
Definition:
support-values.hpp:92
forceinline
#define forceinline
Definition:
config.hpp:173
Gecode::max
void max(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition:
arithmetic.cpp:53
Gecode::Iter::Ranges::size
unsigned int size(I &i)
Size of all ranges of range iterator i.
Definition:
ranges-operations.hpp:78
Gecode::Int::SupportValues
Support value iterator and recorder
Definition:
support-values.hh:52
Test::Int::Basic::i
Gecode::IntArgs i(4, 1, 2, 3, 4)
Gecode::Space
Computation spaces.
Definition:
core.hpp:1748
u
union Gecode::@579::NNF::@61 u
Union depending on nodetype t.
Gecode::Int::SupportValues::operator++
void operator++(void)
Move iterator to next value (if possible)
Definition:
support-values.hpp:76
Gecode
Gecode toplevel namespace
Gecode::Int::ViewRanges
Range iterator for integer views.
Definition:
view.hpp:54
Gecode::Int::SupportValues::support
void support(void)
Mark current (iterator) value as supported.
Definition:
support-values.hpp:98
Gecode::Int::SupportValues::~SupportValues
~SupportValues(void)
Destructor.
Definition:
support-values.hpp:69
a
struct Gecode::@579::NNF::@61::@63 a
For atomic nodes.
Gecode::r
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition:
set.hh:784
GECODE_NEVER
#define GECODE_NEVER
Assert that this command is never executed.
Definition:
macros.hpp:60
Gecode::Int::SupportValues::operator()
bool operator()(void) const
Test whether iterator is still at a value or done.
Definition:
support-values.hpp:86
Gecode::Int::SupportValues::reset
void reset(void)
Reset iterator.
Definition:
support-values.hpp:42
Gecode::ModEvent
int ModEvent
Type for modification events.
Definition:
core.hpp:142
Test::Int::Distinct::v
const int v[7]
Definition:
distinct.cpp:263
l
NNF * l
Left subtree.
Definition:
bool-expr.cpp:244
Gecode::Int::SupportValues::tell
ModEvent tell(Space &home)
Remove all unsupported values.
Definition:
support-values.hpp:179
Gecode::min
void min(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition:
arithmetic.cpp:71
n
int n
Number of negative literals for node type.
Definition:
bool-expr.cpp:238
Gecode::Float::Arithmetic::pos
bool pos(const View &x)
Test whether x is postive.
Definition:
mult.hpp:45
p
int p
Number of positive literals for node type.
Definition:
bool-expr.cpp:236