30 #ifndef INCLUDE_LINEGRAPH_PGR_LINEGRAPHFULL_HPP_
31 #define INCLUDE_LINEGRAPH_PGR_LINEGRAPHFULL_HPP_
46 template <
class G,
typename T_V,
typename T_E>
49 typedef typename boost::graph_traits < G >::vertex_descriptor
V;
50 typedef typename boost::graph_traits < G >::edge_descriptor
E;
51 typedef typename boost::graph_traits < G >::vertex_iterator
V_i;
52 typedef typename boost::graph_traits < G >::edge_iterator
E_i;
53 typedef typename boost::graph_traits < G >::out_edge_iterator
EO_i;
54 typedef typename boost::graph_traits < G >::in_edge_iterator
EI_i;
72 for (
auto vi = vertices(g.
graph).first;
73 vi != vertices(g.
graph).second; ++vi) {
75 log << (*vi) <<
": " <<
" out_edges_of(" << g.
graph[(*vi)] <<
"):";
76 for (boost::tie(out, out_end) = out_edges(*vi, g.
graph);
77 out != out_end; ++out) {
79 << g.
graph[*out].id <<
"=("
80 << g[g.
source(*out)].id <<
", "
81 << g[g.
target(*out)].id <<
")\t";
88 std::vector< Line_graph_full_rt >
90 std::vector< Line_graph_full_rt > results;
92 typename boost::graph_traits < G >::edge_iterator edgeIt, edgeEnd;
94 std::pair<int64_t, int64_t >,
97 auto vertex_count = 0;
98 std::map < int64_t, int64_t > vertex_id_map;
99 std::map < int64_t, int64_t > vertex_id_reverse_map;
101 log <<
"\nPostgres results\n";
102 for (boost::tie(edgeIt, edgeEnd) = boost::edges(this->
graph);
103 edgeIt != edgeEnd; edgeIt++) {
105 auto e_source = this->
graph[this->
source(e)].vertex_id;
106 auto e_target = this->
graph[this->
target(e)].vertex_id;
109 auto target_vertex_id = target_vertex_edge_pair.first;
110 auto target_edge_id = target_vertex_edge_pair.second;
112 auto source_vertex_id = source_vertex_edge_pair.first;
113 auto source_edge_id = source_vertex_edge_pair.second;
117 if (source_edge_id == target_edge_id) {
119 edge_id = source_edge_id;
122 if (vertex_id_map.find(e_source) == vertex_id_map.end()) {
123 if (vertex_id_reverse_map.find(source_vertex_id) ==
124 vertex_id_reverse_map.end()) {
125 vertex_id_map[e_source] = source_vertex_id;
126 vertex_id_reverse_map[source_vertex_id] = e_source;
129 vertex_id_map[e_source] = vertex_count;
130 vertex_id_reverse_map[vertex_count] = e_source;
134 if (vertex_id_map.find(e_target) == vertex_id_map.end()) {
135 if (vertex_id_reverse_map.find(target_vertex_id) ==
136 vertex_id_reverse_map.end()) {
137 vertex_id_map[e_target] = target_vertex_id;
138 vertex_id_reverse_map[target_vertex_id] = e_target;
141 vertex_id_map[e_target] = vertex_count;
142 vertex_id_reverse_map[vertex_count] = e_target;
147 log <<
"e_source = " << e_source
148 <<
" e_target = " << e_target
153 vertex_id_map[e_source],
154 vertex_id_map[e_target],
159 unique[ std::pair<int64_t, int64_t>(e_source, e_target) ] =
162 for (
const auto &
edge : unique) {
163 results.push_back(
edge.second);
170 int64_t original_vertex_id,
171 int64_t original_edge_id) {
172 auto new_id =
static_cast<int64_t
>(this->
num_vertices() + 1);
174 std::pair<int64_t, int64_t>(original_vertex_id, original_edge_id);
175 m_vertex_map[std::pair<int64_t, int64_t>(original_vertex_id,
178 auto v = add_vertex(this->
graph);
179 this->
graph[v].cp_members(original_vertex_id, original_edge_id);
180 this->
graph[v].vertex_id = new_id;
187 for (boost::tie(e_It, e_End) = boost::edges(digraph.
graph);
188 e_It != e_End; e_It++) {
193 template <
typename T>
198 int64_t source_in_edge,
199 int64_t source_out_edge) {
208 auto index_source_edge =
211 auto index_target_edge =
215 auto vm_s = this->
get_V(index_source_edge);
216 auto vm_t = this->
get_V(index_target_edge);
219 this->vertices_map.end());
221 this->vertices_map.end());
223 boost::tie(e, inserted) =
224 boost::add_edge(vm_s, vm_t, this->
graph);
226 this->
graph[e].id = _id;
231 V_i vertexIt, vertexEnd;
232 EO_i e_outIt, e_outEnd;
233 EI_i e_inIt, e_inEnd;
237 for (boost::tie(vertexIt, vertexEnd) = boost::vertices(digraph.
graph);
238 vertexIt != vertexEnd; vertexIt++) {
239 V vertex = *vertexIt;
240 auto vertex_id = digraph[vertex].id;
241 for (boost::tie(e_outIt, e_outEnd) =
242 boost::out_edges(vertex, digraph.
graph);
243 e_outIt != e_outEnd; e_outIt++) {
244 auto out_edge_id = digraph.
graph[*e_outIt].id;
248 for (boost::tie(e_inIt, e_inEnd) =
249 boost::in_edges(vertex, digraph.
graph);
250 e_inIt != e_inEnd; e_inIt++) {
251 auto in_edge_id = digraph.
graph[*e_inIt].id;
254 for (boost::tie(e_outIt, e_outEnd) =
255 boost::out_edges(vertex, digraph.
graph);
256 e_outIt != e_outEnd; e_outIt++) {
257 auto out_edge_id = digraph.
graph[*e_outIt].id;
273 for (boost::tie(vertexIt, vertexEnd) =
274 boost::vertices(digraph.
graph);
275 vertexIt != vertexEnd; vertexIt++) {
276 V vertex = *vertexIt;
277 auto vertex_id = digraph[vertex].id;
279 for (boost::tie(e_inIt, e_inEnd) =
280 boost::in_edges(vertex, digraph.
graph);
281 e_inIt != e_inEnd; e_inIt++) {
282 auto source_vertex_id = digraph[digraph.
source(*e_inIt)].id;
283 auto in_edge_id = digraph.
graph[*e_inIt].id;
309 #endif // INCLUDE_LINEGRAPH_PGR_LINEGRAPHFULL_HPP_