Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop signs for the turn function in lua profiles #4828

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions features/options/extract/turn_function.feature
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Feature: Turn Function Information
end

function print_turn (profile, turn)
print ('is_stop ' .. string.format("%s", tostring(turn.is_stop)))
print ('source_restricted ' .. string.format("%s", tostring(turn.source_restricted)))
print ('source_is_motorway ' .. string.format("%s", tostring(turn.source_is_motorway)))
print ('source_is_link ' .. string.format("%s", tostring(turn.source_is_link)))
Expand Down Expand Up @@ -173,4 +174,67 @@ Feature: Turn Function Information



Scenario: Turns should show if intersection node is tagged with highway=stop stop=all
Given the node map
"""
a->b->c
"""
And the ways
| nodes | oneway |
| ab | yes |
| bc | yes |
And the nodes
| node | highway | stop |
| b | stop | all |

And the data has been saved to disk

When I run "osrm-extract --profile {profile_file} {osm_file}"
Then it should exit successfully
And stdout should contain "is_stop true"


Scenario: Turns should not claim there is stop if there is not
Given the node map
"""
a-b-c
"""
And the ways
| nodes | oneway |
| ab | yes |
| bc | yes |
And the nodes
| node | highway |
| b | - |

And the data has been saved to disk

When I run "osrm-extract --profile {profile_file} {osm_file}"
Then it should exit successfully
And stdout should contain "is_stop false"


Scenario: Turn should show correct stops if intersection node is tagged with highway=stop stop=minor
Given the node map
"""
d
|
v
a->b->c
"""
And the ways
| nodes | oneway | highway |
| ab | yes | primary |
| bc | yes | primary |
| db | yes | tertiary |
And the nodes
| node | highway | stop |
| b | stop | minor |

And the data has been saved to disk

When I run "osrm-extract --profile {profile_file} {osm_file}"
Then it should exit successfully
And stdout should contain "is_stop true"
And stdout should contain "is_stop false"

2 changes: 1 addition & 1 deletion features/support/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ module.exports = function () {
.defer(rimraf, this.scenarioLogFile)
.awaitAll(callback);
// uncomment to get path to logfile
// console.log(" Writing logging output to " + this.scenarioLogFile)
console.log(" Writing logging output to " + this.scenarioLogFile)
});

this.After((scenario, callback) => {
Expand Down
4 changes: 4 additions & 0 deletions include/extractor/edge_based_graph_factory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ class EdgeBasedGraphFactory
const CompressedEdgeContainer &compressed_edge_container,
const std::unordered_set<NodeID> &barrier_nodes,
const std::unordered_set<NodeID> &traffic_lights,
const std::unordered_set<NodeID> &all_way_stops,
const std::unordered_set<NodeID> &minor_stops,
const std::vector<util::Coordinate> &coordinates,
const util::NameTable &name_table,
const std::unordered_set<EdgeID> &segregated_edges,
Expand Down Expand Up @@ -155,6 +157,8 @@ class EdgeBasedGraphFactory

const std::unordered_set<NodeID> &m_barrier_nodes;
const std::unordered_set<NodeID> &m_traffic_lights;
const std::unordered_set<NodeID> &m_all_way_stops;
const std::unordered_set<NodeID> &m_minor_stops;
const CompressedEdgeContainer &m_compressed_edge_container;

const util::NameTable &name_table;
Expand Down
2 changes: 2 additions & 0 deletions include/extractor/extraction_containers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class ExtractionContainers

std::vector<OSMNodeID> barrier_nodes;
std::vector<OSMNodeID> traffic_signals;
std::vector<OSMNodeID> all_way_stops;
std::vector<OSMNodeID> minor_stops;
NodeIDVector used_node_id_list;
NodeVector all_nodes_list;
EdgeVector all_edges_list;
Expand Down
10 changes: 8 additions & 2 deletions include/extractor/extraction_node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@ namespace extractor

struct ExtractionNode
{
ExtractionNode() : traffic_lights(false), barrier(false) {}
void clear() { traffic_lights = barrier = false; }
ExtractionNode()
: traffic_lights(false), barrier(false), is_all_way_stop(false), is_minor_stop(false)
{
}
void clear() { traffic_lights = barrier = is_all_way_stop = is_minor_stop = false; }
bool traffic_lights;
bool barrier;

bool is_all_way_stop;
bool is_minor_stop;
};
}
}
Expand Down
4 changes: 3 additions & 1 deletion include/extractor/extraction_turn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ struct ExtractionTurn
bool is_u_turn,
bool has_traffic_light,
bool is_left_hand_driving,
bool is_stop,
bool source_restricted,
TravelMode source_mode,
bool source_is_motorway,
bool source_is_link,

