Anticipate Lane Changes

This commit is contained in:
Daniel J. Hofmann
2016-06-06 13:52:41 +02:00
committed by Moritz Kobitzsch
parent efa29edf09
commit ec0a1a4ab1
7 changed files with 519 additions and 21 deletions
+1
View File
@@ -149,6 +149,7 @@ class RouteAPI : public BaseAPI
leg_geometry,
phantoms.source_phantom,
phantoms.target_phantom);
leg.steps = guidance::anticipateLaneChange(std::move(leg.steps));
leg_geometry = guidance::resyncGeometry(std::move(leg_geometry), leg.steps);
}
@@ -43,6 +43,11 @@ std::vector<RouteStep> buildIntersections(std::vector<RouteStep> steps);
// remove steps invalidated by post-processing
std::vector<RouteStep> removeNoTurnInstructions(std::vector<RouteStep> steps);
// Constrains lanes for multi-hop situations where lane changes depend on earlier ones.
// Instead of forcing users to change lanes rapidly in a short amount of time,
// we anticipate lane changes emitting only matching lanes early on.
std::vector<RouteStep> anticipateLaneChange(std::vector<RouteStep> steps);
// postProcess will break the connection between the leg geometry
// for which a segment is supposed to represent exactly the coordinates
// between routing maneuvers and the route steps itself.
+40
View File
@@ -0,0 +1,40 @@
#ifndef OSRM_GROUP_BY
#define OSRM_GROUP_BY
#include <algorithm>
#include <utility>
namespace osrm
{
namespace util
{
// Runs fn on consecutive items in sub-ranges determined by pred.
//
// Example:
// vector<int> v{1,2,2,2,3,4,4};
// group_by(first, last, even, print);
// >>> 2,2,2
// >>> 4,4
//
// Note: this mimics Python's itertools.groupby
template <typename Iter, typename Pred, typename Fn>
Fn group_by(Iter first, Iter last, Pred pred, Fn fn)
{
while (first != last)
{
first = std::find_if(first, last, pred);
auto next = std::find_if_not(first, last, pred);
(void)fn(std::make_pair(first, next));
first = next;
}
return fn;
}
} // ns util
} // ns osrm
#endif