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 =
(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(
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.
duration = duration + target_duration;
weight = weight + target_weight;
if (route_data.empty())
{
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.,
duration / 10.,
duration / facade.GetWeightMultiplier(),
weight / facade.GetWeightMultiplier(),
summary,
{}};
}

View File

@ -342,7 +342,10 @@ function way_function(way, result)
'handle_startpoint',
-- set name, ref and pronunciation
'handle_names'
'handle_names',
-- set weight properties of the way
'handle_weights'
}
Handlers.run(handlers,way,result,data,profile)

View File

@ -405,6 +405,18 @@ function Handlers.handle_oneway(way,result,data,profile)
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
function Handlers.handle_blocked_ways(way,result,data,profile)