int source_number_of_lanes,
int source_highway_turn_classification,
int source_access_turn_classification,
Expand All @@ -70,6 +70,7 @@ struct ExtractionTurn
const std::vector<ExtractionTurnLeg> &roads_on_the_left)
: angle(180. - angle), number_of_roads(number_of_roads), is_u_turn(is_u_turn),
has_traffic_light(has_traffic_light), is_left_hand_driving(is_left_hand_driving),
is_stop(is_stop),

source_restricted(source_restricted), source_mode(source_mode),
source_is_motorway(source_is_motorway), source_is_link(source_is_link),
Expand All @@ -95,6 +96,7 @@ struct ExtractionTurn
const bool is_u_turn;
const bool has_traffic_light;
const bool is_left_hand_driving;
const bool is_stop;

// source info
const bool source_restricted;
Expand Down
2 changes: 2 additions & 0 deletions include/extractor/extractor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ class Extractor
const CompressedEdgeContainer &compressed_edge_container,
const std::unordered_set<NodeID> &barrier_nodes,
const std::unordered_set<NodeID> &traffic_lights,
const std::unordered_set<NodeID> &all_way_stops,
const std::unordered_set<NodeID> &minor_stops,
const std::vector<TurnRestriction> &turn_restrictions,
const std::vector<ConditionalTurnRestriction> &conditional_turn_restrictions,
const std::unordered_set<EdgeID> &segregated_edges,
Expand Down
4 changes: 4 additions & 0 deletions include/extractor/node_based_graph_factory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class NodeBasedGraphFactory
auto const &GetGraph() const { return compressed_output_graph; }
auto const &GetBarriers() const { return barriers; }
auto const &GetTrafficSignals() const { return traffic_signals; }
auto const &GetAllWayStops() const { return all_way_stops; }
auto const &GetMinorStops() const { return minor_stops; }
auto const &GetCompressedEdges() const { return compressed_edge_container; }
auto const &GetCoordinates() const { return coordinates; }
auto const &GetAnnotationData() const { return annotation_data; }
Expand Down Expand Up @@ -89,6 +91,8 @@ class NodeBasedGraphFactory
// General Information about the graph, not used outside of extractor
std::unordered_set<NodeID> barriers;
std::unordered_set<NodeID> traffic_signals;
std::unordered_set<NodeID> all_way_stops;
std::unordered_set<NodeID> minor_stops;

std::vector<util::Coordinate> coordinates;

Expand Down
16 changes: 15 additions & 1 deletion include/util/graph_loader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ namespace util
* - traffic lights
* - nodes indexed by their internal (non-osm) id
*/
template <typename BarrierOutIter, typename TrafficSignalsOutIter>
template <typename BarrierOutIter, typename TrafficSignalsOutIter, typename AllWayStopsOutIter, typename MinorStopsOutIter>
NodeID loadNodesFromFile(storage::io::FileReader &file_reader,
BarrierOutIter barriers,
TrafficSignalsOutIter traffic_signals,
AllWayStopsOutIter all_way_stops,
MinorStopsOutIter minor_stops,
std::vector<util::Coordinate> &coordinates,
extractor::PackedOSMIDs &osm_node_ids)
{
Expand Down Expand Up @@ -71,6 +73,18 @@ NodeID loadNodesFromFile(storage::io::FileReader &file_reader,
*traffic_signals++ = file_reader.ReadOne<NodeID>();
}

auto num_all_way_stops = file_reader.ReadElementCount64();
for (auto index = 0UL; index < num_all_way_stops; ++index)
{
*all_way_stops++ = file_reader.ReadOne<NodeID>();
}

auto num_minor_stops = file_reader.ReadElementCount64();
for (auto index = 0UL; index < num_minor_stops; ++index)
{
*minor_stops++ = file_reader.ReadOne<NodeID>();
}

return number_of_nodes;
}

Expand Down
20 changes: 20 additions & 0 deletions profiles/car.lua
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,26 @@ function process_node(profile, node, result, relations)
if "traffic_signals" == tag then
result.traffic_lights = true
end

print('bla')

-- @CHAUTODO sure this should be here? This shouldn't be here
local stop = node:get_value_by_key("stop")
if tag == "stop" then
if stop == "all" then
result.is_all_way_stop = true
print('tag ' .. tag)
print('stop ' .. stop)
print('set all way stop')
else
if stop == "minor" then
result.is_minor_stop = true
print('tag ' .. tag)
print('stop ' .. stop)
print('set minor stop')
end
end
end
end

