From 9974b8b1da979a539db6b15c5eb957d4ba6a1fa6 Mon Sep 17 00:00:00 2001 From: Patrick Niklaus Date: Wed, 19 Apr 2017 14:47:35 +0000 Subject: [PATCH] Apply traffic light penalty also for non-turns --- features/car/traffic_light_penalties.feature | 39 ++++++++++++++++++++ profiles/car.lua | 12 +++--- 2 files changed, 45 insertions(+), 6 deletions(-) create mode 100644 features/car/traffic_light_penalties.feature diff --git a/features/car/traffic_light_penalties.feature b/features/car/traffic_light_penalties.feature new file mode 100644 index 000000000..ceb56d3a4 --- /dev/null +++ b/features/car/traffic_light_penalties.feature @@ -0,0 +1,39 @@ +@routing @car @traffic_light +Feature: Car - Handle traffic lights + + Background: + Given the profile "car" + + Scenario: Car - Encounters a traffic light + Given the node map + """ + a-1-b-2-c + + d-3-e-4-f + + g-h-i k-l-m + | | + j n + + """ + + And the ways + | nodes | highway | + | abc | primary | + | def | primary | + | ghi | primary | + | klm | primary | + | hj | primary | + | ln | primary | + + And the nodes + | node | highway | + | e | traffic_signals | + | l | traffic_signals | + + When I route I should get + | from | to | time | # | + | 1 | 2 | 11.1s | no turn with no traffic light | + | 3 | 4 | 13.1s | no turn with traffic light | + | g | j | 18.7s | turn with no traffic light | + | k | n | 20.7s | turn with traffic light | diff --git a/profiles/car.lua b/profiles/car.lua index 19cb1b988..7995faddb 100644 --- a/profiles/car.lua +++ b/profiles/car.lua @@ -392,21 +392,21 @@ function turn_function (turn) local turn_penalty = profile.turn_penalty local turn_bias = profile.turn_bias + if turn.has_traffic_light then + turn.duration = profile.traffic_light_penalty + end + if turn.turn_type ~= turn_type.no_turn then if turn.angle >= 0 then - turn.duration = turn_penalty / (1 + math.exp( -((13 / turn_bias) * turn.angle/180 - 6.5*turn_bias))) + turn.duration = turn.duration + turn_penalty / (1 + math.exp( -((13 / turn_bias) * turn.angle/180 - 6.5*turn_bias))) else - turn.duration = turn_penalty / (1 + math.exp( -((13 * turn_bias) * -turn.angle/180 - 6.5/turn_bias))) + turn.duration = turn.duration + turn_penalty / (1 + math.exp( -((13 * turn_bias) * -turn.angle/180 - 6.5/turn_bias))) end if turn.direction_modifier == direction_modifier.u_turn then turn.duration = turn.duration + profile.u_turn_penalty end - if turn.has_traffic_light then - turn.duration = turn.duration + profile.traffic_light_penalty - end - -- for distance based routing we don't want to have penalties based on turn angle if properties.weight_name == 'distance' then turn.weight = 0