Adds a statistics handler for turn types and modifiers
This commit is contained in:
parent
73f4e1d45a
commit
c5b48e3506
93
include/extractor/guidance/statistics_handler.hpp
Normal file
93
include/extractor/guidance/statistics_handler.hpp
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
#ifndef OSRM_EXTRACTOR_GUIDANCE_STATISTICS_HANDLER_HPP_
|
||||||
|
#define OSRM_EXTRACTOR_GUIDANCE_STATISTICS_HANDLER_HPP_
|
||||||
|
|
||||||
|
#include "extractor/guidance/intersection.hpp"
|
||||||
|
#include "extractor/guidance/intersection_handler.hpp"
|
||||||
|
|
||||||
|
#include "util/log.hpp"
|
||||||
|
|
||||||
|
#include <mutex>
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
namespace osrm
|
||||||
|
{
|
||||||
|
namespace extractor
|
||||||
|
{
|
||||||
|
namespace guidance
|
||||||
|
{
|
||||||
|
|
||||||
|
// Unconditionally runs over all intersections and gathers statistics for
|
||||||
|
// instruction turn types and direction modifiers (see turn_instruction.hpp).
|
||||||
|
class StatisticsHandler final : public IntersectionHandler
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
StatisticsHandler(const IntersectionGenerator &intersection_generator,
|
||||||
|
const util::NodeBasedDynamicGraph &node_based_graph,
|
||||||
|
const EdgeBasedNodeDataContainer &node_data_container,
|
||||||
|
const std::vector<util::Coordinate> &coordinates,
|
||||||
|
const util::NameTable &name_table,
|
||||||
|
const SuffixTable &street_name_suffix_table)
|
||||||
|
: IntersectionHandler(node_based_graph,
|
||||||
|
node_data_container,
|
||||||
|
coordinates,
|
||||||
|
name_table,
|
||||||
|
street_name_suffix_table,
|
||||||
|
intersection_generator)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
~StatisticsHandler() override final
|
||||||
|
{
|
||||||
|
// Todo: type and modifier to string
|
||||||
|
|
||||||
|
util::Log() << "Assigned turn instruction types";
|
||||||
|
|
||||||
|
for (const auto &kv : type_hist)
|
||||||
|
util::Log() << (int)kv.first << ": " << kv.second;
|
||||||
|
|
||||||
|
util::Log() << "Assigned turn instruction modifiers";
|
||||||
|
|
||||||
|
for (const auto &kv : modifier_hist)
|
||||||
|
util::Log() << (int)kv.first << ": " << kv.second;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool canProcess(const NodeID, const EdgeID, const Intersection &) const override final
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Intersection
|
||||||
|
operator()(const NodeID, const EdgeID, Intersection intersection) const override final
|
||||||
|
{
|
||||||
|
// Lock histograms updates on a per-intersection basis.
|
||||||
|
std::lock_guard<std::mutex> defer{lock};
|
||||||
|
|
||||||
|
// Generate histograms for all roads; this way we will get duplicates
|
||||||
|
// which we would not get doing it after EBF generation. But we want
|
||||||
|
// numbers closer to the handlers and see how often handlers ran.
|
||||||
|
for (const auto &road : intersection)
|
||||||
|
{
|
||||||
|
|
||||||
|
const auto type = road.instruction.type;
|
||||||
|
const auto modifier = road.instruction.direction_modifier;
|
||||||
|
|
||||||
|
type_hist[type] += 1;
|
||||||
|
modifier_hist[modifier] += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return intersection;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
mutable std::mutex lock;
|
||||||
|
mutable std::unordered_map<TurnType::Enum, std::uint64_t> type_hist;
|
||||||
|
mutable std::unordered_map<DirectionModifier::Enum, std::uint64_t> modifier_hist;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace guidance
|
||||||
|
} // namespace extractor
|
||||||
|
} // namespace osrm
|
||||||
|
|
||||||
|
#endif // OSRM_EXTRACTOR_GUIDANCE_VALIDATION_HANDLER_HPP_
|
@ -10,6 +10,7 @@
|
|||||||
#include "extractor/guidance/motorway_handler.hpp"
|
#include "extractor/guidance/motorway_handler.hpp"
|
||||||
#include "extractor/guidance/roundabout_handler.hpp"
|
#include "extractor/guidance/roundabout_handler.hpp"
|
||||||
#include "extractor/guidance/sliproad_handler.hpp"
|
#include "extractor/guidance/sliproad_handler.hpp"
|
||||||
|
#include "extractor/guidance/statistics_handler.hpp"
|
||||||
#include "extractor/guidance/suppress_mode_handler.hpp"
|
#include "extractor/guidance/suppress_mode_handler.hpp"
|
||||||
#include "extractor/guidance/turn_classification.hpp"
|
#include "extractor/guidance/turn_classification.hpp"
|
||||||
#include "extractor/guidance/turn_handler.hpp"
|
#include "extractor/guidance/turn_handler.hpp"
|
||||||
@ -89,6 +90,7 @@ class TurnAnalysis
|
|||||||
const SliproadHandler sliproad_handler;
|
const SliproadHandler sliproad_handler;
|
||||||
const SuppressModeHandler suppress_mode_handler;
|
const SuppressModeHandler suppress_mode_handler;
|
||||||
const DrivewayHandler driveway_handler;
|
const DrivewayHandler driveway_handler;
|
||||||
|
const StatisticsHandler statistics_handler;
|
||||||
|
|
||||||
// Utility function, setting basic turn types. Prepares for normal turn handling.
|
// Utility function, setting basic turn types. Prepares for normal turn handling.
|
||||||
Intersection
|
Intersection
|
||||||
|
@ -22,6 +22,9 @@ namespace util
|
|||||||
|
|
||||||
namespace guidance
|
namespace guidance
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
inline void print(const engine::guidance::RouteStep &step)
|
inline void print(const engine::guidance::RouteStep &step)
|
||||||
{
|
{
|
||||||
std::cout << static_cast<int>(step.maneuver.instruction.type) << " "
|
std::cout << static_cast<int>(step.maneuver.instruction.type) << " "
|
||||||
|
@ -74,6 +74,12 @@ TurnAnalysis::TurnAnalysis(const util::NodeBasedDynamicGraph &node_based_graph,
|
|||||||
name_table,
|
name_table,
|
||||||
street_name_suffix_table),
|
street_name_suffix_table),
|
||||||
driveway_handler(intersection_generator,
|
driveway_handler(intersection_generator,
|
||||||
|
node_based_graph,
|
||||||
|
node_data_container,
|
||||||
|
coordinates,
|
||||||
|
name_table,
|
||||||
|
street_name_suffix_table),
|
||||||
|
statistics_handler(intersection_generator,
|
||||||
node_based_graph,
|
node_based_graph,
|
||||||
node_data_container,
|
node_data_container,
|
||||||
coordinates,
|
coordinates,
|
||||||
@ -175,6 +181,13 @@ Intersection TurnAnalysis::AssignTurnTypes(const NodeID node_prior_to_intersecti
|
|||||||
road.instruction.type = TurnType::OffRamp;
|
road.instruction.type = TurnType::OffRamp;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// After we ran all handlers and determined instruction type
|
||||||
|
// and direction modifier gather statistics about our decisions.
|
||||||
|
if (statistics_handler.canProcess(node_prior_to_intersection, entering_via_edge, intersection))
|
||||||
|
intersection = statistics_handler(
|
||||||
|
node_prior_to_intersection, entering_via_edge, std::move(intersection));
|
||||||
|
|
||||||
return intersection;
|
return intersection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user