Add osrm-util for inspecting various bits of the graph.
This commit is contained in:
parent
d068c7de59
commit
e0ab5f452e
@ -167,6 +167,7 @@ add_executable(osrm-customize src/tools/customize.cpp)
|
|||||||
add_executable(osrm-contract src/tools/contract.cpp)
|
add_executable(osrm-contract src/tools/contract.cpp)
|
||||||
add_executable(osrm-routed src/tools/routed.cpp $<TARGET_OBJECTS:SERVER> $<TARGET_OBJECTS:UTIL>)
|
add_executable(osrm-routed src/tools/routed.cpp $<TARGET_OBJECTS:SERVER> $<TARGET_OBJECTS:UTIL>)
|
||||||
add_executable(osrm-datastore src/tools/store.cpp $<TARGET_OBJECTS:MICROTAR> $<TARGET_OBJECTS:UTIL>)
|
add_executable(osrm-datastore src/tools/store.cpp $<TARGET_OBJECTS:MICROTAR> $<TARGET_OBJECTS:UTIL>)
|
||||||
|
add_executable(osrm-util src/tools/util.cpp $<TARGET_OBJECTS:SERVER> $<TARGET_OBJECTS:UTIL>)
|
||||||
add_library(osrm src/osrm/osrm.cpp $<TARGET_OBJECTS:ENGINE> $<TARGET_OBJECTS:STORAGE> $<TARGET_OBJECTS:MICROTAR> $<TARGET_OBJECTS:UTIL>)
|
add_library(osrm src/osrm/osrm.cpp $<TARGET_OBJECTS:ENGINE> $<TARGET_OBJECTS:STORAGE> $<TARGET_OBJECTS:MICROTAR> $<TARGET_OBJECTS:UTIL>)
|
||||||
add_library(osrm_contract src/osrm/contractor.cpp $<TARGET_OBJECTS:CONTRACTOR> $<TARGET_OBJECTS:UTIL>)
|
add_library(osrm_contract src/osrm/contractor.cpp $<TARGET_OBJECTS:CONTRACTOR> $<TARGET_OBJECTS:UTIL>)
|
||||||
add_library(osrm_extract src/osrm/extractor.cpp $<TARGET_OBJECTS:EXTRACTOR> $<TARGET_OBJECTS:MICROTAR> $<TARGET_OBJECTS:UTIL>)
|
add_library(osrm_extract src/osrm/extractor.cpp $<TARGET_OBJECTS:EXTRACTOR> $<TARGET_OBJECTS:MICROTAR> $<TARGET_OBJECTS:UTIL>)
|
||||||
@ -633,6 +634,7 @@ target_link_libraries(osrm-partition osrm_partition ${Boost_PROGRAM_OPTIONS_LIBR
|
|||||||
target_link_libraries(osrm-customize osrm_customize ${Boost_PROGRAM_OPTIONS_LIBRARY})
|
target_link_libraries(osrm-customize osrm_customize ${Boost_PROGRAM_OPTIONS_LIBRARY})
|
||||||
target_link_libraries(osrm-contract osrm_contract ${Boost_PROGRAM_OPTIONS_LIBRARY})
|
target_link_libraries(osrm-contract osrm_contract ${Boost_PROGRAM_OPTIONS_LIBRARY})
|
||||||
target_link_libraries(osrm-routed osrm ${Boost_PROGRAM_OPTIONS_LIBRARY} ${OPTIONAL_SOCKET_LIBS} ${ZLIB_LIBRARY})
|
target_link_libraries(osrm-routed osrm ${Boost_PROGRAM_OPTIONS_LIBRARY} ${OPTIONAL_SOCKET_LIBS} ${ZLIB_LIBRARY})
|
||||||
|
target_link_libraries(osrm-util osrm)
|
||||||
|
|
||||||
set(EXTRACTOR_LIBRARIES
|
set(EXTRACTOR_LIBRARIES
|
||||||
${BZIP2_LIBRARIES}
|
${BZIP2_LIBRARIES}
|
||||||
@ -736,6 +738,7 @@ set_property(TARGET osrm-partition PROPERTY INSTALL_RPATH_USE_LINK_PATH TRUE)
|
|||||||
set_property(TARGET osrm-contract PROPERTY INSTALL_RPATH_USE_LINK_PATH TRUE)
|
set_property(TARGET osrm-contract PROPERTY INSTALL_RPATH_USE_LINK_PATH TRUE)
|
||||||
set_property(TARGET osrm-datastore PROPERTY INSTALL_RPATH_USE_LINK_PATH TRUE)
|
set_property(TARGET osrm-datastore PROPERTY INSTALL_RPATH_USE_LINK_PATH TRUE)
|
||||||
set_property(TARGET osrm-routed PROPERTY INSTALL_RPATH_USE_LINK_PATH TRUE)
|
set_property(TARGET osrm-routed PROPERTY INSTALL_RPATH_USE_LINK_PATH TRUE)
|
||||||
|
set_property(TARGET osrm-util PROPERTY INSTALL_RPATH_USE_LINK_PATH TRUE)
|
||||||
|
|
||||||
file(GLOB VariantGlob third_party/variant/include/mapbox/*.hpp)
|
file(GLOB VariantGlob third_party/variant/include/mapbox/*.hpp)
|
||||||
file(GLOB LibraryGlob include/osrm/*.hpp)
|
file(GLOB LibraryGlob include/osrm/*.hpp)
|
||||||
@ -761,6 +764,7 @@ install(TARGETS osrm-customize DESTINATION bin)
|
|||||||
install(TARGETS osrm-contract DESTINATION bin)
|
install(TARGETS osrm-contract DESTINATION bin)
|
||||||
install(TARGETS osrm-datastore DESTINATION bin)
|
install(TARGETS osrm-datastore DESTINATION bin)
|
||||||
install(TARGETS osrm-routed DESTINATION bin)
|
install(TARGETS osrm-routed DESTINATION bin)
|
||||||
|
install(TARGETS osrm-util DESTINATION bin)
|
||||||
install(TARGETS osrm DESTINATION lib)
|
install(TARGETS osrm DESTINATION lib)
|
||||||
install(TARGETS osrm_extract DESTINATION lib)
|
install(TARGETS osrm_extract DESTINATION lib)
|
||||||
install(TARGETS osrm_partition DESTINATION lib)
|
install(TARGETS osrm_partition DESTINATION lib)
|
||||||
|
|||||||
@ -372,45 +372,6 @@ inline auto make_filtered_graph_view(const SharedDataIndex &index,
|
|||||||
auto edge_list = make_vector_view<contractor::QueryGraphView::EdgeArrayEntry>(
|
auto edge_list = make_vector_view<contractor::QueryGraphView::EdgeArrayEntry>(
|
||||||
index, name + "/contracted_graph/edge_array");
|
index, name + "/contracted_graph/edge_array");
|
||||||
|
|
||||||
// DEBUG - dump CH
|
|
||||||
std::cout << "digraph {" << std::endl;
|
|
||||||
for (std::size_t i = 0; i < node_list.size(); i++)
|
|
||||||
{
|
|
||||||
for (auto edge = node_list[i].first_edge;
|
|
||||||
edge < (i == node_list.size() - 1 ? edge_list.size() : node_list[i + 1].first_edge);
|
|
||||||
edge++)
|
|
||||||
{
|
|
||||||
const auto &e = edge_list[edge];
|
|
||||||
if (e.data.forward)
|
|
||||||
{
|
|
||||||
std::cout << i << " -> " << e.target;
|
|
||||||
std::cout << "[";
|
|
||||||
std::cout << "label=\"↑" << e.data.weight << "\",weight=\"" << e.data.weight
|
|
||||||
<< "\"";
|
|
||||||
if (e.data.maneuver_restricted)
|
|
||||||
{
|
|
||||||
std::cout << ",color=red,penwidth=3.0";
|
|
||||||
}
|
|
||||||
std::cout << "];";
|
|
||||||
std::cout << std::endl;
|
|
||||||
}
|
|
||||||
if (e.data.backward)
|
|
||||||
{
|
|
||||||
std::cout << e.target << " -> " << i;
|
|
||||||
std::cout << "[";
|
|
||||||
std::cout << "label=\"↓" << e.data.weight << "\",weight=\"" << e.data.weight
|
|
||||||
<< "\"";
|
|
||||||
if (e.data.maneuver_restricted)
|
|
||||||
{
|
|
||||||
std::cout << ",color=red,penwidth=3.0";
|
|
||||||
}
|
|
||||||
std::cout << "];";
|
|
||||||
std::cout << std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
std::cout << "}" << std::endl;
|
|
||||||
|
|
||||||
return util::FilteredGraphView<contractor::QueryGraphView>({node_list, edge_list}, edge_filter);
|
return util::FilteredGraphView<contractor::QueryGraphView>({node_list, edge_list}, edge_filter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,143 +0,0 @@
|
|||||||
#include "storage/serialization.hpp"
|
|
||||||
#include "storage/shared_memory.hpp"
|
|
||||||
#include "storage/shared_monitor.hpp"
|
|
||||||
#include "storage/storage.hpp"
|
|
||||||
|
|
||||||
#include "osrm/exception.hpp"
|
|
||||||
#include "util/log.hpp"
|
|
||||||
#include "util/meminfo.hpp"
|
|
||||||
#include "util/typedefs.hpp"
|
|
||||||
#include "util/version.hpp"
|
|
||||||
|
|
||||||
#include <boost/filesystem.hpp>
|
|
||||||
#include <boost/program_options.hpp>
|
|
||||||
|
|
||||||
#include <csignal>
|
|
||||||
#include <cstdlib>
|
|
||||||
|
|
||||||
using namespace osrm;
|
|
||||||
|
|
||||||
// generate boost::program_options object for the routing part
|
|
||||||
bool generateDataStoreOptions(const int argc,
|
|
||||||
const char *argv[],
|
|
||||||
std::string &verbosity,
|
|
||||||
boost::filesystem::path &base_path,
|
|
||||||
int &max_wait,
|
|
||||||
std::string &dataset_name,
|
|
||||||
bool &list_datasets,
|
|
||||||
bool &list_blocks,
|
|
||||||
bool &only_metric)
|
|
||||||
{
|
|
||||||
// declare a group of options that will be allowed only on command line
|
|
||||||
boost::program_options::options_description generic_options("Options");
|
|
||||||
generic_options.add_options() //
|
|
||||||
("contraction-heirarchy,ch", "Dump CH graph")("cells,c", "Dump partition structure");
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
boost::program_options::store(
|
|
||||||
boost::program_options::command_line_parser(argc, argv, generic_options),
|
|
||||||
option_variables);
|
|
||||||
}
|
|
||||||
catch (const boost::program_options::error &e)
|
|
||||||
{
|
|
||||||
util::Log(logERROR) << e.what();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (option_variables.count("version"))
|
|
||||||
{
|
|
||||||
util::Log() << OSRM_VERSION;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (option_variables.count("help"))
|
|
||||||
{
|
|
||||||
util::Log() << visible_options;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (option_variables.count("remove-locks"))
|
|
||||||
{
|
|
||||||
removeLocks();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (option_variables.count("spring-clean"))
|
|
||||||
{
|
|
||||||
springClean();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
boost::program_options::notify(option_variables);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
[[noreturn]] void CleanupSharedBarriers(int signum)
|
|
||||||
{ // Here the lock state of named mutexes is unknown, make a hard cleanup
|
|
||||||
removeLocks();
|
|
||||||
std::_Exit(128 + signum);
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(const int argc, const char *argv[]) try
|
|
||||||
{
|
|
||||||
int signals[] = {SIGTERM, SIGSEGV, SIGINT, SIGILL, SIGABRT, SIGFPE};
|
|
||||||
for (auto sig : signals)
|
|
||||||
{
|
|
||||||
std::signal(sig, CleanupSharedBarriers);
|
|
||||||
}
|
|
||||||
|
|
||||||
util::LogPolicy::GetInstance().Unmute();
|
|
||||||
|
|
||||||
std::string verbosity;
|
|
||||||
boost::filesystem::path base_path;
|
|
||||||
int max_wait = -1;
|
|
||||||
std::string dataset_name;
|
|
||||||
bool list_datasets = false;
|
|
||||||
bool list_blocks = false;
|
|
||||||
bool only_metric = false;
|
|
||||||
if (!generateDataStoreOptions(argc,
|
|
||||||
argv,
|
|
||||||
verbosity,
|
|
||||||
base_path,
|
|
||||||
max_wait,
|
|
||||||
dataset_name,
|
|
||||||
list_datasets,
|
|
||||||
list_blocks,
|
|
||||||
only_metric))
|
|
||||||
{
|
|
||||||
return EXIT_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
util::LogPolicy::GetInstance().SetLevel(verbosity);
|
|
||||||
|
|
||||||
if (list_datasets || list_blocks)
|
|
||||||
{
|
|
||||||
listRegions(list_blocks);
|
|
||||||
return EXIT_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
storage::StorageConfig config(base_path);
|
|
||||||
if (!config.IsValid())
|
|
||||||
{
|
|
||||||
util::Log(logERROR) << "Config contains invalid file paths. Exiting!";
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
storage::Storage storage(std::move(config));
|
|
||||||
|
|
||||||
return storage.Run(max_wait, dataset_name, only_metric);
|
|
||||||
}
|
|
||||||
catch (const osrm::RuntimeError &e)
|
|
||||||
{
|
|
||||||
util::Log(logERROR) << e.what();
|
|
||||||
return e.GetCode();
|
|
||||||
}
|
|
||||||
catch (const std::bad_alloc &e)
|
|
||||||
{
|
|
||||||
util::DumpMemoryStats();
|
|
||||||
util::Log(logERROR) << "[exception] " << e.what();
|
|
||||||
util::Log(logERROR) << "Please provide more memory or disable locking the virtual "
|
|
||||||
"address space (note: this makes OSRM swap, i.e. slow)";
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
92
src/tools/util.cpp
Normal file
92
src/tools/util.cpp
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
#include "storage/shared_data_index.hpp"
|
||||||
|
#include "storage/view_factory.hpp"
|
||||||
|
|
||||||
|
#include "engine/datafacade/mmap_memory_allocator.hpp"
|
||||||
|
#include "osrm/storage_config.hpp"
|
||||||
|
|
||||||
|
#include <boost/filesystem.hpp>
|
||||||
|
#include <boost/program_options.hpp>
|
||||||
|
|
||||||
|
#include <csignal>
|
||||||
|
#include <cstdlib>
|
||||||
|
|
||||||
|
using namespace osrm;
|
||||||
|
|
||||||
|
void dump_ch(const std::string &filename) {
|
||||||
|
std::cout << filename << std::endl;
|
||||||
|
|
||||||
|
StorageConfig config(filename);
|
||||||
|
engine::datafacade::MMapMemoryAllocator allocator(config);
|
||||||
|
|
||||||
|
auto &index = allocator.GetIndex();
|
||||||
|
|
||||||
|
//auto exclude_prefix = name + "/exclude/" + std::to_string(exclude_index);
|
||||||
|
//auto edge_filter = make_vector_view<bool>(index, exclude_prefix + "/edge_filter");
|
||||||
|
auto node_list = storage::make_vector_view<contractor::QueryGraphView::NodeArrayEntry>(
|
||||||
|
index, "/ch/metrics/routability/contracted_graph/node_array");
|
||||||
|
auto edge_list = storage::make_vector_view<contractor::QueryGraphView::EdgeArrayEntry>(
|
||||||
|
index, "/ch/metrics/routability/contracted_graph/edge_array");
|
||||||
|
|
||||||
|
std::cout << "digraph {" << std::endl;
|
||||||
|
for (std::size_t i = 0; i < node_list.size(); i++)
|
||||||
|
{
|
||||||
|
for (auto edge = node_list[i].first_edge;
|
||||||
|
edge < (i == node_list.size() - 1 ? edge_list.size() : node_list[i + 1].first_edge);
|
||||||
|
edge++)
|
||||||
|
{
|
||||||
|
const auto &e = edge_list[edge];
|
||||||
|
if (e.data.forward)
|
||||||
|
{
|
||||||
|
std::cout << i << " -> " << e.target;
|
||||||
|
std::cout << "[";
|
||||||
|
std::cout << "label=\"↑" << e.data.weight << "\",weight=\"" << e.data.weight
|
||||||
|
<< "\"";
|
||||||
|
if (e.data.maneuver_restricted)
|
||||||
|
{
|
||||||
|
std::cout << ",color=red,penwidth=3.0";
|
||||||
|
}
|
||||||
|
std::cout << "];";
|
||||||
|
std::cout << std::endl;
|
||||||
|
}
|
||||||
|
if (e.data.backward)
|
||||||
|
{
|
||||||
|
std::cout << e.target << " -> " << i;
|
||||||
|
std::cout << "[";
|
||||||
|
std::cout << "label=\"↓" << e.data.weight << "\",weight=\"" << e.data.weight
|
||||||
|
<< "\"";
|
||||||
|
if (e.data.maneuver_restricted)
|
||||||
|
{
|
||||||
|
std::cout << ",color=red,penwidth=3.0";
|
||||||
|
}
|
||||||
|
std::cout << "];";
|
||||||
|
std::cout << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::cout << "}" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(const int argc, const char *argv[])
|
||||||
|
{
|
||||||
|
if (argc < 3) {
|
||||||
|
std::cerr << "Usage: " << argv[0] << " <command> <filename.osrm>" << std::endl;
|
||||||
|
std::cerr << std::endl;
|
||||||
|
std::cerr << "Commands:" << std::endl;
|
||||||
|
std::cerr << " dump-ch - dump the CH graph as a GraphViz .dot file" << std::endl;
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("dump-ch" != std::string(argv[1])) {
|
||||||
|
util::Log(logERROR) << "Invalid command '" << argv[1] << "'" << std::endl;
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
boost::filesystem::path p(std::string(argv[2]) + ".hsgr");
|
||||||
|
if (!boost::filesystem::exists(p)) {
|
||||||
|
util::Log(logERROR) << "File '" << argv[2] << "' does not exist" << std::endl;
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we make it to here, do it
|
||||||
|
dump_ch(std::string(argv[2]));
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user