Fix tools to build with new graph reader interface
This commit is contained in:
parent
a46bcf45d5
commit
e76d8df246
@ -328,12 +328,10 @@ if(WITH_TOOLS OR BUILD_TOOLS)
|
||||
if(UNIX AND NOT APPLE)
|
||||
target_link_libraries(osrm-unlock-all rt)
|
||||
endif()
|
||||
add_executable(osrm-check-hsgr tools/check-hsgr.cpp $<TARGET_OBJECTS:FINGERPRINT> $<TARGET_OBJECTS:EXCEPTION> $<TARGET_OBJECTS:LOGGER>)
|
||||
add_executable(osrm-check-hsgr tools/check-hsgr.cpp $<TARGET_OBJECTS:FINGERPRINT> $<TARGET_OBJECTS:EXCEPTION> $<TARGET_OBJECTS:LOGGER> $<TARGET_OBJECTS:IMPORT>)
|
||||
target_link_libraries(osrm-check-hsgr ${Boost_LIBRARIES})
|
||||
add_executable(osrm-springclean tools/springclean.cpp $<TARGET_OBJECTS:FINGERPRINT> $<TARGET_OBJECTS:LOGGER> $<TARGET_OBJECTS:GITDESCRIPTION> $<TARGET_OBJECTS:EXCEPTION>)
|
||||
target_link_libraries(osrm-springclean ${Boost_LIBRARIES})
|
||||
add_executable(osrm-graph-compare tools/graph_compare.cpp $<TARGET_OBJECTS:FINGERPRINT> $<TARGET_OBJECTS:IMPORT> $<TARGET_OBJECTS:COORDINATE> $<TARGET_OBJECTS:LOGGER> $<TARGET_OBJECTS:RESTRICTION> $<TARGET_OBJECTS:EXCEPTION> $<TARGET_OBJECTS:MERCATOR>)
|
||||
target_link_libraries(osrm-graph-compare ${Boost_LIBRARIES} ${TBB_LIBRARIES})
|
||||
|
||||
install(TARGETS osrm-cli DESTINATION bin)
|
||||
install(TARGETS osrm-io-benchmark DESTINATION bin)
|
||||
|
@ -76,55 +76,25 @@ void DeleteFileIfExists(const std::string &file_name)
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
void LoadRestrictions(const char* path,
|
||||
std::unique_ptr<std::unordered_map<NodeID, NodeID>> ext_to_int_id_map,
|
||||
std::vector<TurnRestriction>& restriction_list)
|
||||
{
|
||||
std::vector<QueryNode> coordinate_list;
|
||||
std::vector<TurnRestriction> restriction_list;
|
||||
std::vector<NodeID> bollard_node_list;
|
||||
std::vector<NodeID> traffic_lights_list;
|
||||
|
||||
LogPolicy::GetInstance().Unmute();
|
||||
try
|
||||
std::ifstream input_stream(path, std::ios::binary);
|
||||
if (!input_stream.is_open())
|
||||
{
|
||||
// enable logging
|
||||
if (argc < 3)
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << "usage:\n" << argv[0]
|
||||
<< " <osrm> <osrm.restrictions>";
|
||||
return -1;
|
||||
throw osrm::exception("Cannot open restriction file");
|
||||
}
|
||||
loadRestrictionsFromFile(input_stream, *ext_to_int_id_map, restriction_list);
|
||||
}
|
||||
|
||||
SimpleLogger().Write() << "Using restrictions from file: " << argv[2];
|
||||
std::ifstream restriction_ifstream(argv[2], std::ios::binary);
|
||||
const FingerPrint fingerprint_orig;
|
||||
FingerPrint fingerprint_loaded;
|
||||
restriction_ifstream.read(reinterpret_cast<char *>(&fingerprint_loaded),
|
||||
sizeof(FingerPrint));
|
||||
|
||||
// check fingerprint and warn if necessary
|
||||
if (!fingerprint_loaded.TestGraphUtil(fingerprint_orig))
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << argv[2] << " was prepared with a different build. "
|
||||
"Reprocess to get rid of this warning.";
|
||||
}
|
||||
|
||||
if (!restriction_ifstream.good())
|
||||
{
|
||||
throw osrm::exception("Could not access <osrm-restrictions> files");
|
||||
}
|
||||
uint32_t usable_restrictions = 0;
|
||||
restriction_ifstream.read(reinterpret_cast<char *>(&usable_restrictions), sizeof(uint32_t));
|
||||
restriction_list.resize(usable_restrictions);
|
||||
|
||||
// load restrictions
|
||||
if (usable_restrictions > 0)
|
||||
{
|
||||
restriction_ifstream.read(reinterpret_cast<char *>(&restriction_list[0]),
|
||||
usable_restrictions * sizeof(TurnRestriction));
|
||||
}
|
||||
restriction_ifstream.close();
|
||||
|
||||
std::ifstream input_stream(argv[1], std::ifstream::in | std::ifstream::binary);
|
||||
std::size_t LoadGraph(const char* path,
|
||||
std::vector<QueryNode>& coordinate_list,
|
||||
std::vector<NodeID>& barrier_node_list,
|
||||
std::unordered_map<NodeID, NodeID>& ext_to_int_id_map,
|
||||
std::vector<TarjanEdge>& graph_edge_list)
|
||||
{
|
||||
std::ifstream input_stream(path, std::ifstream::in | std::ifstream::binary);
|
||||
if (!input_stream.is_open())
|
||||
{
|
||||
throw osrm::exception("Cannot open osrm file");
|
||||
@ -132,24 +102,19 @@ int main(int argc, char *argv[])
|
||||
|
||||
// load graph data
|
||||
std::vector<ImportEdge> edge_list;
|
||||
const NodeID number_of_nodes =
|
||||
readBinaryOSRMGraphFromStream(input_stream, edge_list, bollard_node_list,
|
||||
traffic_lights_list, &coordinate_list, restriction_list);
|
||||
input_stream.close();
|
||||
std::vector<NodeID> traffic_light_node_list;
|
||||
|
||||
BOOST_ASSERT_MSG(restriction_list.size() == usable_restrictions,
|
||||
"size of restriction_list changed");
|
||||
auto number_of_nodes = loadNodesFromFile(input_stream, barrier_node_list,
|
||||
traffic_light_node_list,
|
||||
coordinate_list,
|
||||
ext_to_int_id_map);
|
||||
|
||||
SimpleLogger().Write() << restriction_list.size() << " restrictions, "
|
||||
<< bollard_node_list.size() << " bollard nodes, "
|
||||
<< traffic_lights_list.size() << " traffic lights";
|
||||
auto number_of_edges = loadEdgesFromFile(input_stream, ext_to_int_id_map, edge_list);
|
||||
|
||||
traffic_lights_list.clear();
|
||||
traffic_lights_list.shrink_to_fit();
|
||||
traffic_light_node_list.clear();
|
||||
traffic_light_node_list.shrink_to_fit();
|
||||
|
||||
// Building an node-based graph
|
||||
std::vector<TarjanEdge> graph_edge_list;
|
||||
// DeallocatingVector<TarjanEdge> graph_edge_list;
|
||||
for (const auto &input_edge : edge_list)
|
||||
{
|
||||
if (input_edge.source == input_edge.target)
|
||||
@ -168,10 +133,33 @@ int main(int argc, char *argv[])
|
||||
(std::max)(input_edge.weight, 1), input_edge.name_id);
|
||||
}
|
||||
}
|
||||
edge_list.clear();
|
||||
edge_list.shrink_to_fit();
|
||||
BOOST_ASSERT_MSG(0 == edge_list.size() && 0 == edge_list.capacity(),
|
||||
"input edge vector not properly deallocated");
|
||||
|
||||
return number_of_nodes;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
std::vector<QueryNode> coordinate_list;
|
||||
std::vector<TurnRestriction> restriction_list;
|
||||
std::vector<NodeID> barrier_node_list;
|
||||
auto ext_to_int_id_map = osrm::make_unique<std::unordered_map<NodeID, NodeID>>();
|
||||
|
||||
LogPolicy::GetInstance().Unmute();
|
||||
try
|
||||
{
|
||||
// enable logging
|
||||
if (argc < 3)
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << "usage:\n" << argv[0]
|
||||
<< " <osrm> <osrm.restrictions>";
|
||||
return -1;
|
||||
}
|
||||
|
||||
SimpleLogger().Write() << "Using restrictions from file: " << argv[2];
|
||||
|
||||
std::vector<TarjanEdge> graph_edge_list;
|
||||
auto number_of_nodes = LoadGraph(argv[1], coordinate_list, barrier_node_list, *ext_to_int_id_map, graph_edge_list);
|
||||
LoadRestrictions(argv[2], std::move(ext_to_int_id_map), restriction_list);
|
||||
|
||||
tbb::parallel_sort(graph_edge_list.begin(), graph_edge_list.end());
|
||||
const auto graph = std::make_shared<TarjanGraph>(number_of_nodes, graph_edge_list);
|
||||
@ -181,9 +169,8 @@ int main(int argc, char *argv[])
|
||||
SimpleLogger().Write() << "Starting SCC graph traversal";
|
||||
|
||||
RestrictionMap restriction_map(restriction_list);
|
||||
auto tarjan = osrm::make_unique<TarjanSCC<TarjanGraph>>(graph,
|
||||
restriction_map,
|
||||
bollard_node_list);
|
||||
auto tarjan = osrm::make_unique<TarjanSCC<TarjanGraph>>(graph, restriction_map,
|
||||
barrier_node_list);
|
||||
tarjan->run();
|
||||
SimpleLogger().Write() << "identified: " << tarjan->get_number_of_components()
|
||||
<< " many components";
|
||||
|
@ -1,199 +0,0 @@
|
||||
#include "../data_structures/dynamic_graph.hpp"
|
||||
#include "../data_structures/import_edge.hpp"
|
||||
#include "../data_structures/query_node.hpp"
|
||||
#include "../data_structures/restriction.hpp"
|
||||
#include "../data_structures/static_graph.hpp"
|
||||
#include "../util/fingerprint.hpp"
|
||||
#include "../util/graph_loader.hpp"
|
||||
#include "../util/integer_range.hpp"
|
||||
#include "../util/make_unique.hpp"
|
||||
#include "../util/osrm_exception.hpp"
|
||||
#include "../util/simple_logger.hpp"
|
||||
|
||||
#include "../typedefs.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <fstream>
|
||||
|
||||
struct TarjanEdgeData
|
||||
{
|
||||
TarjanEdgeData() : distance(INVALID_EDGE_WEIGHT), name_id(INVALID_NAMEID) {}
|
||||
TarjanEdgeData(unsigned distance, unsigned name_id) : distance(distance), name_id(name_id) {}
|
||||
unsigned distance;
|
||||
unsigned name_id;
|
||||
};
|
||||
|
||||
using StaticTestGraph = StaticGraph<TarjanEdgeData>;
|
||||
using DynamicTestGraph = StaticGraph<TarjanEdgeData>;
|
||||
using StaticEdge = StaticTestGraph::InputEdge;
|
||||
using DynamicEdge = DynamicTestGraph::InputEdge;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
std::vector<QueryNode> coordinate_list;
|
||||
std::vector<TurnRestriction> restriction_list;
|
||||
std::vector<NodeID> bollard_node_list;
|
||||
std::vector<NodeID> traffic_lights_list;
|
||||
|
||||
LogPolicy::GetInstance().Unmute();
|
||||
try
|
||||
{
|
||||
// enable logging
|
||||
if (argc < 3)
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << "usage:\n" << argv[0]
|
||||
<< " <osrm> <osrm.restrictions>";
|
||||
return -1;
|
||||
}
|
||||
|
||||
SimpleLogger().Write() << "Using restrictions from file: " << argv[2];
|
||||
std::ifstream restriction_ifstream(argv[2], std::ios::binary);
|
||||
const FingerPrint fingerprint_orig;
|
||||
FingerPrint fingerprint_loaded;
|
||||
restriction_ifstream.read(reinterpret_cast<char *>(&fingerprint_loaded),
|
||||
sizeof(FingerPrint));
|
||||
|
||||
// check fingerprint and warn if necessary
|
||||
if (!fingerprint_loaded.TestGraphUtil(fingerprint_orig))
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << argv[2] << " was prepared with a different build. "
|
||||
"Reprocess to get rid of this warning.";
|
||||
}
|
||||
|
||||
if (!restriction_ifstream.good())
|
||||
{
|
||||
throw osrm::exception("Could not access <osrm-restrictions> files");
|
||||
}
|
||||
uint32_t usable_restrictions = 0;
|
||||
restriction_ifstream.read(reinterpret_cast<char *>(&usable_restrictions), sizeof(uint32_t));
|
||||
restriction_list.resize(usable_restrictions);
|
||||
|
||||
// load restrictions
|
||||
if (usable_restrictions > 0)
|
||||
{
|
||||
restriction_ifstream.read(reinterpret_cast<char *>(&restriction_list[0]),
|
||||
usable_restrictions * sizeof(TurnRestriction));
|
||||
}
|
||||
restriction_ifstream.close();
|
||||
|
||||
std::ifstream input_stream(argv[1], std::ifstream::in | std::ifstream::binary);
|
||||
if (!input_stream.is_open())
|
||||
{
|
||||
throw osrm::exception("Cannot open osrm file");
|
||||
}
|
||||
|
||||
// load graph data
|
||||
std::vector<ImportEdge> edge_list;
|
||||
const NodeID number_of_nodes =
|
||||
readBinaryOSRMGraphFromStream(input_stream, edge_list, bollard_node_list,
|
||||
traffic_lights_list, &coordinate_list, restriction_list);
|
||||
input_stream.close();
|
||||
|
||||
BOOST_ASSERT_MSG(restriction_list.size() == usable_restrictions,
|
||||
"size of restriction_list changed");
|
||||
|
||||
SimpleLogger().Write() << restriction_list.size() << " restrictions, "
|
||||
<< bollard_node_list.size() << " bollard nodes, "
|
||||
<< traffic_lights_list.size() << " traffic lights";
|
||||
|
||||
traffic_lights_list.clear();
|
||||
traffic_lights_list.shrink_to_fit();
|
||||
|
||||
// Building an node-based graph
|
||||
std::vector<StaticEdge> static_graph_edge_list;
|
||||
std::vector<DynamicEdge> dynamic_graph_edge_list;
|
||||
for (const auto &input_edge : edge_list)
|
||||
{
|
||||
if (input_edge.source == input_edge.target)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (input_edge.forward)
|
||||
{
|
||||
static_graph_edge_list.emplace_back(input_edge.source, input_edge.target,
|
||||
(std::max)(input_edge.weight, 1),
|
||||
input_edge.name_id);
|
||||
dynamic_graph_edge_list.emplace_back(input_edge.source, input_edge.target,
|
||||
(std::max)(input_edge.weight, 1),
|
||||
input_edge.name_id);
|
||||
}
|
||||
if (input_edge.backward)
|
||||
{
|
||||
dynamic_graph_edge_list.emplace_back(input_edge.target, input_edge.source,
|
||||
(std::max)(input_edge.weight, 1),
|
||||
input_edge.name_id);
|
||||
static_graph_edge_list.emplace_back(input_edge.target, input_edge.source,
|
||||
(std::max)(input_edge.weight, 1),
|
||||
input_edge.name_id);
|
||||
}
|
||||
}
|
||||
edge_list.clear();
|
||||
edge_list.shrink_to_fit();
|
||||
BOOST_ASSERT_MSG(0 == edge_list.size() && 0 == edge_list.capacity(),
|
||||
"input edge vector not properly deallocated");
|
||||
|
||||
tbb::parallel_sort(static_graph_edge_list.begin(), static_graph_edge_list.end());
|
||||
tbb::parallel_sort(dynamic_graph_edge_list.begin(), dynamic_graph_edge_list.end());
|
||||
|
||||
auto static_graph =
|
||||
osrm::make_unique<StaticTestGraph>(number_of_nodes, static_graph_edge_list);
|
||||
auto dynamic_graph =
|
||||
osrm::make_unique<DynamicTestGraph>(number_of_nodes, dynamic_graph_edge_list);
|
||||
|
||||
SimpleLogger().Write() << "Starting static/dynamic graph comparison";
|
||||
|
||||
BOOST_ASSERT(static_graph->GetNumberOfNodes() == dynamic_graph->GetNumberOfNodes());
|
||||
BOOST_ASSERT(static_graph->GetNumberOfEdges() == dynamic_graph->GetNumberOfEdges());
|
||||
for (const auto node : osrm::irange(0u, static_graph->GetNumberOfNodes()))
|
||||
{
|
||||
const auto static_range = static_graph->GetAdjacentEdgeRange(node);
|
||||
const auto dynamic_range = dynamic_graph->GetAdjacentEdgeRange(node);
|
||||
SimpleLogger().Write() << "checking node " << node << "/"
|
||||
<< static_graph->GetNumberOfNodes();
|
||||
|
||||
BOOST_ASSERT(static_range.size() == dynamic_range.size());
|
||||
const auto static_begin = static_graph->BeginEdges(node);
|
||||
const auto dynamic_begin = dynamic_graph->BeginEdges(node);
|
||||
|
||||
// check raw interface
|
||||
for (const auto i : osrm::irange(0u, static_range.size()))
|
||||
{
|
||||
const auto static_target = static_graph->GetTarget(static_begin + i);
|
||||
const auto dynamic_target = dynamic_graph->GetTarget(dynamic_begin + i);
|
||||
BOOST_ASSERT(static_target == dynamic_target);
|
||||
|
||||
const auto static_data = static_graph->GetEdgeData(static_begin + i);
|
||||
const auto dynamic_data = dynamic_graph->GetEdgeData(dynamic_begin + i);
|
||||
|
||||
BOOST_ASSERT(static_data.distance == dynamic_data.distance);
|
||||
BOOST_ASSERT(static_data.name_id == dynamic_data.name_id);
|
||||
}
|
||||
|
||||
// check range interface
|
||||
std::vector<EdgeID> static_target_ids, dynamic_target_ids;
|
||||
std::vector<TarjanEdgeData> static_edge_data, dynamic_edge_data;
|
||||
for (const auto static_id : static_range)
|
||||
{
|
||||
static_target_ids.push_back(static_graph->GetTarget(static_id));
|
||||
static_edge_data.push_back(static_graph->GetEdgeData(static_id));
|
||||
}
|
||||
for (const auto dynamic_id : dynamic_range)
|
||||
{
|
||||
dynamic_target_ids.push_back(dynamic_graph->GetTarget(dynamic_id));
|
||||
dynamic_edge_data.push_back(dynamic_graph->GetEdgeData(dynamic_id));
|
||||
}
|
||||
BOOST_ASSERT(static_target_ids.size() == dynamic_target_ids.size());
|
||||
BOOST_ASSERT(std::equal(std::begin(static_target_ids), std::end(static_target_ids),
|
||||
std::begin(dynamic_target_ids)));
|
||||
}
|
||||
|
||||
SimpleLogger().Write() << "Graph comparison finished successfully";
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
SimpleLogger().Write(logWARNING) << "[exception] " << e.what();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user