Add update functionality to osrm-customize

All speed file flags are compatible with osrm-contract.
This commit is contained in:
Patrick Niklaus
2017-03-10 22:35:46 +00:00
committed by Patrick Niklaus
parent c6e9cc8024
commit 907f933a54
21 changed files with 266 additions and 93 deletions
+35 -7
View File
@@ -1,17 +1,22 @@
#include "customizer/customizer.hpp"
#include "customizer/cell_customizer.hpp"
#include "partition/edge_based_graph_reader.hpp"
#include "partition/io.hpp"
#include "customizer/edge_based_graph.hpp"
#include "customizer/io.hpp"
#include "partition/cell_storage.hpp"
#include "partition/edge_based_graph_reader.hpp"
#include "partition/io.hpp"
#include "partition/io.hpp"
#include "partition/multi_level_partition.hpp"
#include "updater/updater.hpp"
#include "util/log.hpp"
#include "util/timing_util.hpp"
namespace osrm
{
namespace customize
namespace customizer
{
template <typename Graph, typename Partition, typename CellStorage>
@@ -66,14 +71,32 @@ void CellStorageStatistics(const Graph &graph,
}
}
int Customizer::Run(const CustomizationConfig &config)
auto LoadAndUpdateEdgeExpandedGraph(const CustomizationConfig &config)
{
TIMER_START(loading_data);
auto edge_based_graph = partition::LoadEdgeBasedGraph(config.edge_based_graph_path.string());
updater::Updater updater(config.updater_config);
EdgeID num_nodes;
std::vector<extractor::EdgeBasedEdge> edge_based_edge_list;
std::tie(num_nodes, edge_based_edge_list) = updater.LoadAndUpdateEdgeExpandedGraph();
auto directed = partition::splitBidirectionalEdges(edge_based_edge_list);
auto tidied =
partition::prepareEdgesForUsageInGraph<StaticEdgeBasedGraphEdge>(std::move(directed));
auto edge_based_graph = std::make_unique<StaticEdgeBasedGraph>(num_nodes, std::move(tidied));
util::Log() << "Loaded edge based graph for mapping partition ids: "
<< edge_based_graph->GetNumberOfEdges() << " edges, "
<< edge_based_graph->GetNumberOfNodes() << " nodes";
return edge_based_graph;
}
int Customizer::Run(const CustomizationConfig &config)
{
TIMER_START(loading_data);
auto edge_based_graph = LoadAndUpdateEdgeExpandedGraph(config);
partition::MultiLevelPartition mlp;
partition::io::read(config.mld_partition_path, mlp);
@@ -93,10 +116,15 @@ int Customizer::Run(const CustomizationConfig &config)
TIMER_STOP(writing_mld_data);
util::Log() << "MLD customization writing took " << TIMER_SEC(writing_mld_data) << " seconds";
TIMER_START(writing_graph);
io::write(config.mld_graph_path, *edge_based_graph);
TIMER_STOP(writing_graph);
util::Log() << "Graph writing took " << TIMER_SEC(writing_graph) << " seconds";
CellStorageStatistics(*edge_based_graph, mlp, storage);
return 0;
}
} // namespace customize
} // namespace customizer$
} // namespace osrm
+27 -41
View File
@@ -1,5 +1,6 @@
#include "storage/storage.hpp"
#include "contractor/query_edge.hpp"
#include "customizer/edge_based_graph.hpp"
#include "extractor/compressed_edge_container.hpp"
#include "extractor/edge_based_edge.hpp"
#include "extractor/guidance/turn_instruction.hpp"
@@ -441,23 +442,26 @@ void Storage::PopulateLayout(DataLayout &layout)
layout.SetBlockSize<char>(DataLayout::MLD_CELL_LEVEL_OFFSETS, 0);
}
if (boost::filesystem::exists(config.edge_based_graph_path))
if (boost::filesystem::exists(config.mld_graph_path))
{
io::FileReader ebg_file(config.edge_based_graph_path,
io::FileReader::VerifyFingerprint);
io::FileReader reader(config.mld_graph_path, io::FileReader::VerifyFingerprint);
const auto num_edges = ebg_file.ReadElementCount64();
const auto num_nodes = ebg_file.ReadOne<EdgeID>() + 1;
const auto num_nodes =
reader.ReadVectorSize<customizer::StaticEdgeBasedGraph::NodeArrayEntry>();
const auto num_edges =
reader.ReadVectorSize<customizer::StaticEdgeBasedGraph::EdgeArrayEntry>();
layout.SetBlockSize<EdgeBasedGraph::NodeArrayEntry>(DataLayout::MLD_GRAPH_NODE_LIST,
num_nodes + 1);
layout.SetBlockSize<EdgeBasedGraph::EdgeArrayEntry>(DataLayout::MLD_GRAPH_EDGE_LIST,
2 * num_edges);
layout.SetBlockSize<customizer::StaticEdgeBasedGraph::NodeArrayEntry>(
DataLayout::MLD_GRAPH_NODE_LIST, num_nodes);
layout.SetBlockSize<customizer::StaticEdgeBasedGraph::EdgeArrayEntry>(
DataLayout::MLD_GRAPH_EDGE_LIST, num_edges);
}
else
{
layout.SetBlockSize<char>(DataLayout::MLD_GRAPH_NODE_LIST, 0);
layout.SetBlockSize<char>(DataLayout::MLD_GRAPH_EDGE_LIST, 0);
layout.SetBlockSize<customizer::StaticEdgeBasedGraph::NodeArrayEntry>(
DataLayout::MLD_GRAPH_NODE_LIST, 0);
layout.SetBlockSize<customizer::StaticEdgeBasedGraph::EdgeArrayEntry>(
DataLayout::MLD_GRAPH_EDGE_LIST, 0);
}
}
}
@@ -929,39 +933,21 @@ void Storage::PopulateData(const DataLayout &layout, char *memory_ptr)
reader.ReadInto(mld_cell_level_offsets_ptr, size);
}
if (boost::filesystem::exists(config.edge_based_graph_path))
if (boost::filesystem::exists(config.mld_graph_path))
{
io::FileReader reader(config.edge_based_graph_path, io::FileReader::VerifyFingerprint);
io::FileReader reader(config.mld_graph_path, io::FileReader::VerifyFingerprint);
const auto number_of_edges = reader.ReadElementCount64();
const auto number_of_nodes = reader.ReadOne<EdgeID>() + 1;
std::vector<extractor::EdgeBasedEdge> original_edges(number_of_edges);
reader.ReadInto(original_edges);
auto nodes_ptr =
layout.GetBlockPtr<customizer::StaticEdgeBasedGraph::NodeArrayEntry, true>(
memory_ptr, DataLayout::MLD_GRAPH_NODE_LIST);
auto edges_ptr =
layout.GetBlockPtr<customizer::StaticEdgeBasedGraph::EdgeArrayEntry, true>(
memory_ptr, DataLayout::MLD_GRAPH_EDGE_LIST);
// FIXME: move graph pre-processing to a pre-processing tool #3783
original_edges = partition::splitBidirectionalEdges(std::move(original_edges));
auto edges = partition::prepareEdgesForUsageInGraph(std::move(original_edges));
BOOST_ASSERT(edges.size() <= 2 * number_of_edges);
auto nodes_ptr = layout.GetBlockPtr<EdgeBasedGraph::NodeArrayEntry, true>(
memory_ptr, DataLayout::MLD_GRAPH_NODE_LIST);
auto edges_ptr = layout.GetBlockPtr<EdgeBasedGraph::EdgeArrayEntry, true>(
memory_ptr, DataLayout::MLD_GRAPH_EDGE_LIST);
EdgeBasedGraph::EdgeIterator edge = 0;
for (const auto node : util::irange(0u, number_of_nodes + 1))
{
EdgeBasedGraph::EdgeIterator last_edge = edge;
while (edge < edges.size() && edges[edge].source == node)
{
edges_ptr[edge].target = edges[edge].target;
edges_ptr[edge].data = edges[edge].data;
++edge;
}
nodes_ptr[node].first_edge = last_edge;
}
BOOST_ASSERT(edge == edges.size());
auto num_nodes = reader.ReadElementCount64();
reader.ReadInto(nodes_ptr, num_nodes);
auto num_edges = reader.ReadElementCount64();
reader.ReadInto(edges_ptr, num_edges);
}
}
}
+2 -2
View File
@@ -36,7 +36,7 @@ StorageConfig::StorageConfig(const boost::filesystem::path &base)
intersection_class_path{base.string() + ".icd"}, turn_lane_data_path{base.string() + ".tld"},
turn_lane_description_path{base.string() + ".tls"},
mld_partition_path{base.string() + ".partition"}, mld_storage_path{base.string() + ".cells"},
edge_based_graph_path{base.string() + ".ebg"}
mld_graph_path{base.string() + ".mldgr"}
{
}
@@ -65,7 +65,7 @@ bool StorageConfig::IsValid() const
CheckFileList({hsgr_data_path, core_data_path});
// MLD files
CheckFileList({mld_partition_path, mld_storage_path, edge_based_graph_path});
CheckFileList({mld_partition_path, mld_storage_path, mld_graph_path});
return true;
}
+21 -4
View File
@@ -21,7 +21,7 @@ enum class return_code : unsigned
};
return_code
parseArguments(int argc, char *argv[], customize::CustomizationConfig &customization_config)
parseArguments(int argc, char *argv[], customizer::CustomizationConfig &customization_config)
{
// declare a group of options that will be allowed only on command line
boost::program_options::options_description generic_options("Options");
@@ -34,7 +34,24 @@ parseArguments(int argc, char *argv[], customize::CustomizationConfig &customiza
("threads,t",
boost::program_options::value<unsigned int>(&customization_config.requested_num_threads)
->default_value(tbb::task_scheduler_init::default_num_threads()),
"Number of threads to use");
"Number of threads to use")(
"segment-speed-file",
boost::program_options::value<std::vector<std::string>>(
&customization_config.updater_config.segment_speed_lookup_paths)
->composing(),
"Lookup files containing nodeA, nodeB, speed data to adjust edge weights")(
"turn-penalty-file",
boost::program_options::value<std::vector<std::string>>(
&customization_config.updater_config.turn_penalty_lookup_paths)
->composing(),
"Lookup files containing from_, to_, via_nodes, and turn penalties to adjust turn "
"weights")("edge-weight-updates-over-factor",
boost::program_options::value<double>(
&customization_config.updater_config.log_edge_updates_factor)
->default_value(0.0),
"Use with `--segment-speed-file`. Provide an `x` factor, by which Extractor "
"will log edge "
"weights updated by more than this factor");
// hidden options, will be allowed on command line, but will not be
// shown to the user
@@ -99,7 +116,7 @@ parseArguments(int argc, char *argv[], customize::CustomizationConfig &customiza
int main(int argc, char *argv[]) try
{
util::LogPolicy::GetInstance().Unmute();
customize::CustomizationConfig customization_config;
customizer::CustomizationConfig customization_config;
const auto result = parseArguments(argc, argv, customization_config);
@@ -131,7 +148,7 @@ int main(int argc, char *argv[]) try
tbb::task_scheduler_init init(customization_config.requested_num_threads);
auto exitcode = customize::Customizer().Run(customization_config);
auto exitcode = customizer::Customizer().Run(customization_config);
util::DumpMemoryStats();
+10 -1
View File
@@ -162,6 +162,14 @@ void CheckWeightsConsistency(
}
#endif
Updater::NumNodesAndEdges Updater::LoadAndUpdateEdgeExpandedGraph() const
{
std::vector<extractor::EdgeBasedEdge> edge_based_edge_list;
std::vector<EdgeWeight> node_weights;
auto max_edge_id = Updater::LoadAndUpdateEdgeExpandedGraph(edge_based_edge_list, node_weights);
return std::make_tuple(max_edge_id + 1, std::move(edge_based_edge_list));
}
EdgeID
Updater::LoadAndUpdateEdgeExpandedGraph(std::vector<extractor::EdgeBasedEdge> &edge_based_edge_list,
std::vector<EdgeWeight> &node_weights) const
@@ -525,7 +533,8 @@ Updater::LoadAndUpdateEdgeExpandedGraph(std::vector<extractor::EdgeBasedEdge> &e
// Update the node-weight cache. This is the weight of the edge-based-node only,
// it doesn't include the turn. We may visit the same node multiple times, but
// we should always assign the same value here.
node_weights[inbuffer.source] = new_weight;
if (node_weights.size() > 0)
node_weights[inbuffer.source] = new_weight;
// We found a zero-speed edge, so we'll skip this whole edge-based-edge which
// effectively removes it from the routing network.