30 #ifndef INCLUDE_CONTRACTION_PGR_CONTRACTIONGRAPH_HPP_
31 #define INCLUDE_CONTRACTION_PGR_CONTRACTIONGRAPH_HPP_
34 #include <boost/graph/iteration_macros.hpp>
53 typedef typename boost::graph_traits < G >::vertex_descriptor
V;
54 typedef typename boost::graph_traits < G >::edge_descriptor
E;
55 typedef typename boost::graph_traits < G >::out_edge_iterator
EO_i;
56 typedef typename boost::graph_traits < G >::in_edge_iterator
EI_i;
74 for (boost::tie(out, out_end) = out_edges(v, this->
graph);
75 out != out_end; ++out) {
76 adjacent_vertices += this->
adjacent(v, *out);
78 for (boost::tie(in, in_end) = in_edges(v, this->
graph);
80 adjacent_vertices += this->
adjacent(v, *in);
82 return adjacent_vertices;
91 std::tuple<double, Identifiers<int64_t>,
bool>
95 double min_cost = (std::numeric_limits<double>::max)();
99 BGL_FORALL_OUTEDGES_T(u, e, this->
graph,
G) {
100 if (this->
target(e) == v) {
101 contracted_vertices += this->
graph[e].contracted_vertices();
102 if (this->
graph[e].cost < min_cost) {
103 min_cost = this->
graph[e].cost;
109 return std::make_tuple(min_cost, contracted_vertices, found);
113 BGL_FORALL_OUTEDGES_T(u, e, this->
graph,
G) {
115 contracted_vertices += this->
graph[e].contracted_vertices();
116 if (this->
graph[e].cost < min_cost) {
117 min_cost = this->
graph[e].cost;
123 return std::make_tuple(min_cost, contracted_vertices, found);
135 for (
auto vi = vertices(g.
graph).first;
136 vi != vertices(g.
graph).second;
139 os << g.
graph[*vi].id <<
"(" << (*vi) <<
")"
140 << g.
graph[*vi].contracted_vertices() << std::endl;
141 os <<
" out_edges_of(" << g.
graph[*vi].id <<
"):";
142 for (boost::tie(out, out_end) = out_edges(*vi, g.
graph);
143 out != out_end; ++out) {
144 os <<
' ' << g.
graph[*out].id
147 << g.
graph[*out].cost <<
"\t";
175 boost::tie(e, inserted) = boost::add_edge(u, v, this->
graph);
182 return boost::edge(u, v, this->
graph).second && boost::edge(v, w, this->
graph).second;
212 if (u == v || v == w || u == w)
return false;
233 (
has_u_v_w(u, v, w) && !(boost::edge(v, u, this->
graph).second || boost::edge(w, v, this->
graph).second))
238 (
has_u_v_w(w, v, u) && !(boost::edge(v, w, this->
graph).second || boost::edge(u, v, this->
graph).second));
245 if (adjacent_vertices.size() == 2) {
247 V u = adjacent_vertices.front();
248 adjacent_vertices.pop_front();
249 V w = adjacent_vertices.front();
250 adjacent_vertices.pop_front();
263 #endif // INCLUDE_CONTRACTION_PGR_CONTRACTIONGRAPH_HPP_