function process_way(profile, way, result, relations)
Expand Down
30 changes: 25 additions & 5 deletions src/extractor/edge_based_graph_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,15 @@ EdgeBasedGraphFactory::EdgeBasedGraphFactory(
const CompressedEdgeContainer &compressed_edge_container,
const std::unordered_set<NodeID> &barrier_nodes,
const std::unordered_set<NodeID> &traffic_lights,
const std::unordered_set<NodeID> &all_way_stops,
const std::unordered_set<NodeID> &minor_stops,
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_barrier_nodes(barrier_nodes), m_traffic_lights(traffic_lights), m_all_way_stops(all_way_stops), m_minor_stops(minor_stops),
m_compressed_edge_container(compressed_edge_container), name_table(name_table),
segregated_edges(segregated_edges), lane_description_map(lane_description_map)
{
Expand Down Expand Up @@ -564,7 +566,8 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
const auto &road_legs_on_the_right,
const auto &road_legs_on_the_left,
const auto entry_class_id,
const auto &edge_geometries) {
const auto &edge_geometries,
const auto is_minor) {

const auto node_restricted = isRestricted(node_along_road_entering,
intersection_node,
Expand Down Expand Up @@ -601,6 +604,11 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
// compute weight and duration penalties
auto is_traffic_light = m_traffic_lights.count(intersection_node);

//@CHAUTODO
bool is_stop = m_all_way_stops.count(intersection_node) > 0 || (m_minor_stops.count(intersection_node) > 0 && is_minor);
std::cout << "Creating turn at " << intersection_node << " " << m_all_way_stops.count(intersection_node) << std::endl;


ExtractionTurn extracted_turn(
// general info
turn.angle,
Expand All @@ -610,6 +618,7 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
is_traffic_light,
m_edge_based_node_container.GetAnnotation(edge_data1.annotation_data)
.is_left_hand_driving,
is_stop,
// source info
edge_data1.flags.restricted,
m_edge_based_node_container.GetAnnotation(edge_data1.annotation_data).travel_mode,
Expand Down Expand Up @@ -875,6 +884,14 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
<< m_coordinates[intersection_node].toOSMLink();
}



guidance::RoadPriorityClass::Enum from_priority = m_node_based_graph.GetEdgeData(incoming_edge.edge).flags.road_classification.GetPriority();
bool is_minor = std::any_of(
intersection.begin(), intersection.end(), [&](auto connected_road) {
return m_node_based_graph.GetEdgeData(connected_road.eid).flags.road_classification.GetPriority() < from_priority;
});

// In case a way restriction starts at a given location, add a turn onto
// every artificial node eminating here.
//
Expand Down Expand Up @@ -914,7 +931,8 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
road_legs_on_the_right,
road_legs_on_the_left,
entry_class_id,
edge_geometries);
edge_geometries,
is_minor);

buffer->continuous_data.edges_list.push_back(
edge_with_data_and_condition.first.edge);
Expand Down Expand Up @@ -979,7 +997,8 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
road_legs_on_the_right,
road_legs_on_the_left,
entry_class_id,
edge_geometries);
edge_geometries,
is_minor);

buffer->delayed_data.push_back(
std::move(edge_with_data_and_condition.first));
Expand Down Expand Up @@ -1016,7 +1035,8 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
road_legs_on_the_right,
road_legs_on_the_left,
entry_class_id,
edge_geometries);
edge_geometries,
is_minor);

buffer->delayed_data.push_back(
std::move(edge_with_data_and_condition.first));
Expand Down
36 changes: 36 additions & 0 deletions src/extractor/extraction_containers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,42 @@ void ExtractionContainers::WriteNodes(storage::io::FileWriter &file_out) const
log << "ok, after " << TIMER_SEC(write_nodes) << "s";
}

{
util::UnbufferedLog log;
log << "Writing all way stop nodes ... ";
TIMER_START(write_nodes);
std::vector<NodeID> internal_all_way_stops;
for (const auto osm_id : all_way_stops)
{
const auto node_id = mapExternalToInternalNodeID(
used_node_id_list.begin(), used_node_id_list.end(), osm_id);
if (node_id != SPECIAL_NODEID)
{
internal_all_way_stops.push_back(node_id);
}
}
storage::serialization::write(file_out, internal_all_way_stops);
log << "ok, after " << TIMER_SEC(write_nodes) << "s";
}

{
util::UnbufferedLog log;
log << "Writing minor stop nodes ... ";
TIMER_START(write_nodes);
std::vector<NodeID> internal_minor_stops;
for (const auto osm_id : minor_stops)
{
const auto node_id = mapExternalToInternalNodeID(
used_node_id_list.begin(), used_node_id_list.end(), osm_id);
if (node_id != SPECIAL_NODEID)
{
internal_minor_stops.push_back(node_id);
}
}
storage::serialization::write(file_out, internal_minor_stops);
log << "ok, after " << TIMER_SEC(write_nodes) << "s";
}

util::Log() << "Processed " << max_internal_node_id << " nodes";
}

Expand Down
Loading