From 6f0512cf6e7d19acff1f85f82eede2d8d01b6e1d Mon Sep 17 00:00:00 2001 From: Vladimir Byko-Ianko Date: Thu, 4 Jul 2019 11:15:41 +0300 Subject: [PATCH] [routing] Adding benchmarks on finding best segments of the route. --- routing/routing_benchmarks/CMakeLists.txt | 1 + .../bicycle_routing_tests.cpp | 5 +- .../routing_benchmarks/car_routing_tests.cpp | 78 +++++++++++++++++++ routing/routing_benchmarks/helpers.cpp | 48 ++++++------ routing/routing_benchmarks/helpers.hpp | 8 +- .../pedestrian_routing_tests.cpp | 6 +- 6 files changed, 119 insertions(+), 27 deletions(-) create mode 100644 routing/routing_benchmarks/car_routing_tests.cpp diff --git a/routing/routing_benchmarks/CMakeLists.txt b/routing/routing_benchmarks/CMakeLists.txt index ef9ae89d41..e2db6c3107 100644 --- a/routing/routing_benchmarks/CMakeLists.txt +++ b/routing/routing_benchmarks/CMakeLists.txt @@ -5,6 +5,7 @@ set( ../routing_integration_tests/routing_test_tools.cpp ../routing_integration_tests/routing_test_tools.hpp bicycle_routing_tests.cpp + car_routing_tests.cpp helpers.cpp helpers.hpp pedestrian_routing_tests.cpp diff --git a/routing/routing_benchmarks/bicycle_routing_tests.cpp b/routing/routing_benchmarks/bicycle_routing_tests.cpp index e88b1c13ac..348741957e 100644 --- a/routing/routing_benchmarks/bicycle_routing_tests.cpp +++ b/routing/routing_benchmarks/bicycle_routing_tests.cpp @@ -22,7 +22,10 @@ std::set const kMapFiles = {"Russia_Moscow"}; class BicycleTest : public RoutingTest { public: - BicycleTest() : RoutingTest(routing::IRoadGraph::Mode::ObeyOnewayTag, kMapFiles) {} + BicycleTest() + : RoutingTest(routing::IRoadGraph::Mode::ObeyOnewayTag, routing::VehicleType::Bicycle, kMapFiles) + { + } protected: // RoutingTest overrides: diff --git a/routing/routing_benchmarks/car_routing_tests.cpp b/routing/routing_benchmarks/car_routing_tests.cpp new file mode 100644 index 0000000000..a9c1088c07 --- /dev/null +++ b/routing/routing_benchmarks/car_routing_tests.cpp @@ -0,0 +1,78 @@ +#include "testing/testing.hpp" + +#include "routing/routing_benchmarks/helpers.hpp" + +#include "routing/bicycle_directions.hpp" +#include "routing/road_graph.hpp" + +#include "routing_common/car_model.hpp" + +#include "geometry/latlon.hpp" +#include "geometry/mercator.hpp" + +#include +#include +#include + +namespace +{ +std::set const kMapFiles = {"Russia_Moscow"}; + +class CarTest : public RoutingTest +{ +public: + CarTest() + : RoutingTest(routing::IRoadGraph::Mode::ObeyOnewayTag, routing::VehicleType::Car, kMapFiles) + { + } + + void TestCarRouter(ms::LatLon const & start, ms::LatLon const & final, size_t reiterations) + { + routing::Route routeFoundByAstarBidirectional("", 0 /* route id */); + auto router = CreateRouter("test-astar-bidirectional"); + + m2::PointD const startMerc = MercatorBounds::FromLatLon(start); + m2::PointD const finalMerc = MercatorBounds::FromLatLon(final); + for (size_t i = 0; i < reiterations; ++i) + TestRouter(*router, startMerc, finalMerc, routeFoundByAstarBidirectional); + } + +protected: + // RoutingTest overrides: + std::unique_ptr CreateDirectionsEngine( + std::shared_ptr numMwmIds) override + { + std::unique_ptr engine( + new routing::BicycleDirectionsEngine(m_dataSource, numMwmIds)); + return engine; + } + + std::unique_ptr CreateModelFactory() override + { + std::unique_ptr factory( + new SimplifiedModelFactory()); + return factory; + } +}; + +// Benchmarks below are on profiling looking for the best segments of routes. +// So short routes are used to focus on time needed for finding the best segments. + +// Start and finish are located in a city with dense road network. +UNIT_CLASS_TEST(CarTest, InCity) +{ + TestCarRouter(ms::LatLon(55.75785, 37.58267), ms::LatLon(55.76082, 37.58492), 30); +} + +// Start and finish are located near a big road. +UNIT_CLASS_TEST(CarTest, BigRoad) +{ + TestCarRouter(ms::LatLon(55.75826, 37.39476), ms::LatLon(55.7605, 37.39003), 30); +} + +// Start are located near an airport center. It's far from road network. +UNIT_CLASS_TEST(CarTest, InAirport) +{ + TestCarRouter(ms::LatLon(55.97285, 37.41275), ms::LatLon(55.96396, 37.41922), 30); +} +} // namespace diff --git a/routing/routing_benchmarks/helpers.cpp b/routing/routing_benchmarks/helpers.cpp index 44ed2fbd85..efd709a10b 100644 --- a/routing/routing_benchmarks/helpers.cpp +++ b/routing/routing_benchmarks/helpers.cpp @@ -4,7 +4,6 @@ #include "routing/base/astar_algorithm.hpp" #include "routing/features_road_graph.hpp" -#include "routing/route.hpp" #include "routing/router_delegate.hpp" #include "routing_integration_tests/routing_test_tools.hpp" @@ -29,26 +28,6 @@ using namespace std; namespace { -void TestRouter(routing::IRouter & router, m2::PointD const & startPos, - m2::PointD const & finalPos, routing::Route & route) -{ - routing::RouterDelegate delegate; - LOG(LINFO, ("Calculating routing ...", router.GetName())); - base::Timer timer; - auto const resultCode = router.CalculateRoute(routing::Checkpoints(startPos, finalPos), - m2::PointD::Zero() /* startDirection */, - false /* adjust */, delegate, route); - double const elapsedSec = timer.ElapsedSeconds(); - TEST_EQUAL(routing::RouterResultCode::NoError, resultCode, ()); - TEST(route.IsValid(), ()); - m2::PolylineD const & poly = route.GetPoly(); - TEST(base::AlmostEqualAbs(poly.Front(), startPos, routing::kPointsEqualEpsilon), ()); - TEST(base::AlmostEqualAbs(poly.Back(), finalPos, routing::kPointsEqualEpsilon), ()); - LOG(LINFO, ("Route polyline size:", route.GetPoly().GetSize())); - LOG(LINFO, ("Route distance, meters:", route.GetTotalDistanceMeters())); - LOG(LINFO, ("Elapsed, seconds:", elapsedSec)); -} - m2::PointD GetPointOnEdge(routing::Edge const & e, double posAlong) { if (posAlong <= 0.0) @@ -60,8 +39,9 @@ m2::PointD GetPointOnEdge(routing::Edge const & e, double posAlong) } } // namespace -RoutingTest::RoutingTest(routing::IRoadGraph::Mode mode, set const & neededMaps) - : m_mode(mode) , m_neededMaps(neededMaps) , m_numMwmIds(make_unique()) +RoutingTest::RoutingTest(routing::IRoadGraph::Mode mode, routing::VehicleType type, + set const & neededMaps) + : m_mode(mode), m_type(type), m_neededMaps(neededMaps), m_numMwmIds(make_unique()) { classificator::Load(); @@ -151,7 +131,7 @@ unique_ptr RoutingTest::CreateRouter(string const & name) } unique_ptr router = integration::CreateVehicleRouter( - m_dataSource, *m_cig, m_trafficCache, neededLocalFiles, routing::VehicleType::Pedestrian); + m_dataSource, *m_cig, m_trafficCache, neededLocalFiles, m_type); return router; } @@ -161,3 +141,23 @@ void RoutingTest::GetNearestEdges(m2::PointD const & pt, routing::FeaturesRoadGraph graph(m_dataSource, m_mode, CreateModelFactory()); graph.FindClosestEdges(pt, 1 /* count */, edges); } + +void TestRouter(routing::IRouter & router, m2::PointD const & startPos, + m2::PointD const & finalPos, routing::Route & route) +{ + routing::RouterDelegate delegate; + LOG(LINFO, ("Calculating routing ...", router.GetName())); + base::Timer timer; + auto const resultCode = router.CalculateRoute(routing::Checkpoints(startPos, finalPos), + m2::PointD::Zero() /* startDirection */, + false /* adjust */, delegate, route); + double const elapsedSec = timer.ElapsedSeconds(); + TEST_EQUAL(routing::RouterResultCode::NoError, resultCode, ()); + TEST(route.IsValid(), ()); + m2::PolylineD const & poly = route.GetPoly(); + TEST(base::AlmostEqualAbs(poly.Front(), startPos, routing::kPointsEqualEpsilon), ()); + TEST(base::AlmostEqualAbs(poly.Back(), finalPos, routing::kPointsEqualEpsilon), ()); + LOG(LINFO, ("Route polyline size:", route.GetPoly().GetSize())); + LOG(LINFO, ("Route distance, meters:", route.GetTotalDistanceMeters())); + LOG(LINFO, ("Elapsed, seconds:", elapsedSec)); +} diff --git a/routing/routing_benchmarks/helpers.hpp b/routing/routing_benchmarks/helpers.hpp index 24af033f1e..68ca1ea4b0 100644 --- a/routing/routing_benchmarks/helpers.hpp +++ b/routing/routing_benchmarks/helpers.hpp @@ -2,6 +2,7 @@ #include "routing/index_router.hpp" #include "routing/road_graph.hpp" +#include "routing/route.hpp" #include "routing/router.hpp" #include "routing/vehicle_mask.hpp" @@ -26,7 +27,8 @@ class RoutingTest { public: - RoutingTest(routing::IRoadGraph::Mode mode, std::set const & neededMaps); + RoutingTest(routing::IRoadGraph::Mode mode, routing::VehicleType type, + std::set const & neededMaps); virtual ~RoutingTest() = default; @@ -43,6 +45,7 @@ protected: std::vector> & edges); routing::IRoadGraph::Mode const m_mode; + routing::VehicleType m_type; FrozenDataSource m_dataSource; traffic::TrafficCache m_trafficCache; @@ -94,3 +97,6 @@ public: private: std::shared_ptr const m_model; }; + +void TestRouter(routing::IRouter & router, m2::PointD const & startPos, + m2::PointD const & finalPos, routing::Route & route); diff --git a/routing/routing_benchmarks/pedestrian_routing_tests.cpp b/routing/routing_benchmarks/pedestrian_routing_tests.cpp index ed92bb9979..76f29a0bc8 100644 --- a/routing/routing_benchmarks/pedestrian_routing_tests.cpp +++ b/routing/routing_benchmarks/pedestrian_routing_tests.cpp @@ -38,7 +38,11 @@ set const kMapFiles = class PedestrianTest : public RoutingTest { public: - PedestrianTest() : RoutingTest(routing::IRoadGraph::Mode::IgnoreOnewayTag, kMapFiles) {} + PedestrianTest() + : RoutingTest(routing::IRoadGraph::Mode::IgnoreOnewayTag, routing::VehicleType::Pedestrian, + kMapFiles) + { + } protected: // RoutingTest overrides: