Refactor turn lane passing

This commit is contained in:
Patrick Niklaus 2017-06-16 12:35:04 +00:00 committed by Patrick Niklaus
parent 4f13208ce8
commit 37b8d3acd4
8 changed files with 78 additions and 95 deletions

View File

@ -83,8 +83,6 @@ class EdgeBasedGraphFactory
const extractor::PackedOSMIDs &osm_node_ids, const extractor::PackedOSMIDs &osm_node_ids,
ProfileProperties profile_properties, ProfileProperties profile_properties,
const util::NameTable &name_table, const util::NameTable &name_table,
std::vector<std::uint32_t> &turn_lane_offsets,
std::vector<guidance::TurnLaneType::Mask> &turn_lane_masks,
guidance::LaneDescriptionMap &lane_description_map); guidance::LaneDescriptionMap &lane_description_map);
void Run(ScriptingEnvironment &scripting_environment, void Run(ScriptingEnvironment &scripting_environment,
@ -150,8 +148,6 @@ class EdgeBasedGraphFactory
ProfileProperties profile_properties; ProfileProperties profile_properties;
const util::NameTable &name_table; const util::NameTable &name_table;
std::vector<std::uint32_t> &turn_lane_offsets;
std::vector<guidance::TurnLaneType::Mask> &turn_lane_masks;
guidance::LaneDescriptionMap &lane_description_map; guidance::LaneDescriptionMap &lane_description_map;
unsigned RenumberEdges(); unsigned RenumberEdges();

View File

@ -56,8 +56,8 @@ class Extractor
private: private:
ExtractorConfig config; ExtractorConfig config;
std::vector<TurnRestriction> ParseOSMData(ScriptingEnvironment &scripting_environment, std::tuple<guidance::LaneDescriptionMap, std::vector<TurnRestriction>>
const unsigned number_of_threads); ParseOSMData(ScriptingEnvironment &scripting_environment, const unsigned number_of_threads);
std::pair<std::size_t, EdgeID> std::pair<std::size_t, EdgeID>
BuildEdgeExpandedGraph(ScriptingEnvironment &scripting_environment, BuildEdgeExpandedGraph(ScriptingEnvironment &scripting_environment,
@ -69,7 +69,8 @@ class Extractor
std::vector<EdgeWeight> &edge_based_node_weights, std::vector<EdgeWeight> &edge_based_node_weights,
util::DeallocatingVector<EdgeBasedEdge> &edge_based_edge_list, util::DeallocatingVector<EdgeBasedEdge> &edge_based_edge_list,
const std::string &intersection_class_output_file, const std::string &intersection_class_output_file,
std::vector<TurnRestriction> &turn_restrictions); std::vector<TurnRestriction> &turn_restrictions,
guidance::LaneDescriptionMap &turn_lane_map);
void FindComponents(unsigned max_edge_id, void FindComponents(unsigned max_edge_id,
const util::DeallocatingVector<EdgeBasedEdge> &input_edge_list, const util::DeallocatingVector<EdgeBasedEdge> &input_edge_list,
const std::vector<EdgeBasedNodeSegment> &input_node_segments, const std::vector<EdgeBasedNodeSegment> &input_node_segments,
@ -90,20 +91,10 @@ class Extractor
const std::vector<util::guidance::BearingClass> &bearing_classes, const std::vector<util::guidance::BearingClass> &bearing_classes,
const std::vector<util::guidance::EntryClass> &entry_classes) const; const std::vector<util::guidance::EntryClass> &entry_classes) const;
void WriteTurnLaneData(const std::string &turn_lane_file) const;
// Writes compressed node based graph and its embedding into a file for osrm-partition to use. // Writes compressed node based graph and its embedding into a file for osrm-partition to use.
static void WriteCompressedNodeBasedGraph(const std::string &path, static void WriteCompressedNodeBasedGraph(const std::string &path,
const util::NodeBasedDynamicGraph &graph, const util::NodeBasedDynamicGraph &graph,
const std::vector<util::Coordinate> &coordiantes); const std::vector<util::Coordinate> &coordiantes);
// globals persisting during the extraction process and the graph generation process
// during turn lane analysis, we might have to combine lanes for roads that are modelled as two
// but are more or less experienced as one. This can be due to solid lines in between lanes, for
// example, that genereate a small separation between them. As a result, we might have to
// augment the turn lane map during processing, further adding more types.
guidance::LaneDescriptionMap turn_lane_map;
}; };
} }
} }

View File

@ -73,8 +73,6 @@ class TurnLaneHandler
typedef std::vector<TurnLaneData> LaneDataVector; typedef std::vector<TurnLaneData> LaneDataVector;
TurnLaneHandler(const util::NodeBasedDynamicGraph &node_based_graph, TurnLaneHandler(const util::NodeBasedDynamicGraph &node_based_graph,
const std::vector<std::uint32_t> &turn_lane_offsets,
const std::vector<TurnLaneType::Mask> &turn_lane_masks,
LaneDescriptionMap &lane_description_map, LaneDescriptionMap &lane_description_map,
const TurnAnalysis &turn_analysis, const TurnAnalysis &turn_analysis,
util::guidance::LaneDataIdMap &id_map); util::guidance::LaneDataIdMap &id_map);
@ -90,8 +88,8 @@ class TurnLaneHandler
// we need to be able to look at previous intersections to, in some cases, find the correct turn // we need to be able to look at previous intersections to, in some cases, find the correct turn
// lanes for a turn // lanes for a turn
const util::NodeBasedDynamicGraph &node_based_graph; const util::NodeBasedDynamicGraph &node_based_graph;
const std::vector<std::uint32_t> &turn_lane_offsets; std::vector<std::uint32_t> turn_lane_offsets;
const std::vector<TurnLaneType::Mask> &turn_lane_masks; std::vector<TurnLaneType::Mask> turn_lane_masks;
LaneDescriptionMap &lane_description_map; LaneDescriptionMap &lane_description_map;
const TurnAnalysis &turn_analysis; const TurnAnalysis &turn_analysis;
util::guidance::LaneDataIdMap &id_map; util::guidance::LaneDataIdMap &id_map;

View File

@ -7,6 +7,7 @@
#include <string> #include <string>
#include <unordered_map> #include <unordered_map>
#include <vector> #include <vector>
#include <numeric> //partial_sum
#include <boost/functional/hash.hpp> #include <boost/functional/hash.hpp>
@ -99,6 +100,34 @@ typedef util::ConcurrentIDMap<guidance::TurnLaneDescription,
guidance::TurnLaneDescription_hash> guidance::TurnLaneDescription_hash>
LaneDescriptionMap; LaneDescriptionMap;
inline std::tuple<std::vector<std::uint32_t>, std::vector<TurnLaneType::Mask>>
transformTurnLaneMapIntoArrays(const LaneDescriptionMap &turn_lane_map)
{
// could use some additional capacity? To avoid a copy during processing, though small data so
// probably not that important.
//
// From the map, we construct an adjacency array that allows access from all IDs to the list of
// associated Turn Lane Masks.
//
// turn lane offsets points into the locations of the turn_lane_masks array. We use a standard
// adjacency array like structure to store the turn lane masks.
std::vector<std::uint32_t> turn_lane_offsets(turn_lane_map.data.size() +
2); // empty ID + sentinel
for (auto entry = turn_lane_map.data.begin(); entry != turn_lane_map.data.end(); ++entry)
turn_lane_offsets[entry->second + 1] = entry->first.size();
// inplace prefix sum
std::partial_sum(turn_lane_offsets.begin(), turn_lane_offsets.end(), turn_lane_offsets.begin());
// allocate the current masks
std::vector<guidance::TurnLaneType::Mask> turn_lane_masks(turn_lane_offsets.back());
for (auto entry = turn_lane_map.data.begin(); entry != turn_lane_map.data.end(); ++entry)
std::copy(entry->first.begin(),
entry->first.end(),
turn_lane_masks.begin() + turn_lane_offsets[entry->second]);
return std::make_tuple(std::move(turn_lane_offsets), std::move(turn_lane_masks));
}
} // guidance } // guidance
} // extractor } // extractor
} // osrm } // osrm

View File

@ -27,6 +27,23 @@ struct ConcurrentIDMap
std::unordered_map<KeyType, ValueType, HashType> data; std::unordered_map<KeyType, ValueType, HashType> data;
mutable UpgradableMutex mutex; mutable UpgradableMutex mutex;
ConcurrentIDMap() = default;
ConcurrentIDMap(ConcurrentIDMap &&other)
{
ScopedWriterLock other_lock{other.mutex};
ScopedWriterLock lock{mutex};
data = std::move(other.data);
}
ConcurrentIDMap& operator=(ConcurrentIDMap &&other)
{
ScopedWriterLock other_lock{other.mutex};
ScopedWriterLock lock{mutex};
data = std::move(other.data);
return *this;
}
const ValueType ConcurrentFindOrAdd(const KeyType &key) const ValueType ConcurrentFindOrAdd(const KeyType &key)
{ {
{ {

View File

@ -51,15 +51,12 @@ EdgeBasedGraphFactory::EdgeBasedGraphFactory(
const extractor::PackedOSMIDs &osm_node_ids, const extractor::PackedOSMIDs &osm_node_ids,
ProfileProperties profile_properties, ProfileProperties profile_properties,
const util::NameTable &name_table, const util::NameTable &name_table,
std::vector<std::uint32_t> &turn_lane_offsets,
std::vector<guidance::TurnLaneType::Mask> &turn_lane_masks,
guidance::LaneDescriptionMap &lane_description_map) guidance::LaneDescriptionMap &lane_description_map)
: m_max_edge_id(0), m_coordinates(coordinates), m_osm_node_ids(osm_node_ids), : m_max_edge_id(0), m_coordinates(coordinates), m_osm_node_ids(osm_node_ids),
m_node_based_graph(std::move(node_based_graph)), m_node_based_graph(std::move(node_based_graph)),
m_restriction_map(std::move(restriction_map)), m_barrier_nodes(barrier_nodes), m_restriction_map(std::move(restriction_map)), m_barrier_nodes(barrier_nodes),
m_traffic_lights(traffic_lights), m_compressed_edge_container(compressed_edge_container), m_traffic_lights(traffic_lights), m_compressed_edge_container(compressed_edge_container),
profile_properties(std::move(profile_properties)), name_table(name_table), profile_properties(std::move(profile_properties)), name_table(name_table),
turn_lane_offsets(turn_lane_offsets), turn_lane_masks(turn_lane_masks),
lane_description_map(lane_description_map) lane_description_map(lane_description_map)
{ {
} }
@ -352,8 +349,6 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
util::guidance::LaneDataIdMap lane_data_map; util::guidance::LaneDataIdMap lane_data_map;
guidance::lanes::TurnLaneHandler turn_lane_handler(*m_node_based_graph, guidance::lanes::TurnLaneHandler turn_lane_handler(*m_node_based_graph,
turn_lane_offsets,
turn_lane_masks,
lane_description_map, lane_description_map,
turn_analysis, turn_analysis,
lane_data_map); lane_data_map);

View File

@ -52,7 +52,6 @@
#include <iostream> #include <iostream>
#include <iterator> #include <iterator>
#include <memory> #include <memory>
#include <numeric> //partial_sum
#include <thread> #include <thread>
#include <tuple> #include <tuple>
#include <type_traits> #include <type_traits>
@ -64,37 +63,6 @@ namespace osrm
namespace extractor namespace extractor
{ {
namespace
{
std::tuple<std::vector<std::uint32_t>, std::vector<guidance::TurnLaneType::Mask>>
transformTurnLaneMapIntoArrays(const guidance::LaneDescriptionMap &turn_lane_map)
{
// could use some additional capacity? To avoid a copy during processing, though small data so
// probably not that important.
//
// From the map, we construct an adjacency array that allows access from all IDs to the list of
// associated Turn Lane Masks.
//
// turn lane offsets points into the locations of the turn_lane_masks array. We use a standard
// adjacency array like structure to store the turn lane masks.
std::vector<std::uint32_t> turn_lane_offsets(turn_lane_map.data.size() +
2); // empty ID + sentinel
for (auto entry = turn_lane_map.data.begin(); entry != turn_lane_map.data.end(); ++entry)
turn_lane_offsets[entry->second + 1] = entry->first.size();
// inplace prefix sum
std::partial_sum(turn_lane_offsets.begin(), turn_lane_offsets.end(), turn_lane_offsets.begin());
// allocate the current masks
std::vector<guidance::TurnLaneType::Mask> turn_lane_masks(turn_lane_offsets.back());
for (auto entry = turn_lane_map.data.begin(); entry != turn_lane_map.data.end(); ++entry)
std::copy(entry->first.begin(),
entry->first.end(),
turn_lane_masks.begin() + turn_lane_offsets[entry->second]);
return std::make_tuple(std::move(turn_lane_offsets), std::move(turn_lane_masks));
}
} // namespace
/** /**
* TODO: Refactor this function into smaller functions for better readability. * TODO: Refactor this function into smaller functions for better readability.
* *
@ -123,7 +91,10 @@ int Extractor::run(ScriptingEnvironment &scripting_environment)
tbb::task_scheduler_init init(number_of_threads ? number_of_threads tbb::task_scheduler_init init(number_of_threads ? number_of_threads
: tbb::task_scheduler_init::automatic); : tbb::task_scheduler_init::automatic);
auto turn_restrictions = ParseOSMData(scripting_environment, number_of_threads); guidance::LaneDescriptionMap turn_lane_map;
std::vector<TurnRestriction> turn_restrictions;
std::tie(turn_lane_map, turn_restrictions) =
ParseOSMData(scripting_environment, number_of_threads);
// Transform the node-based graph that OSM is based on into an edge-based graph // Transform the node-based graph that OSM is based on into an edge-based graph
// that is better for routing. Every edge becomes a node, and every valid // that is better for routing. Every edge becomes a node, and every valid
@ -149,7 +120,8 @@ int Extractor::run(ScriptingEnvironment &scripting_environment)
edge_based_node_weights, edge_based_node_weights,
edge_based_edge_list, edge_based_edge_list,
config.intersection_class_data_output_path, config.intersection_class_data_output_path,
turn_restrictions); turn_restrictions,
turn_lane_map);
auto number_of_node_based_nodes = graph_size.first; auto number_of_node_based_nodes = graph_size.first;
auto max_edge_id = graph_size.second; auto max_edge_id = graph_size.second;
@ -201,7 +173,8 @@ int Extractor::run(ScriptingEnvironment &scripting_environment)
return 0; return 0;
} }
std::vector<TurnRestriction> Extractor::ParseOSMData(ScriptingEnvironment &scripting_environment, std::tuple<guidance::LaneDescriptionMap, std::vector<TurnRestriction>>
Extractor::ParseOSMData(ScriptingEnvironment &scripting_environment,
const unsigned number_of_threads) const unsigned number_of_threads)
{ {
TIMER_START(extracting); TIMER_START(extracting);
@ -332,6 +305,7 @@ std::vector<TurnRestriction> Extractor::ParseOSMData(ScriptingEnvironment &scrip
<< " ways, and " << number_of_relations << " relations"; << " ways, and " << number_of_relations << " relations";
// take control over the turn lane map // take control over the turn lane map
guidance::LaneDescriptionMap turn_lane_map;
turn_lane_map.data = extractor_callbacks->moveOutLaneDescriptionMap().data; turn_lane_map.data = extractor_callbacks->moveOutLaneDescriptionMap().data;
extractor_callbacks.reset(); extractor_callbacks.reset();
@ -353,7 +327,8 @@ std::vector<TurnRestriction> Extractor::ParseOSMData(ScriptingEnvironment &scrip
TIMER_STOP(extracting); TIMER_STOP(extracting);
util::Log() << "extraction finished after " << TIMER_SEC(extracting) << "s"; util::Log() << "extraction finished after " << TIMER_SEC(extracting) << "s";
return extraction_containers.unconditional_turn_restrictions; return std::make_tuple(std::move(turn_lane_map),
std::move(extraction_containers.unconditional_turn_restrictions));
} }
void Extractor::FindComponents(unsigned max_edge_id, void Extractor::FindComponents(unsigned max_edge_id,
@ -459,7 +434,8 @@ Extractor::BuildEdgeExpandedGraph(ScriptingEnvironment &scripting_environment,
std::vector<EdgeWeight> &edge_based_node_weights, std::vector<EdgeWeight> &edge_based_node_weights,
util::DeallocatingVector<EdgeBasedEdge> &edge_based_edge_list, util::DeallocatingVector<EdgeBasedEdge> &edge_based_edge_list,
const std::string &intersection_class_output_file, const std::string &intersection_class_output_file,
std::vector<TurnRestriction> &turn_restrictions) std::vector<TurnRestriction> &turn_restrictions,
guidance::LaneDescriptionMap &turn_lane_map)
{ {
std::unordered_set<NodeID> barrier_nodes; std::unordered_set<NodeID> barrier_nodes;
std::unordered_set<NodeID> traffic_lights; std::unordered_set<NodeID> traffic_lights;
@ -478,12 +454,6 @@ Extractor::BuildEdgeExpandedGraph(ScriptingEnvironment &scripting_environment,
util::NameTable name_table(config.names_file_name); util::NameTable name_table(config.names_file_name);
// could use some additional capacity? To avoid a copy during processing, though small data so
// probably not that important.
std::vector<std::uint32_t> turn_lane_offsets;
std::vector<guidance::TurnLaneType::Mask> turn_lane_masks;
std::tie(turn_lane_offsets, turn_lane_masks) = transformTurnLaneMapIntoArrays(turn_lane_map);
EdgeBasedGraphFactory edge_based_graph_factory( EdgeBasedGraphFactory edge_based_graph_factory(
node_based_graph, node_based_graph,
compressed_edge_container, compressed_edge_container,
@ -494,8 +464,6 @@ Extractor::BuildEdgeExpandedGraph(ScriptingEnvironment &scripting_environment,
osm_node_ids, osm_node_ids,
scripting_environment.GetProfileProperties(), scripting_environment.GetProfileProperties(),
name_table, name_table,
turn_lane_offsets,
turn_lane_masks,
turn_lane_map); turn_lane_map);
edge_based_graph_factory.Run(scripting_environment, edge_based_graph_factory.Run(scripting_environment,
@ -530,7 +498,14 @@ Extractor::BuildEdgeExpandedGraph(ScriptingEnvironment &scripting_environment,
config.compressed_node_based_graph_output_path, *node_based_graph, coordinates); config.compressed_node_based_graph_output_path, *node_based_graph, coordinates);
}); });
WriteTurnLaneData(config.turn_lane_descriptions_file_name); {
std::vector<std::uint32_t> turn_lane_offsets;
std::vector<guidance::TurnLaneType::Mask> turn_lane_masks;
std::tie(turn_lane_offsets, turn_lane_masks) =
guidance::transformTurnLaneMapIntoArrays(turn_lane_map);
files::writeTurnLaneDescriptions(
config.turn_lane_descriptions_file_name, turn_lane_offsets, turn_lane_masks);
}
files::writeSegmentData(config.geometry_output_path, files::writeSegmentData(config.geometry_output_path,
*compressed_edge_container.ToSegmentData()); *compressed_edge_container.ToSegmentData());
@ -640,22 +615,6 @@ void Extractor::WriteIntersectionClassificationData(
<< " entry classes and " << total_bearings << " bearing values."; << " entry classes and " << total_bearings << " bearing values.";
} }
void Extractor::WriteTurnLaneData(const std::string &turn_lane_file) const
{
// Write the turn lane data to file
std::vector<std::uint32_t> turn_lane_offsets;
std::vector<guidance::TurnLaneType::Mask> turn_lane_masks;
std::tie(turn_lane_offsets, turn_lane_masks) = transformTurnLaneMapIntoArrays(turn_lane_map);
util::Log() << "Writing turn lane masks...";
TIMER_START(turn_lane_timer);
files::writeTurnLaneDescriptions(turn_lane_file, turn_lane_offsets, turn_lane_masks);
TIMER_STOP(turn_lane_timer);
util::Log() << "done (" << TIMER_SEC(turn_lane_timer) << ")";
}
void Extractor::WriteCompressedNodeBasedGraph(const std::string &path, void Extractor::WriteCompressedNodeBasedGraph(const std::string &path,
const util::NodeBasedDynamicGraph &graph, const util::NodeBasedDynamicGraph &graph,
const std::vector<util::Coordinate> &coordinates) const std::vector<util::Coordinate> &coordinates)

View File

@ -34,15 +34,13 @@ std::size_t getNumberOfTurns(const Intersection &intersection)
} // namespace } // namespace
TurnLaneHandler::TurnLaneHandler(const util::NodeBasedDynamicGraph &node_based_graph, TurnLaneHandler::TurnLaneHandler(const util::NodeBasedDynamicGraph &node_based_graph,
const std::vector<std::uint32_t> &turn_lane_offsets,
const std::vector<TurnLaneType::Mask> &turn_lane_masks,
LaneDescriptionMap &lane_description_map, LaneDescriptionMap &lane_description_map,
const TurnAnalysis &turn_analysis, const TurnAnalysis &turn_analysis,
util::guidance::LaneDataIdMap &id_map) util::guidance::LaneDataIdMap &id_map)
: node_based_graph(node_based_graph), turn_lane_offsets(turn_lane_offsets), : node_based_graph(node_based_graph), lane_description_map(lane_description_map),
turn_lane_masks(turn_lane_masks), lane_description_map(lane_description_map),
turn_analysis(turn_analysis), id_map(id_map) turn_analysis(turn_analysis), id_map(id_map)
{ {
std::tie(turn_lane_offsets, turn_lane_masks) = transformTurnLaneMapIntoArrays(lane_description_map);
count_handled = count_called = 0; count_handled = count_called = 0;
} }