osrm-backend/include/extractor/turn_path_compressor.hpp
Michael Bell a98074a051
Improvements to maneuver override processing (#6215)
This change unblocks the osrm-extract debug build, which is
currently failing on a maneuver override assertion.

The processing of maneuver overrides currently has three issues
- It assumes the via node(s) can't be compressed (the failing assertion)
- It can't handle via-paths containing incompressible nodes
- It doesn't interop with turn restriction on the same path

Turn restrictions and maneuver overrides both use the same
from-via-to path representation.
Therefore, we can fix these issues by consolidating their
structures and reusing the path representation for
turn restrictions, which already is robust to the above
issues.

This also simplifies some of the codebase by removing maneuver
override specific path processing.

There are ~100 maneuver overrides in the OSM database, so the
impact on processing and routing will be minimal.
2022-08-24 16:19:24 +01:00

55 lines
2.2 KiB
C++

#ifndef OSRM_EXTRACTOR_TURN_PATH_COMPRESSOR_HPP_
#define OSRM_EXTRACTOR_TURN_PATH_COMPRESSOR_HPP_
#include "util/typedefs.hpp"
#include <boost/unordered_map.hpp>
#include <vector>
namespace osrm
{
namespace extractor
{
struct TurnPath;
struct TurnRestriction;
struct UnresolvedManeuverOverride;
// OSRM stores turn paths as node -> [node] -> node instead of way -> node -> way (or
// way->[way]->way) as it is done in OSM. These paths need to match the state of graph
// compression which we perform in the graph compressor that removes certain degree two nodes from
// the graph (all but the ones with penalties/barriers, as of the state of writing).
// Since this graph compression is performed after creating the turn paths in the extraction
// phase, we need to update the involved nodes whenever one of the nodes is compressed.
//
//
// !!!! Will bind to the restriction/maneuver vectors and modify it in-place !!!!
class TurnPathCompressor
{
public:
TurnPathCompressor(std::vector<TurnRestriction> &restrictions,
std::vector<UnresolvedManeuverOverride> &maneuver_overrides);
// account for the compression of `from-via-to` into `from-to`
void Compress(const NodeID from, const NodeID via, const NodeID to);
private:
// A turn path is given as `from start via node(s) to end`. Edges ending at `head` being
// contracted move the head pointer to their respective head. Edges starting at tail move the
// tail values to their respective tails.
// Via nodes that are compressed are removed from the restriction representation.
// We do not compress the first and last via nodes of a restriction as they act as
// entrance/exit points into the restriction graph. For a node restriction, the first and last
// via nodes are the same.
// Similarly, we do not compress the instruction via node in a maneuver override, as we need
// this to identify the location of the maneuver during routing path-processing.
boost::unordered_multimap<NodeID, TurnPath *> starts;
boost::unordered_multimap<NodeID, TurnPath *> vias;
boost::unordered_multimap<NodeID, TurnPath *> ends;
};
} // namespace extractor
} // namespace osrm
#endif // OSRM_EXTRACTOR_TURN_PATH_COMPRESSOR_HPP_