Skip to content

Commit

Permalink
Pass approach/exit speed values to turn_function.
Browse files Browse the repository at this point in the history
  • Loading branch information
danpat authored and Moritz Kobitzsch committed Oct 12, 2016
1 parent 8bb55d1 commit 6fa7ffd
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 9 deletions.
2 changes: 1 addition & 1 deletion profiles/bicycle.lua
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ function way_function (way, result)
limit( result, maxspeed, maxspeed_forward, maxspeed_backward )
end

function turn_function (angle)
function turn_function (angle, approach_road_speed, exit_road_speed)
-- compute turn penalty as angle^2, with a left/right bias
-- multiplying by 10 converts to deci-seconds see issue #1318
k = 10*turn_penalty/(90.0*90.0)
Expand Down
2 changes: 0 additions & 2 deletions profiles/car.lua
Original file line number Diff line number Diff line change
Expand Up @@ -591,8 +591,6 @@ function way_function (way, result)
result.is_startpoint = result.forward_mode == mode.driving or result.backward_mode == mode.driving
end

-- a detailed turn function as an alternative to turn function, offering more properties to decide on a good penalty
-- returns penalty in seconds
function turn_function(angle, turn_properties, intersection_properties, approach_segment, exit_segment)
local penalty = 0;
if turn_properties.angle>=0 then
Expand Down
2 changes: 1 addition & 1 deletion profiles/turnbot.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

require 'testbot'

function turn_function (angle)
function turn_function (angle, approach_road_speed, exit_road_speed)
-- multiplying by 10 converts to deci-seconds see issue #1318
return 10*20*math.abs(angle)/180
end
41 changes: 36 additions & 5 deletions src/extractor/edge_based_graph_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,6 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(

bool crosses_through_traffic = false;
const EdgeData &edge_data_from_u = m_node_based_graph->GetEdgeData(edge_from_u);
const TurnSegment approach_segment = {static_cast<double>(edge_data_from_u.distance),
static_cast<double>(edge_data_from_u.distance)};
const IntersectionProperties intersection_properties = {
crosses_traffic_light, false, false};
for (const auto turn : possible_turns)
Expand Down Expand Up @@ -470,12 +468,45 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
const TurnProperties turn_properties = {
180. - turn.angle, turn.angle, crosses_through_traffic, requires_announcement};

const TurnSegment exit_segment = {static_cast<double>(edge_data2.distance),
static_cast<double>(edge_data2.distance)};

const bool isTrivial = m_compressed_edge_container.IsTrivial(edge_from_u);

const auto &approach_node =
isTrivial
? m_node_info_list[node_u]
: m_node_info_list[m_compressed_edge_container.GetLastEdgeSourceID(
edge_from_u)];
const auto &intersection_node =
m_node_info_list[m_compressed_edge_container.GetLastEdgeTargetID(
edge_from_u)];

const auto &exit_node =
m_node_info_list[m_compressed_edge_container.GetFirstEdgeTargetID(
turn.eid)];

const double approach_segment_length =
util::coordinate_calculation::greatCircleDistance(approach_node, intersection_node);
const double exit_segment_length =
util::coordinate_calculation::greatCircleDistance(intersection_node, exit_node);

const auto approach_road_segments =
m_compressed_edge_container.GetBucketReference(edge_from_u);
const auto exit_road_segments =
m_compressed_edge_container.GetBucketReference(turn.eid);

// segment_length is in metres, weight is in deciseconds, this converts those
// to km/h
const double approach_speed = approach_segment_length / (approach_road_segments.back().weight/10) * 3.6; // km/h
const double exit_speed = exit_segment_length / (exit_road_segments.front().weight/10) * 3.6; // km/h

const TurnSegment approach_segment = {approach_segment_length,approach_speed};
const TurnSegment exit_segment = {exit_segment_length,exit_speed};

const auto turn_instruction = turn.instruction;

const int32_t turn_penalty = scripting_environment.GetTurnPenalty(
turn_properties, intersection_properties, approach_segment, exit_segment);
const auto turn_instruction = turn.instruction;


if (turn_instruction.direction_modifier == guidance::DirectionModifier::UTurn)
{
Expand Down
2 changes: 2 additions & 0 deletions src/extractor/scripting_environment_lua.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,8 @@ std::int32_t LuaScriptingEnvironment::GetTurnPenalty(
boost::cref(intersection_properties),
boost::cref(approach_segment),
boost::cref(exit_segment));
BOOST_ASSERT(penalty < std::numeric_limits<int32_t>::max());
BOOST_ASSERT(penalty > std::numeric_limits<int32_t>::min());
return boost::numeric_cast<int32_t>(penalty);
}
catch (const luabind::error &er)
Expand Down

0 comments on commit 6fa7ffd

Please sign in to comment.