-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loads the edge based graph edges and constructs a dynamic graph from it
- Loading branch information
1 parent
032d1da
commit 35c981a
Showing
5 changed files
with
120 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
#ifndef OSRM_EDGE_BASED_GRAPH_READER_HPP | ||
#define OSRM_EDGE_BASED_GRAPH_READER_HPP | ||
|
||
#include "storage/io.hpp" | ||
#include "util/coordinate.hpp" | ||
#include "util/dynamic_graph.hpp" | ||
|
||
#include <cstdint> | ||
|
||
#include <algorithm> | ||
#include <iterator> | ||
#include <memory> | ||
#include <vector> | ||
|
||
namespace osrm | ||
{ | ||
namespace partition | ||
{ | ||
|
||
struct EdgeBasedGraphEdgeData | ||
{ | ||
}; | ||
|
||
struct EdgeBasedGraph : util::DynamicGraph<EdgeBasedGraphEdgeData> | ||
{ | ||
using Base = util::DynamicGraph<EdgeBasedGraphEdgeData>; | ||
using Base::Base; | ||
}; | ||
|
||
struct EdgeBasedGraphEdge : EdgeBasedGraph::InputEdge | ||
{ | ||
using Base = EdgeBasedGraph::InputEdge; | ||
using Base::Base; | ||
}; | ||
|
||
struct EdgeBasedGraphReader | ||
{ | ||
EdgeBasedGraphReader(storage::io::FileReader &reader) | ||
{ | ||
// Reads: | Fingerprint | #e | max_eid | edges | | ||
// - uint64: number of edges | ||
// - EdgeID: max edge id | ||
// - extractor::EdgeBasedEdge edges | ||
// | ||
// Gets written in Extractor::WriteEdgeBasedGraph | ||
|
||
const auto num_edges = reader.ReadElementCount64(); | ||
const auto max_edge_id = reader.ReadOne<EdgeID>(); | ||
|
||
// Sentinel | ||
num_nodes = max_edge_id + 1; | ||
|
||
edges.resize(num_edges); | ||
reader.ReadInto(edges); | ||
} | ||
|
||
// FIXME: wrapped in unique_ptr since dynamic_graph is not move-able | ||
|
||
std::unique_ptr<EdgeBasedGraph> BuildEdgeBasedGraph() | ||
{ | ||
std::sort(begin(edges), end(edges)); | ||
|
||
// TODO: See GraphContractor ctor for the ugly dance one has to perform here | ||
std::vector<EdgeBasedGraphEdge> graph_edges(edges.size()); | ||
|
||
std::transform(begin(edges), end(edges), begin(graph_edges), [](const auto &edge) { | ||
return EdgeBasedGraphEdge{edge.source, edge.target}; | ||
}); | ||
|
||
return std::make_unique<EdgeBasedGraph>(num_nodes, graph_edges); | ||
} | ||
|
||
private: | ||
std::vector<extractor::EdgeBasedEdge> edges; | ||
std::size_t num_nodes; | ||
}; | ||
|
||
inline std::unique_ptr<EdgeBasedGraph> LoadEdgeBasedGraph(const std::string &path) | ||
{ | ||
const auto fingerprint = storage::io::FileReader::VerifyFingerprint; | ||
storage::io::FileReader reader(path, fingerprint); | ||
|
||
EdgeBasedGraphReader builder{reader}; | ||
|
||
return builder.BuildEdgeBasedGraph(); | ||
} | ||
|
||
} // ns partition | ||
} // ns osrm | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters