Use immutable node-based-graph for segregated edges.

This commit is contained in:
vng
2017-11-09 16:37:16 +03:00
committed by Michael Krasnyk
parent 32e6ccb037
commit 90e361c3dc
6 changed files with 25 additions and 21 deletions
+6 -4
View File
@@ -67,12 +67,13 @@ EdgeBasedGraphFactory::EdgeBasedGraphFactory(
const std::unordered_set<NodeID> &traffic_lights,
const std::vector<util::Coordinate> &coordinates,
const util::NameTable &name_table,
const std::unordered_set<EdgeID> &segregated_edges,
guidance::LaneDescriptionMap &lane_description_map)
: m_edge_based_node_container(node_data_container), m_number_of_edge_based_nodes(0),
m_coordinates(coordinates), m_node_based_graph(std::move(node_based_graph)),
m_barrier_nodes(barrier_nodes), m_traffic_lights(traffic_lights),
m_compressed_edge_container(compressed_edge_container), name_table(name_table),
lane_description_map(lane_description_map)
segregated_edges(segregated_edges), lane_description_map(lane_description_map)
{
}
@@ -165,7 +166,7 @@ NBGToEBG EdgeBasedGraphFactory::InsertEdgeBasedNode(const NodeID node_u, const N
m_edge_based_node_container.nodes[nbe_to_ebn_mapping[edge_id_1]].annotation_id =
forward_data.annotation_data;
m_edge_based_node_container.nodes[nbe_to_ebn_mapping[edge_id_1]].segregated =
forward_data.segregated;
segregated_edges.count(edge_id_1) > 0;
if (nbe_to_ebn_mapping[edge_id_2] != SPECIAL_EDGEID)
{
@@ -174,7 +175,7 @@ NBGToEBG EdgeBasedGraphFactory::InsertEdgeBasedNode(const NodeID node_u, const N
m_edge_based_node_container.nodes[nbe_to_ebn_mapping[edge_id_2]].annotation_id =
reverse_data.annotation_data;
m_edge_based_node_container.nodes[nbe_to_ebn_mapping[edge_id_2]].segregated =
reverse_data.segregated;
segregated_edges.count(edge_id_2) > 0;
}
// Add segments of edge-based nodes
@@ -371,7 +372,8 @@ EdgeBasedGraphFactory::GenerateEdgeExpandedNodes(const WayRestrictionMap &way_re
edge_data.geometry_id;
m_edge_based_node_container.nodes[edge_based_node_id].annotation_id =
edge_data.annotation_data;
m_edge_based_node_container.nodes[edge_based_node_id].segregated = edge_data.segregated;
m_edge_based_node_container.nodes[edge_based_node_id].segregated =
segregated_edges.count(eid) > 0;
m_edge_based_node_weights.push_back(m_edge_based_node_weights[eid]);
+12 -12
View File
@@ -220,11 +220,11 @@ int Extractor::run(ScriptingEnvironment &scripting_environment)
util::Log() << "Find segregated edges in node-based graph ..." << std::flush;
TIMER_START(segregated);
const size_t segregated_count = FindSegregatedNodes(node_based_graph_factory);
auto segregated_edges = FindSegregatedNodes(node_based_graph_factory);
TIMER_STOP(segregated);
util::Log() << "ok, after " << TIMER_SEC(segregated) << "s";
util::Log() << "Segregated edges count = " << segregated_count;
util::Log() << "Segregated edges count = " << segregated_edges.size();
util::Log() << "Writing nodes for nodes-based and edges-based graphs ...";
auto const &coordinates = node_based_graph_factory.GetCoordinates();
@@ -277,6 +277,7 @@ int Extractor::run(ScriptingEnvironment &scripting_environment)
traffic_signals,
turn_restrictions,
conditional_turn_restrictions,
segregated_edges,
turn_lane_map,
scripting_environment,
edge_based_nodes_container,
@@ -664,6 +665,7 @@ EdgeID Extractor::BuildEdgeExpandedGraph(
const std::unordered_set<NodeID> &traffic_signals,
const std::vector<TurnRestriction> &turn_restrictions,
const std::vector<ConditionalTurnRestriction> &conditional_turn_restrictions,
const std::unordered_set<EdgeID> &segregated_edges,
// might have to be updated to add new lane combinations
guidance::LaneDescriptionMap &turn_lane_map,
// for calculating turn penalties
@@ -685,6 +687,7 @@ EdgeID Extractor::BuildEdgeExpandedGraph(
traffic_signals,
coordinates,
name_table,
segregated_edges,
turn_lane_map);
const auto create_edge_based_edges = [&]() {
@@ -949,11 +952,11 @@ bool IsSegregated(std::vector<EdgeInfo> v1,
return edgeLength <= threshold;
}
size_t Extractor::FindSegregatedNodes(NodeBasedGraphFactory &factory)
std::unordered_set<EdgeID> Extractor::FindSegregatedNodes(NodeBasedGraphFactory &factory)
{
util::NameTable names(config.GetPath(".osrm.names").string());
auto &graph = factory.GetGraph();
auto const &graph = factory.GetGraph();
auto const &annotation = factory.GetAnnotationData();
guidance::CoordinateExtractor coordExtractor(
@@ -1039,16 +1042,16 @@ size_t Extractor::FindSegregatedNodes(NodeBasedGraphFactory &factory)
edgeLength);
};
size_t segregated_count = 0;
std::unordered_set<EdgeID> segregated_edges;
for (NodeID sourceID = 0; sourceID < graph.GetNumberOfNodes(); ++sourceID)
{
auto const sourceEdges = graph.GetAdjacentEdgeRange(sourceID);
for (EdgeID edgeID : sourceEdges)
{
auto &edgeData = graph.GetEdgeData(edgeID);
auto const &edgeData = graph.GetEdgeData(edgeID);
if (edgeData.reversed || edgeData.segregated)
if (edgeData.reversed)
continue;
NodeID const targetID = graph.GetTarget(edgeID);
@@ -1056,14 +1059,11 @@ size_t Extractor::FindSegregatedNodes(NodeBasedGraphFactory &factory)
double const length = get_edge_length(sourceID, edgeID, targetID);
if (isSegregatedFn(edgeData, sourceEdges, sourceID, targetEdges, targetID, length))
{
++segregated_count;
edgeData.segregated = true;
}
segregated_edges.insert(edgeID);
}
}
return segregated_count;
return segregated_edges;
}
} // namespace extractor