Skip to content

Commit

Permalink
Write edges in the right order
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMarex committed May 26, 2017
1 parent 5c61a92 commit 6777b5c
Showing 1 changed file with 28 additions and 16 deletions.
44 changes: 28 additions & 16 deletions include/partition/edge_based_graph_reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include "util/dynamic_graph.hpp"
#include "util/typedefs.hpp"

#include <tbb/parallel_sort.h>

#include <cstdint>

#include <algorithm>
Expand Down Expand Up @@ -126,28 +128,38 @@ std::vector<OutputEdgeT> prepareEdgesForUsageInGraph(std::vector<extractor::Edge
return graph_edges;
}

std::vector<extractor::EdgeBasedEdge>
graphToEdges(const DynamicEdgeBasedGraph& edge_based_graph)
std::vector<extractor::EdgeBasedEdge> graphToEdges(const DynamicEdgeBasedGraph &edge_based_graph)
{
std::vector<extractor::EdgeBasedEdge> edges;
edges.reserve(edge_based_graph.GetNumberOfEdges() * 2);

for (const auto node : util::irange<NodeID>(0, edge_based_graph.GetNumberOfNodes()))
{

for (auto edge: edge_based_graph.GetAdjacentEdgeRange(node))
NodeID max_turn_id = 0;
auto range = tbb::blocked_range<NodeID>(0, edge_based_graph.GetNumberOfNodes());
tbb::parallel_for(range, [&](const auto range) {
for (auto node = range.begin(); node < range.end(); ++node)
{
const auto& data = edge_based_graph.GetEdgeData(edge);
// we only need to save the forward edges, since the read method will
// convert from forward to bi-directional edges again
if (data.forward)
for (auto edge : edge_based_graph.GetAdjacentEdgeRange(node))
{
auto target = edge_based_graph.GetTarget(edge);
edges.emplace_back(node, target, data);
const auto &data = edge_based_graph.GetEdgeData(edge);
max_turn_id = std::max(max_turn_id, data.turn_id);
}
}
}
});

std::vector<extractor::EdgeBasedEdge> edges(max_turn_id + 1);
tbb::parallel_for(range, [&](const auto range) {
for (auto node = range.begin(); node < range.end(); ++node)
{
for (auto edge : edge_based_graph.GetAdjacentEdgeRange(node))
{
const auto &data = edge_based_graph.GetEdgeData(edge);
// we only need to save the forward edges, since the read method will
// convert from forward to bi-directional edges again
if (data.forward)
{
auto target = edge_based_graph.GetTarget(edge);
edges[data.turn_id] = extractor::EdgeBasedEdge{node, target, data};
}
}
}
});
return edges;
}

Expand Down

0 comments on commit 6777b5c

Please sign in to comment.