Allow specifing a weight for routing that is independent of duration

This commit is contained in:
Patrick Niklaus
2016-05-12 18:50:10 +02:00
committed by Patrick Niklaus
parent e463733138
commit 279f8aabfb
85 changed files with 2100 additions and 853 deletions
@@ -75,8 +75,11 @@ inline LegGeometry assembleGeometry(const datafacade::BaseDataFacade &facade,
}
prev_coordinate = coordinate;
geometry.annotations.emplace_back(LegGeometry::Annotation{
current_distance, path_point.duration_until_turn / 10., path_point.datasource_id});
geometry.annotations.emplace_back(
LegGeometry::Annotation{current_distance,
path_point.duration_until_turn / 10.,
path_point.weight_until_turn / 10.,
path_point.datasource_id});
geometry.locations.push_back(std::move(coordinate));
geometry.osm_node_ids.push_back(facade.GetOSMNodeIDOfNode(path_point.turn_via_node));
}
@@ -89,10 +92,14 @@ inline LegGeometry assembleGeometry(const datafacade::BaseDataFacade &facade,
const std::vector<DatasourceID> forward_datasources =
facade.GetUncompressedForwardDatasources(target_node.packed_geometry_id);
// FIXME this is wrong. We need to check for traversal direction here
// and for the case of a local path (target and source on the same edge)
geometry.annotations.emplace_back(
LegGeometry::Annotation{current_distance,
target_node.forward_duration / 10.,
target_node.forward_weight / 10.,
forward_datasources[target_node.fwd_segment_position]});
geometry.segment_offsets.push_back(geometry.locations.size());
geometry.locations.push_back(target_node.location);
+11 -16
View File
@@ -79,7 +79,7 @@ std::array<std::uint32_t, SegmentNumber> summarizeRoute(const std::vector<PathDa
return NamedSegment{point.duration_until_turn, index++, point.name_id};
});
const auto target_duration =
target_traversed_in_reverse ? target_node.reverse_weight : target_node.forward_weight;
target_traversed_in_reverse ? target_node.reverse_duration : target_node.forward_duration;
if (target_duration > 1)
segments.push_back({target_duration, index++, target_node.name_id});
// this makes sure that the segment with the lowest position comes first
@@ -130,18 +130,14 @@ inline RouteLeg assembleLeg(const datafacade::BaseDataFacade &facade,
const bool needs_summary)
{
const auto target_duration =
(target_traversed_in_reverse ? target_node.reverse_weight : target_node.forward_weight) /
10.;
(target_traversed_in_reverse ? target_node.reverse_duration : target_node.forward_duration);
auto distance = std::accumulate(
leg_geometry.segment_distances.begin(), leg_geometry.segment_distances.end(), 0.);
auto duration = std::accumulate(route_data.begin(),
route_data.end(),
0.,
[](const double sum, const PathData &data) {
return sum + data.duration_until_turn;
}) /
10.;
auto duration = std::accumulate(
route_data.begin(), route_data.end(), 0, [](const double sum, const PathData &data) {
return sum + data.duration_until_turn;
});
// s
// |
@@ -155,10 +151,10 @@ inline RouteLeg assembleLeg(const datafacade::BaseDataFacade &facade,
// The duration of the turn (a,c) -> (c,e) will be the duration of (a,c) (e.g. the duration
// of (a,b,c)).
// The phantom node of s will contain:
// `forward_weight`: duration of (a,s)
// `forward_duration`: duration of (a,s)
// `forward_offset`: 0 (its the first segment)
// The phantom node of t will contain:
// `forward_weight`: duration of (d,t)
// `forward_duration`: duration of (d,t)
// `forward_offset`: duration of (c, d)
// path_data will have entries for (s,b), (b, c), (c, d) but (d, t) is only
// caputed by the phantom node. So we need to add the target duration here.
@@ -167,9 +163,8 @@ inline RouteLeg assembleLeg(const datafacade::BaseDataFacade &facade,
duration = duration + target_duration;
if (route_data.empty())
{
duration -= (target_traversed_in_reverse ? source_node.reverse_weight
: source_node.forward_weight) /
10.0;
duration -= (target_traversed_in_reverse ? source_node.reverse_duration
: source_node.forward_duration);
}
std::string summary;
@@ -201,7 +196,7 @@ inline RouteLeg assembleLeg(const datafacade::BaseDataFacade &facade,
summary = boost::algorithm::join(summary_names, ", ");
}
return RouteLeg{duration, distance, summary, {}};
return RouteLeg{duration / 10., distance, summary, {}};
}
} // namespace guidance
+22 -7
View File
@@ -41,14 +41,20 @@ inline std::vector<RouteStep> assembleSteps(const datafacade::BaseDataFacade &fa
const bool source_traversed_in_reverse,
const bool target_traversed_in_reverse)
{
const double constexpr ZERO_DURATION = 0., ZERO_DISTANCE = 0.;
const double weight_multiplier = std::pow(10., facade.GetWeightPrecision());
const double constexpr ZERO_DURATION = 0., ZERO_DISTANCE = 0., ZERO_WEIGHT = 0;
const constexpr char *NO_ROTARY_NAME = "";
const EdgeWeight source_duration =
const EdgeWeight source_weight =
source_traversed_in_reverse ? source_node.reverse_weight : source_node.forward_weight;
const EdgeWeight source_duration =
source_traversed_in_reverse ? source_node.reverse_duration : source_node.forward_duration;
const auto source_mode = source_traversed_in_reverse ? source_node.backward_travel_mode
: source_node.forward_travel_mode;
const EdgeWeight target_duration =
target_traversed_in_reverse ? target_node.reverse_duration : target_node.forward_duration;
const EdgeWeight target_weight =
target_traversed_in_reverse ? target_node.reverse_weight : target_node.forward_weight;
const auto target_mode = target_traversed_in_reverse ? target_node.backward_travel_mode
: target_node.forward_travel_mode;
@@ -84,7 +90,8 @@ inline std::vector<RouteStep> assembleSteps(const datafacade::BaseDataFacade &fa
// but a RouteStep is with regard to the segment after the turn.
// We need to skip the first segment because it is already covered by the
// initial start of a route
int segment_duration = 0;
EdgeWeight segment_duration = 0;
EdgeWeight segment_weight = 0;
// some name changes are not announced in our processing. For these, we have to keep the
// first name on the segment
@@ -93,11 +100,12 @@ inline std::vector<RouteStep> assembleSteps(const datafacade::BaseDataFacade &fa
{
const auto &path_point = leg_data[leg_data_index];
segment_duration += path_point.duration_until_turn;
segment_weight += path_point.weight_until_turn;
// all changes to this check have to be matched with assemble_geometry
if (path_point.turn_instruction.type != extractor::guidance::TurnType::NoTurn)
{
BOOST_ASSERT(segment_duration >= 0);
BOOST_ASSERT(segment_weight >= 0);
const auto name = facade.GetNameForID(step_name_id);
const auto ref = facade.GetRefForID(step_name_id);
const auto pronunciation = facade.GetPronunciationForID(step_name_id);
@@ -111,8 +119,9 @@ inline std::vector<RouteStep> assembleSteps(const datafacade::BaseDataFacade &fa
destinations.to_string(),
NO_ROTARY_NAME,
NO_ROTARY_NAME,
segment_duration / 10.0,
segment_duration / 10.,
distance,
segment_weight / weight_multiplier,
path_point.travel_mode,
maneuver,
leg_geometry.FrontIndex(segment_index),
@@ -173,10 +182,12 @@ inline std::vector<RouteStep> assembleSteps(const datafacade::BaseDataFacade &fa
0};
segment_index++;
segment_duration = 0;
segment_weight = 0;
}
}
const auto distance = leg_geometry.segment_distances[segment_index];
const int duration = segment_duration + target_duration;
const EdgeWeight duration = segment_duration + target_duration;
const EdgeWeight weight = segment_weight + target_weight;
BOOST_ASSERT(duration >= 0);
steps.push_back(RouteStep{step_name_id,
facade.GetNameForID(step_name_id).to_string(),
@@ -187,6 +198,7 @@ inline std::vector<RouteStep> assembleSteps(const datafacade::BaseDataFacade &fa
NO_ROTARY_NAME,
duration / 10.,
distance,
weight / weight_multiplier,
target_mode,
maneuver,
leg_geometry.FrontIndex(segment_index),
@@ -202,7 +214,8 @@ inline std::vector<RouteStep> assembleSteps(const datafacade::BaseDataFacade &fa
// |---| source_duration
// |---------| target_duration
int duration = target_duration - source_duration;
const EdgeWeight duration = target_duration - source_duration;
const EdgeWeight weight = target_weight - source_weight;
BOOST_ASSERT(duration >= 0);
steps.push_back(RouteStep{source_node.name_id,
@@ -214,6 +227,7 @@ inline std::vector<RouteStep> assembleSteps(const datafacade::BaseDataFacade &fa
NO_ROTARY_NAME,
duration / 10.,
leg_geometry.segment_distances[segment_index],
weight / weight_multiplier,
source_mode,
std::move(maneuver),
leg_geometry.FrontIndex(segment_index),
@@ -251,6 +265,7 @@ inline std::vector<RouteStep> assembleSteps(const datafacade::BaseDataFacade &fa
NO_ROTARY_NAME,
ZERO_DURATION,
ZERO_DISTANCE,
ZERO_WEIGHT,
target_mode,
std::move(maneuver),
leg_geometry.locations.size() - 1,
+3 -2
View File
@@ -37,8 +37,9 @@ struct LegGeometry
// Per-coordinate metadata
struct Annotation
{
double distance;
double duration;
double distance; // distance in meters
double duration; // duration in seconds
double weight; // weight value
DatasourceID datasource;
};
std::vector<Annotation> annotations;
+6 -2
View File
@@ -64,8 +64,9 @@ struct RouteStep
std::string destinations;
std::string rotary_name;
std::string rotary_pronunciation;
double duration;
double distance;
double duration; // duration in seconds
double distance; // distance in meters
double weight; // weight value
extractor::TravelMode mode;
StepManeuver maneuver;
// indices into the locations array stored the LegGeometry
@@ -117,6 +118,7 @@ inline void RouteStep::Invalidate()
rotary_pronunciation.clear();
duration = 0;
distance = 0;
weight = 0;
mode = TRAVEL_MODE_INACCESSIBLE;
maneuver = getInvalidStepManeuver();
geometry_begin = 0;
@@ -132,6 +134,7 @@ inline RouteStep &RouteStep::AddInFront(const RouteStep &preceeding_step)
BOOST_ASSERT(mode == preceeding_step.mode);
duration += preceeding_step.duration;
distance += preceeding_step.distance;
weight += preceeding_step.weight;
geometry_begin = preceeding_step.geometry_begin;
intersections.insert(intersections.begin(),
@@ -148,6 +151,7 @@ inline RouteStep &RouteStep::ElongateBy(const RouteStep &following_step)
BOOST_ASSERT(mode == following_step.mode);
duration += following_step.duration;
distance += following_step.distance;
weight += following_step.weight;
geometry_end = following_step.geometry_end;
intersections.insert(intersections.end(),