diff options
author | Mikhail Gorbushin <m.gorbushin@corp.mail.ru> | 2019-06-17 15:41:24 +0300 |
---|---|---|
committer | Mikhail Gorbushin <m.gorbushin@corp.mail.ru> | 2019-06-17 17:53:36 +0300 |
commit | 3e917efe053279ca5b986326eb59aef8880aed9a (patch) | |
tree | 12f9ce6a2020616369c112d23b4c3a7766775e77 | |
parent | 92763a2c14e4a4df7a091c0796cce13af5951897 (diff) |
[routing] start using routes_builder in routing_quolity_testsroutes_builder_tool
-rw-r--r-- | routing/routes_builder/routes_builder.cpp | 6 | ||||
-rw-r--r-- | routing/routing_quality/routing_quality_tests/utils.cpp | 0 | ||||
-rw-r--r-- | routing/routing_quality/routing_quality_tests/utils.hpp | 0 | ||||
-rw-r--r-- | routing/routing_quality/utils.cpp | 134 | ||||
-rw-r--r-- | routing/routing_quality/utils.hpp | 39 | ||||
-rw-r--r-- | routing/routing_quality/waypoints.cpp | 44 | ||||
-rw-r--r-- | routing/routing_quality/waypoints.hpp | 22 |
7 files changed, 31 insertions, 214 deletions
diff --git a/routing/routes_builder/routes_builder.cpp b/routing/routes_builder/routes_builder.cpp index 140a8e9582..3e99ca3f4d 100644 --- a/routing/routes_builder/routes_builder.cpp +++ b/routing/routes_builder/routes_builder.cpp @@ -46,9 +46,9 @@ RoutesBuilder::RoutesBuilder(size_t threadsNumber) auto const & countryFile = localFile.GetCountryFile(); auto const mwmId = m_dataSource.GetMwmIdByCountryFile(countryFile); CHECK(mwmId.IsAlive(), ()); - // We have to exclude minsk-pass because we can't register mwm which is not from - // countries.txt. - if (mwmId.GetInfo()->GetType() == MwmInfo::COUNTRY && countryFile.GetName() != "minsk-pass") + + // Only maps from countries.txt should be used for tests. + if (m_cpg->GetStorageForTesting().IsLeaf(countryFile.GetName())) m_numMwmIds->RegisterFile(countryFile); } } diff --git a/routing/routing_quality/routing_quality_tests/utils.cpp b/routing/routing_quality/routing_quality_tests/utils.cpp new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/routing/routing_quality/routing_quality_tests/utils.cpp diff --git a/routing/routing_quality/routing_quality_tests/utils.hpp b/routing/routing_quality/routing_quality_tests/utils.hpp new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/routing/routing_quality/routing_quality_tests/utils.hpp diff --git a/routing/routing_quality/utils.cpp b/routing/routing_quality/utils.cpp deleted file mode 100644 index 582754ef6f..0000000000 --- a/routing/routing_quality/utils.cpp +++ /dev/null @@ -1,134 +0,0 @@ -#include "routing/routing_quality/utils.hpp" - -#include "routing_common/num_mwm_id.hpp" - -#include "routing/index_router.hpp" - -#include "indexer/classificator_loader.hpp" -#include "indexer/data_source.hpp" - -#include "storage/country_info_getter.hpp" -#include "storage/country_parent_getter.hpp" -#include "storage/routing_helpers.hpp" - -#include "platform/local_country_file.hpp" -#include "platform/local_country_file_utils.hpp" -#include "platform/platform.hpp" - -#include "geometry/mercator.hpp" - -#include "base/assert.hpp" -#include "base/macros.hpp" -#include "base/stl_helpers.hpp" - -#include <array> -#include <limits> -#include <memory> -#include <utility> - -using namespace std; -using namespace routing; - -namespace -{ -class RouteGetter -{ -public: - static RouteGetter & Instance() - { - static RouteGetter instance; - return instance; - } - - routing_quality::RouteResult operator()(routing_quality::RoutePoints && waypoints, VehicleType type) - { - CHECK_LESS(type, VehicleType::Count, ()); - auto const & infoGetter = *m_cig.get(); - - auto const countryFileGetter = [&infoGetter](m2::PointD const & pt) { - return infoGetter.GetRegionCountryId(pt); - }; - - auto const getMwmRectByName = [&infoGetter](string const & countryId) { - return infoGetter.GetLimitRectForLeaf(countryId); - }; - - auto const index = base::Underlying(type); - if (!m_routers[index]) - { - m_routers[index] = make_unique<IndexRouter>(type, false /* load altitudes */, *m_cpg, - countryFileGetter, getMwmRectByName, m_numMwmIds, - MakeNumMwmTree(*m_numMwmIds, infoGetter), m_trafficCache, m_dataSource); - } - - routing_quality::RouteResult result; - result.m_code = m_routers[index]->CalculateRoute( - Checkpoints(move(waypoints)), m2::PointD::Zero(), - false /* adjustToPrevRoute */, m_delegate, result.m_route); - return result; - } - -private: - RouteGetter() - { - CHECK(m_cig, ()); - CHECK(m_cpg, ()); - - classificator::Load(); - vector<platform::LocalCountryFile> localFiles; - - platform::FindAllLocalMapsAndCleanup(numeric_limits<int64_t>::max(), localFiles); - for (auto const & localFile : localFiles) - { - UNUSED_VALUE(m_dataSource.RegisterMap(localFile)); - auto const & countryFile = localFile.GetCountryFile(); - auto const mwmId = m_dataSource.GetMwmIdByCountryFile(countryFile); - CHECK(mwmId.IsAlive(), ()); - - // Only maps from countries.txt should be used for tests. - if (m_cpg->GetStorageForTesting().IsLeaf(countryFile.GetName())) - m_numMwmIds->RegisterFile(countryFile); - } - } - - DISALLOW_COPY_AND_MOVE(RouteGetter); - - FrozenDataSource m_dataSource; - shared_ptr<NumMwmIds> m_numMwmIds = make_shared<NumMwmIds>(); - array<unique_ptr<IndexRouter>, base::Underlying(VehicleType::Count)> m_routers{}; - unique_ptr<storage::CountryParentGetter> m_cpg = make_unique<storage::CountryParentGetter>(); - unique_ptr<storage::CountryInfoGetter> m_cig = storage::CountryInfoReader::CreateCountryInfoReader(GetPlatform()); - traffic::TrafficCache m_trafficCache; - RouterDelegate m_delegate; -}; -} // namespace - -namespace routing_quality -{ -FollowedPolyline GetRouteFollowedPolyline(RouteParams && params) -{ - CHECK_GREATER_OR_EQUAL(params.m_waypoints.size(), 2, ()); - auto points = FromLatLon(params.m_waypoints); - auto const result = RouteGetter::Instance()(move(points), params.m_type); - CHECK_EQUAL(result.m_code, RouterResultCode::NoError, ()); - CHECK(result.m_route.IsValid(), ()); - return result.m_route.GetFollowedPolyline(); -} - -RouteResult GetRoute(RoutePoints && waypoints, VehicleType type) -{ - CHECK_GREATER_OR_EQUAL(waypoints.size(), 2, ()); - return RouteGetter::Instance()(move(waypoints), type); -} - -RoutePoints FromLatLon(Coordinates const & coords) -{ - CHECK(!coords.empty(), ()); - RoutePoints ret; - ret.reserve(coords.size()); - for (auto const & ll : coords) - ret.emplace_back(MercatorBounds::FromLatLon(ll)); - - return ret; -} -} // namespace routing_quality diff --git a/routing/routing_quality/utils.hpp b/routing/routing_quality/utils.hpp deleted file mode 100644 index 614cf7a8a1..0000000000 --- a/routing/routing_quality/utils.hpp +++ /dev/null @@ -1,39 +0,0 @@ -#pragma once - -#include "routing/base/followed_polyline.hpp" -#include "routing/route.hpp" -#include "routing/routing_callbacks.hpp" -#include "routing/vehicle_mask.hpp" - -#include "geometry/latlon.hpp" -#include "geometry/point2d.hpp" - -#include <vector> - -namespace routing_quality -{ -using Coordinates = std::vector<ms::LatLon>; - -struct RouteParams -{ - /// Waypoints which the route passes through. - Coordinates m_waypoints; - routing::VehicleType m_type = routing::VehicleType::Car; -}; - -using RoutePoints = std::vector<m2::PointD>; - -struct RouteResult -{ - routing::Route m_route{"" /* router */, 0 /* routeId */}; - routing::RouterResultCode m_code{routing::RouterResultCode::InternalError}; -}; - -/// Builds the route based on |params| and returns its polyline. -routing::FollowedPolyline GetRouteFollowedPolyline(RouteParams && params); - -/// Builds the route with |type| through |waypoints| and returns the route object and the router result code. -RouteResult GetRoute(RoutePoints && waypoints, routing::VehicleType type); - -RoutePoints FromLatLon(Coordinates const & coords); -} // namespace routing_quality diff --git a/routing/routing_quality/waypoints.cpp b/routing/routing_quality/waypoints.cpp index 144e888b66..71628f28c8 100644 --- a/routing/routing_quality/waypoints.cpp +++ b/routing/routing_quality/waypoints.cpp @@ -1,5 +1,6 @@ #include "routing/routing_quality/waypoints.hpp" -#include "routing/routing_quality/utils.hpp" + +#include "routing/base/followed_polyline.hpp" #include "geometry/mercator.hpp" #include "geometry/point2d.hpp" @@ -16,15 +17,15 @@ namespace routing_quality { namespace metrics { -Similarity CompareByNumberOfMatchedWaypoints(routing::FollowedPolyline && polyline, ReferenceRoutes && candidates) +Similarity CompareByNumberOfMatchedWaypoints(routing::FollowedPolyline && polyline, + ReferenceRoutes && candidates) { auto constexpr kMaxDistanceFromRouteM = 15; Similarity bestResult = 0.0; for (size_t j = 0; j < candidates.size(); ++j) { routing::FollowedPolyline current = polyline; - auto const & candidate = candidates[j]; - auto const & waypoints = candidate.m_waypoints; + auto const & waypoints = candidates[j]; auto const size = waypoints.size(); CHECK_GREATER(size, 0, ()); size_t numberOfErrors = 0; @@ -40,44 +41,39 @@ Similarity CompareByNumberOfMatchedWaypoints(routing::FollowedPolyline && polyli continue; } - LOG(LINFO, ("Can't find point", ll, "with index", i)); + LOG(LDEBUG, ("Can't find point", ll, "with index", i)); ++numberOfErrors; } CHECK_LESS_OR_EQUAL(numberOfErrors, size, ()); - auto const result = ((size - numberOfErrors) / static_cast<double>(size)) * candidate.m_factor; - LOG(LINFO, ("Matching result", result, "for route with index", j)); + auto const result = ((size - numberOfErrors) / static_cast<double>(size)); + LOG(LDEBUG, ("Matching result", result, "for route with index", j)); bestResult = max(bestResult, result); } - LOG(LINFO, ("Best result", bestResult)); + LOG(LDEBUG, ("Best result", bestResult)); return bestResult; } } // namespace metrics -Similarity CheckWaypoints(RouteParams && params, ReferenceRoutes && candidates) +Similarity CheckWaypoints(Params const & params, ReferenceRoutes && referenceRoutes) { - return metrics::CompareByNumberOfMatchedWaypoints(GetRouteFollowedPolyline(move(params)), move(candidates)); + auto & builder = routing::routes_builder::RoutesBuilder::GetSimpleRoutesBuilder(); + auto result = builder.ProcessTask(params); + + return metrics::CompareByNumberOfMatchedWaypoints(move(result.m_followedPolyline), + move(referenceRoutes)); } -bool CheckRoute(routing::VehicleType type, ms::LatLon const & start, ms::LatLon const & finish, - vector<Coordinates> && referenceTracks) +bool CheckRoute(Params const & params, ReferenceRoutes && referenceRoutes) { - RouteParams params; - params.m_waypoints = {start, finish}; - params.m_type = type; - - ReferenceRoutes candidates(referenceTracks.size()); - - for (size_t i = 0; i < candidates.size(); ++i) - candidates[i].m_waypoints = move(referenceTracks[i]); - - return CheckWaypoints(move(params), move(candidates)) == 1.0; + return CheckWaypoints(params, move(referenceRoutes)) == 1.0; } bool CheckCarRoute(ms::LatLon const & start, ms::LatLon const & finish, - std::vector<Coordinates> && referenceTracks) + ReferenceRoutes && referenceTracks) { - return CheckRoute(routing::VehicleType::Car, start, finish, move(referenceTracks)); + Params params(routing::VehicleType::Car, start, finish); + return CheckRoute(params, move(referenceTracks)); } } // namespace routing_quality diff --git a/routing/routing_quality/waypoints.hpp b/routing/routing_quality/waypoints.hpp index 2e28d774c9..c617326e6c 100644 --- a/routing/routing_quality/waypoints.hpp +++ b/routing/routing_quality/waypoints.hpp @@ -1,6 +1,7 @@ #pragma once -#include "routing/routing_quality/utils.hpp" +#include "routing/routes_builder/routes_builder.hpp" + #include "routing/vehicle_mask.hpp" #include "geometry/latlon.hpp" @@ -9,29 +10,22 @@ namespace routing_quality { -struct RouteParams; +using Params = routing::routes_builder::RoutesBuilder::Params; -struct ReferenceRoute -{ - /// \brief Waypoints which the route passes through. - Coordinates m_waypoints; - /// \brief Value in range (0.0; 1.0] which indicates how desirable the route is. - double m_factor = 1.0; -}; +using Waypoints = std::vector<ms::LatLon>; /// \brief There can be more than one reference route. -using ReferenceRoutes = std::vector<ReferenceRoute>; +using ReferenceRoutes = std::vector<Waypoints>; using Similarity = double; /// \brief Checks how many reference waypoints the route contains. /// \returns normalized value in range [0.0; 1.0]. -Similarity CheckWaypoints(RouteParams && params, ReferenceRoutes && candidates); +Similarity CheckWaypoints(Params const & params, ReferenceRoutes && referenceRoutes); /// \returns true if route from |start| to |finish| fully conforms one of |candidates| /// and false otherwise. -bool CheckRoute(routing::VehicleType type, ms::LatLon const & start, ms::LatLon const & finish, - std::vector<Coordinates> && referenceTracks); +bool CheckRoute(Params const & params, ReferenceRoutes && referenceRoutes); bool CheckCarRoute(ms::LatLon const & start, ms::LatLon const & finish, - std::vector<Coordinates> && referenceTracks); + ReferenceRoutes && referenceRoutes); } // namespace routing_quality |