Added 'distance' weight to car profile

This commit is contained in:
Michael Krasnyk 2017-02-01 20:35:29 +01:00 committed by Patrick Niklaus
parent 5fd6355829
commit 9e5d45d86a
3 changed files with 30 additions and 12 deletions

View File

@ -131,6 +131,8 @@ inline RouteLeg assembleLeg(const datafacade::BaseDataFacade &facade,
{ {
const auto target_duration = const auto target_duration =
(target_traversed_in_reverse ? target_node.reverse_duration : target_node.forward_duration); (target_traversed_in_reverse ? target_node.reverse_duration : target_node.forward_duration);
const auto target_weight =
(target_traversed_in_reverse ? target_node.reverse_weight : target_node.forward_weight);
auto distance = std::accumulate( auto distance = std::accumulate(
leg_geometry.segment_distances.begin(), leg_geometry.segment_distances.end(), 0.); leg_geometry.segment_distances.begin(), leg_geometry.segment_distances.end(), 0.);
@ -165,6 +167,7 @@ inline RouteLeg assembleLeg(const datafacade::BaseDataFacade &facade,
// On local segments, the target duration is already part of the duration, however. // On local segments, the target duration is already part of the duration, however.
duration = duration + target_duration; duration = duration + target_duration;
weight = weight + target_weight;
if (route_data.empty()) if (route_data.empty())
{ {
duration -= (target_traversed_in_reverse ? source_node.reverse_duration duration -= (target_traversed_in_reverse ? source_node.reverse_duration
@ -204,7 +207,7 @@ inline RouteLeg assembleLeg(const datafacade::BaseDataFacade &facade,
return RouteLeg{std::round(distance * 10.) / 10., return RouteLeg{std::round(distance * 10.) / 10.,
duration / 10., duration / 10.,
duration / facade.GetWeightMultiplier(), weight / facade.GetWeightMultiplier(),
summary, summary,
{}}; {}};
} }

View File

@ -21,13 +21,13 @@ local profile = {
default_mode = mode.driving, default_mode = mode.driving,
default_speed = 10, default_speed = 10,
oneway_handling = true, oneway_handling = true,
side_road_speed_multiplier = 0.8, side_road_speed_multiplier = 0.8,
turn_penalty = 7.5, turn_penalty = 7.5,
speed_reduction = 0.8, speed_reduction = 0.8,
traffic_light_penalty = 2, traffic_light_penalty = 2,
u_turn_penalty = 20, u_turn_penalty = 20,
-- Note: this biases right-side driving. -- Note: this biases right-side driving.
-- Should be inverted for left-driving countries. -- Should be inverted for left-driving countries.
turn_bias = properties.left_hand_driving and 1/1.075 or 1.075, turn_bias = properties.left_hand_driving and 1/1.075 or 1.075,
@ -36,7 +36,7 @@ local profile = {
suffix_list = { suffix_list = {
'N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW', 'North', 'South', 'West', 'East' 'N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW', 'North', 'South', 'West', 'East'
}, },
barrier_whitelist = Set { barrier_whitelist = Set {
'cattle_grid', 'cattle_grid',
'border_control', 'border_control',
@ -85,7 +85,7 @@ local profile = {
'motor_vehicle', 'motor_vehicle',
'vehicle' 'vehicle'
}, },
avoid = Set { avoid = Set {
'area', 'area',
'toll', 'toll',
@ -93,7 +93,7 @@ local profile = {
'impassable', 'impassable',
'hov_lanes' 'hov_lanes'
}, },
speeds = Sequence { speeds = Sequence {
highway = { highway = {
motorway = 90, motorway = 90,
@ -120,7 +120,7 @@ local profile = {
driveway = 5, driveway = 5,
["drive-through"] = 5 ["drive-through"] = 5
}, },
route_speeds = { route_speeds = {
ferry = 5, ferry = 5,
shuttle_train = 10 shuttle_train = 10
@ -129,7 +129,7 @@ local profile = {
bridge_speeds = { bridge_speeds = {
movable = 5 movable = 5
}, },
-- surface/trackype/smoothness -- surface/trackype/smoothness
-- values were estimated from looking at the photos at the relevant wiki pages -- values were estimated from looking at the photos at the relevant wiki pages
@ -277,7 +277,7 @@ function way_function(way, result)
-- in general we should try to abort as soon as -- in general we should try to abort as soon as
-- possible if the way is not routable, to avoid doing -- possible if the way is not routable, to avoid doing
-- unnecessary work. this implies we should check things that -- unnecessary work. this implies we should check things that
-- commonly forbids access early, and handle edge cases later. -- commonly forbids access early, and handle edge cases later.
-- data table for storing intermediate values during processing -- data table for storing intermediate values during processing
local data = { local data = {
@ -342,9 +342,12 @@ function way_function(way, result)
'handle_startpoint', 'handle_startpoint',
-- set name, ref and pronunciation -- set name, ref and pronunciation
'handle_names' 'handle_names',
-- set weight properties of the way
'handle_weights'
} }
Handlers.run(handlers,way,result,data,profile) Handlers.run(handlers,way,result,data,profile)
end end
@ -354,7 +357,7 @@ function turn_function (turn)
-- the function to some turn penalty samples from real driving. -- the function to some turn penalty samples from real driving.
local turn_penalty = profile.turn_penalty local turn_penalty = profile.turn_penalty
local turn_bias = profile.turn_bias local turn_bias = profile.turn_bias
if turn.turn_type ~= turn_type.no_turn then if turn.turn_type ~= turn_type.no_turn then
if turn.angle >= 0 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_penalty / (1 + math.exp( -((13 / turn_bias) * turn.angle/180 - 6.5*turn_bias)))

View File

@ -405,6 +405,18 @@ function Handlers.handle_oneway(way,result,data,profile)
end end
end end
function Handlers.handle_weights(way,result,data,profile)
if properties.weight_name == 'distance' then
result.weight = 0
-- set weight rates to 1 for the distance weight, edge weights are distance / rate
if (result.forward_mode ~= mode.inaccessible and result.forward_speed > 0) then
result.forward_rate = 1
end
if (result.backward_mode ~= mode.inaccessible and result.backward_speed > 0) then
result.backward_rate = 1
end
end
end
-- handle various that can block access -- handle various that can block access
function Handlers.handle_blocked_ways(way,result,data,profile) function Handlers.handle_blocked_ways(way,result,data,profile)