Skip to content

Commit

Permalink
Add data structure to allow identification of via-way turns during cr…
Browse files Browse the repository at this point in the history
…eation of edge-based-graph
  • Loading branch information
Moritz Kobitzsch committed Jul 12, 2017
1 parent c5e4c66 commit 3ae0590
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 32 deletions.
8 changes: 4 additions & 4 deletions include/extractor/edge_based_graph_factory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ class EdgeBasedGraphFactory
CompressedEdgeContainer &compressed_edge_container,
const std::unordered_set<NodeID> &barrier_nodes,
const std::unordered_set<NodeID> &traffic_lights,
std::shared_ptr<const RestrictionMap> restriction_map,
const std::vector<util::Coordinate> &coordinates,
const extractor::PackedOSMIDs &osm_node_ids,
ProfileProperties profile_properties,
Expand All @@ -91,7 +90,8 @@ class EdgeBasedGraphFactory
const std::string &turn_weight_penalties_filename,
const std::string &turn_duration_penalties_filename,
const std::string &turn_penalties_index_filename,
const std::string &cnbg_ebg_mapping_path);
const std::string &cnbg_ebg_mapping_path,
const RestrictionMap & restriction_map);

// The following get access functions destroy the content in the factory
void GetEdgeBasedEdges(util::DeallocatingVector<EdgeBasedEdge> &edges);
Expand Down Expand Up @@ -139,7 +139,6 @@ class EdgeBasedGraphFactory
const std::vector<util::Coordinate> &m_coordinates;
const extractor::PackedOSMIDs &m_osm_node_ids;
std::shared_ptr<util::NodeBasedDynamicGraph> m_node_based_graph;
std::shared_ptr<RestrictionMap const> m_restriction_map;

const std::unordered_set<NodeID> &m_barrier_nodes;
const std::unordered_set<NodeID> &m_traffic_lights;
Expand All @@ -159,7 +158,8 @@ class EdgeBasedGraphFactory
const std::string &turn_lane_data_filename,
const std::string &turn_weight_penalties_filename,
const std::string &turn_duration_penalties_filename,
const std::string &turn_penalties_index_filename);
const std::string &turn_penalties_index_filename,
const RestrictionMap & restriction_map);

NBGToEBG InsertEdgeBasedNode(const NodeID u, const NodeID v);

Expand Down
38 changes: 38 additions & 0 deletions include/extractor/way_restriction_map.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#ifndef OSRM_EXTRACTOR_WAY_RESTRICTION_MAP_HPP_
#define OSRM_EXTRACTOR_WAY_RESTRICTION_MAP_HPP_

#include <utility>
#include <vector>

// to access the turn restrictions
#include <boost/unordered_map.hpp>

#include "extractor/restriction.hpp"
#include "util/typedefs.hpp"

// Given the compressed representation of via-way turn restrictions, we provide a fast access into
// the restrictions to indicate which turns may be restricted due to a way in between
namespace osrm
{
namespace extractor
{

class WayRestrictionMap
{
public:
WayRestrictionMap(const std::vector<TurnRestriction> &turn_restrictions);

// check if an edge between two nodes is a restricted turn
bool IsStart(const NodeID from, const NodeID to) const;
bool IsEnd(const NodeID from, const NodeID to) const;

private:
// acces to the turn restrictions based on the via way they use
boost::unordered_multimap<std::pair<NodeID, NodeID>, std::size_t> restriction_starts;
boost::unordered_multimap<std::pair<NodeID, NodeID>, std::size_t> restriction_ends;
};

} // namespace extractor
} // namespace osrm

#endif // OSRM_EXTRACTOR_WAY_RESTRICTION_MAP_HPP_
17 changes: 9 additions & 8 deletions src/extractor/edge_based_graph_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,14 @@ EdgeBasedGraphFactory::EdgeBasedGraphFactory(
CompressedEdgeContainer &compressed_edge_container,
const std::unordered_set<NodeID> &barrier_nodes,
const std::unordered_set<NodeID> &traffic_lights,
std::shared_ptr<const RestrictionMap> restriction_map,
const std::vector<util::Coordinate> &coordinates,
const extractor::PackedOSMIDs &osm_node_ids,
ProfileProperties profile_properties,
const util::NameTable &name_table,
guidance::LaneDescriptionMap &lane_description_map)
: 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_restriction_map(std::move(restriction_map)), m_barrier_nodes(barrier_nodes),
m_barrier_nodes(barrier_nodes),
m_traffic_lights(traffic_lights), m_compressed_edge_container(compressed_edge_container),
profile_properties(std::move(profile_properties)), name_table(name_table),
lane_description_map(lane_description_map)
Expand Down Expand Up @@ -192,7 +191,8 @@ void EdgeBasedGraphFactory::Run(ScriptingEnvironment &scripting_environment,
const std::string &turn_weight_penalties_filename,
const std::string &turn_duration_penalties_filename,
const std::string &turn_penalties_index_filename,
const std::string &cnbg_ebg_mapping_path)
const std::string &cnbg_ebg_mapping_path,
const RestrictionMap &restriction_map)
{
TIMER_START(renumber);
m_max_edge_id = RenumberEdges() - 1;
Expand All @@ -211,7 +211,8 @@ void EdgeBasedGraphFactory::Run(ScriptingEnvironment &scripting_environment,
turn_lane_data_filename,
turn_weight_penalties_filename,
turn_duration_penalties_filename,
turn_penalties_index_filename);
turn_penalties_index_filename,
restriction_map);

