Skip to content

Commit 62abea3

Browse files
committed
Apply traffic light penalty also for non-turns
1 parent 3364be1 commit 62abea3

File tree

2 files changed

+45
-6
lines changed

2 files changed

+45
-6
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
@routing @car @traffic_light
2+
Feature: Car - Handle traffic lights
3+
4+
Background:
5+
Given the profile "car"
6+
7+
Scenario: Car - Encounters a traffic light
8+
Given the node map
9+
"""
10+
a-1-b-2-c
11+
12+
d-3-e-4-f
13+
14+
g-h-i k-l-m
15+
| |
16+
j n
17+
18+
"""
19+
20+
And the ways
21+
| nodes | highway |
22+
| abc | primary |
23+
| def | primary |
24+
| ghi | primary |
25+
| klm | primary |
26+
| hj | primary |
27+
| ln | primary |
28+
29+
And the nodes
30+
| node | highway |
31+
| e | traffic_signals |
32+
| l | traffic_signals |
33+
34+
When I route I should get
35+
| from | to | time | # |
36+
| 1 | 2 | 11.1s | no turn with no traffic light |
37+
| 3 | 4 | 13.1s | no turn with traffic light |
38+
| g | j | 18.7s | turn with no traffic light |
39+
| k | n | 20.7s | turn with traffic light |

profiles/car.lua

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -392,21 +392,21 @@ function turn_function (turn)
392392
local turn_penalty = profile.turn_penalty
393393
local turn_bias = profile.turn_bias
394394

395+
if turn.has_traffic_light then
396+
turn.duration = profile.traffic_light_penalty
397+
end
398+
395399
if turn.turn_type ~= turn_type.no_turn then
396400
if turn.angle >= 0 then
397-
turn.duration = turn_penalty / (1 + math.exp( -((13 / turn_bias) * turn.angle/180 - 6.5*turn_bias)))
401+
turn.duration = turn.duration + turn_penalty / (1 + math.exp( -((13 / turn_bias) * turn.angle/180 - 6.5*turn_bias)))
398402
else
399-
turn.duration = turn_penalty / (1 + math.exp( -((13 * turn_bias) * -turn.angle/180 - 6.5/turn_bias)))
403+
turn.duration = turn.duration + turn_penalty / (1 + math.exp( -((13 * turn_bias) * -turn.angle/180 - 6.5/turn_bias)))
400404
end
401405

402406
if turn.direction_modifier == direction_modifier.u_turn then
403407
turn.duration = turn.duration + profile.u_turn_penalty
404408
end
405409

406-
if turn.has_traffic_light then
407-
turn.duration = turn.duration + profile.traffic_light_penalty
408-
end
409-
410410
-- for distance based routing we don't want to have penalties based on turn angle
411411
if properties.weight_name == 'distance' then
412412
turn.weight = 0

0 commit comments

Comments
 (0)