From 1ab2b87cc05ecfc512147ae59422a7fcf9f060d4 Mon Sep 17 00:00:00 2001 From: Daniel Patterson Date: Tue, 6 Sep 2016 09:07:00 -0700 Subject: [PATCH] Update turn penalty function to better fit measured data --- CHANGELOG.md | 1 + profiles/car.lua | 13 +++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c19d4e351..95dbdf704 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ - Profiles - includes library guidance.lua that offers preliminary configuration on guidance. - added left_hand_driving flag in global profile properties + - modified turn penalty function for car profile - better fit to real data - Guidance - Handle Access tags for lanes, only considering valid lanes in lane-guidance (think car | car | bike | car) - API: diff --git a/profiles/car.lua b/profiles/car.lua index bd321b267..9daff8ff7 100644 --- a/profiles/car.lua +++ b/profiles/car.lua @@ -150,10 +150,10 @@ properties.left_hand_driving = false local side_road_speed_multiplier = 0.8 -local turn_penalty = 1 +local turn_penalty = 7.5 -- Note: this biases right-side driving. Should be -- inverted for left-driving countries. -local turn_bias = properties.left_hand_driving and 1/1.2 or 1.2 +local turn_bias = properties.left_hand_driving and 1/1.075 or 1.075 local obey_oneway = true local ignore_areas = true @@ -544,12 +544,13 @@ function way_function (way, result) end function turn_function (angle) - ---- compute turn penalty as angle^2, with a left/right bias + -- Use a sigmoid function to return a penalty that maxes out at turn_penalty + -- over the space of 0-180 degrees. Values here were chosen by fitting + -- the function to some turn penalty samples from real driving. -- multiplying by 10 converts to deci-seconds see issue #1318 - k = 10*turn_penalty/(90.0*90.0) if angle>=0 then - return angle*angle*k/turn_bias + return 10 * turn_penalty / (1 + 2.718 ^ - ((13 / turn_bias) * angle/180 - 6.5*turn_bias)) else - return angle*angle*k*turn_bias + return 10 * turn_penalty / (1 + 2.718 ^ - ((13 * turn_bias) * - angle/180 - 6.5/turn_bias)) end end