TIMER_STOP(generate_edges);

Expand Down Expand Up @@ -321,7 +322,8 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
const std::string &turn_lane_data_filename,
const std::string &turn_weight_penalties_filename,
const std::string &turn_duration_penalties_filename,
const std::string &turn_penalties_index_filename)
const std::string &turn_penalties_index_filename,
const RestrictionMap &restriction_map)
{

util::Log() << "Generating edge-expanded edges ";
Expand All @@ -342,7 +344,7 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
SuffixTable street_name_suffix_table(scripting_environment);
guidance::TurnAnalysis turn_analysis(*m_node_based_graph,
m_coordinates,
*m_restriction_map,
restriction_map,
m_barrier_nodes,
m_compressed_edge_container,
name_table,
Expand Down Expand Up @@ -713,8 +715,7 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
util::Log() << "Edge-expanded graph ...";
util::Log() << " contains " << m_edge_based_edge_list.size() << " edges";
util::Log() << " skips " << restricted_turns_counter << " turns, "
"defined by "
<< m_restriction_map->size() << " restrictions";
"defined by " << restriction_map.size() << " restrictions";
util::Log() << " skips " << skipped_uturns_counter << " U turns";
util::Log() << " skips " << skipped_barrier_turns_counter << " turns over barriers";
}
Expand Down
46 changes: 26 additions & 20 deletions src/extractor/extractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include "extractor/compressed_edge_container.hpp"
#include "extractor/restriction_map.hpp"
#include "extractor/way_restriction_map.hpp"
#include "util/static_graph.hpp"
#include "util/static_rtree.hpp"

Expand Down Expand Up @@ -470,26 +471,31 @@ Extractor::BuildEdgeExpandedGraph(ScriptingEnvironment &scripting_environment,

util::NameTable name_table(config.names_file_name);

auto restriction_map = std::make_shared<RestrictionMap>(turn_restrictions);
EdgeBasedGraphFactory edge_based_graph_factory(
node_based_graph,
compressed_edge_container,
barrier_nodes,
traffic_lights,
std::const_pointer_cast<RestrictionMap const>(restriction_map),
coordinates,
osm_node_ids,
scripting_environment.GetProfileProperties(),
name_table,
turn_lane_map);

edge_based_graph_factory.Run(scripting_environment,
config.edge_output_path,
config.turn_lane_data_file_name,
config.turn_weight_penalties_path,
config.turn_duration_penalties_path,
config.turn_penalties_index_path,
config.cnbg_ebg_graph_mapping_output_path);
EdgeBasedGraphFactory edge_based_graph_factory(node_based_graph,
compressed_edge_container,
barrier_nodes,
traffic_lights,
coordinates,
osm_node_ids,
scripting_environment.GetProfileProperties(),
name_table,
turn_lane_map);

{ // scoped to relase right after the run
RestrictionMap via_node_restriction_map(turn_restrictions);
WayRestrictionMap via_way_restriction_map(turn_restrictions);
turn_restrictions.clear();
turn_restrictions.shrink_to_fit();

edge_based_graph_factory.Run(scripting_environment,
config.edge_output_path,
config.turn_lane_data_file_name,
config.turn_weight_penalties_path,
config.turn_duration_penalties_path,
config.turn_penalties_index_path,
config.cnbg_ebg_graph_mapping_output_path,
via_node_restriction_map);
}

compressed_edge_container.PrintStatistics();

Expand Down
35 changes: 35 additions & 0 deletions src/extractor/way_restriction_map.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include "extractor/way_restriction_map.hpp"

namespace osrm
{
namespace extractor
{

WayRestrictionMap::WayRestrictionMap(const std::vector<TurnRestriction> &turn_restrictions)
{
// map all way restrictions into access containers
const auto prepare_way_restriction = [this](const auto &restriction) {
if (restriction.Type() != RestrictionType::WAY_RESTRICTION)
return;

const auto &way = restriction.AsWayRestriction();
restriction_starts.insert(
std::make_pair(std::make_pair(way.in_restriction.via, way.in_restriction.to), 0));
restriction_ends.insert(
std::make_pair(std::make_pair(way.out_restriction.from, way.out_restriction.via), 0));
};
std::for_each(turn_restrictions.begin(), turn_restrictions.end(), prepare_way_restriction);
}

// check if an edge between two nodes is a restricted turn
bool WayRestrictionMap::IsStart(const NodeID from, const NodeID to) const
{
return restriction_starts.count(std::make_pair(from, to)) > 0;
}
bool WayRestrictionMap::IsEnd(const NodeID from, const NodeID to) const
{
return restriction_ends.count(std::make_pair(from, to)) > 0;
}

} // namespace extractor
} // namespace osrm

0 comments on commit 3ae0590

Please sign in to comment.