forked from xsafran1/pepmc2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
transitional_state_space.hpp
244 lines (203 loc) · 5.11 KB
/
transitional_state_space.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
#ifndef PEPMC_TRANSITIONAL_STATE_SPACE_HPP
#define PEPMC_TRANSITIONAL_STATE_SPACE_HPP
#include "state_space.hpp"
template <typename T>
class transitional_state_space
{
public:
typedef T value_type;
typedef state_space<T> ss_t;
ss_t & m_ss;
transitional_state_space(ss_t & ss)
: m_ss(ss)
{
}
struct vertex_descriptor
{
typename ss_t::vertex_descriptor vertex;
std::size_t dim;
std::size_t above;
std::size_t bellow;
bool fair;
vertex_descriptor()
: dim(0), above(0), bellow(0), fair(true)
{
}
bool empty() const
{
return vertex.empty();
}
friend std::ostream & operator<<(std::ostream & out, vertex_descriptor const & v)
{
return out << "{" << v.vertex << ", " << v.dim << ", "
<< v.above << ", " << v.bellow << ", " << "UF"[v.fair] << "}";
}
friend bool operator==(vertex_descriptor const & lhs, vertex_descriptor const & rhs)
{
return boost::tie(lhs.vertex, lhs.dim, lhs.above, lhs.bellow, lhs.fair)
== boost::tie(rhs.vertex, rhs.dim, rhs.above, rhs.bellow, rhs.fair);
}
friend bool operator<(vertex_descriptor const & lhs, vertex_descriptor const & rhs)
{
return boost::tie(lhs.vertex, lhs.dim, lhs.above, lhs.bellow, lhs.fair)
< boost::tie(rhs.vertex, rhs.dim, rhs.above, rhs.bellow, rhs.fair);
}
friend std::size_t hash_value(vertex_descriptor const & v)
{
using boost::hash_value;
std::size_t res = hash_value(v.vertex);
boost::hash_combine(res, v.dim);
boost::hash_combine(res, v.above);
boost::hash_combine(res, v.bellow);
boost::hash_combine(res, v.fair);
return res;
}
};
bool final(vertex_descriptor const & v) const
{
return v.fair;
}
class init_enumerator
{
public:
init_enumerator(transitional_state_space const & g)
: m_g(g), m_inner(g.m_ss)
{
}
bool valid() const
{
return m_inner.valid();
}
void next()
{
m_inner.next();
}
vertex_descriptor get() const
{
vertex_descriptor res;
res.vertex = m_inner.get();
res.fair = m_g.m_ss.final(res.vertex);
return res;
}
private:
transitional_state_space const & m_g;
typename ss_t::init_enumerator m_inner;
};
class out_edge_enumerator
{
public:
out_edge_enumerator(transitional_state_space const & g, vertex_descriptor const & source)
: m_g(g), m_source(source), m_inner(g.m_ss, source.vertex)
{
this->update_target();
}
void reset()
{
m_inner.reset();
}
vertex_descriptor const & source() const
{
return m_source;
}
vertex_descriptor const & target() const
{
return m_target;
}
template <typename Tag>
void paramset_intersect(paramset<T, Tag> & p) const
{
m_inner.paramset_intersect(p);
if (m_target.above + m_target.bellow == 0)
return;
paramset<T, Tag> p_transient;
for (std::size_t dim = 0; dim < m_g.m_ss.dims(); ++dim)
{
paramset<T, Tag> p_down = p;
paramset<T, Tag> p_up = p;
auto v = m_target.vertex;
m_g.m_ss.remove_nontransient(p_down, p_up, v, dim);
for (std::size_t i = 0; i < m_target.above; ++i)
{
v.coords[m_target.dim] = m_target.vertex.coords[m_target.dim] + i + 1;
m_g.m_ss.remove_nontransient(p_down, p_up, v, dim);
}
for (std::size_t i = 0; i < m_target.bellow; ++i)
{
v.coords[m_target.dim] = m_target.vertex.coords[m_target.dim] - i - 1;
m_g.m_ss.remove_nontransient(p_down, p_up, v, dim);
}
p_transient.set_union(std::move(p_down));
p_transient.set_union(std::move(p_up));
}
if (!m_target.fair)
p = std::move(p_transient);
else
p.set_difference(p_transient);
}
bool valid() const
{
return m_inner.valid();
}
void next()
{
if (!m_target.fair && m_g.m_ss.final(m_target.vertex))
{
m_target.fair = true;
return;
}
m_inner.next();
this->update_target();
}
private:
void update_target()
{
if (!m_inner.valid())
return;
m_target.vertex = m_inner.target();
// TODO: Make the dependency a little less explicit.
m_target.dim = m_inner.m_dim;
if (m_source.dim != m_inner.m_dim)
{
m_target.above = 0;
m_target.bellow = 0;
m_target.fair = m_g.m_ss.final(m_target.vertex);
}
else if (!m_inner.m_up)
{
m_target.above = m_source.above + 1;
m_target.bellow = (m_source.bellow == 0? 0: m_source.bellow - 1);
m_target.fair = false;
}
else
{
m_target.bellow = m_source.bellow + 1;
m_target.above = (m_source.above == 0? 0: m_source.above - 1);
m_target.fair = false;
}
}
transitional_state_space const & m_g;
vertex_descriptor m_source;
vertex_descriptor m_target;
typename ss_t::out_edge_enumerator m_inner;
};
template <typename Paramset>
void self_loop(vertex_descriptor const & v, Paramset & p) const
{
m_ss.self_loop(v.vertex, p);
}
typedef typename ss_t::literal_proposition literal_proposition;
typedef typename ss_t::proposition proposition;
bool valid(proposition const & prop, vertex_descriptor const & v) const
{
return m_ss.valid(prop, v.vertex);
}
void refine_thresholds(std::size_t amount)
{
m_ss.refine_thresholds(amount);
}
friend std::ostream & operator<<(std::ostream & o, transitional_state_space const & v)
{
return o << v.m_ss;
}
};
#endif