Format all C++ and Java code via clang-format

Signed-off-by: Konstantin Pastbin <konstantin.pastbin@gmail.com>
This commit is contained in:
Konstantin Pastbin
2025-08-17 14:32:37 +07:00
parent 9f0290c0ec
commit bfffa1fff4
2169 changed files with 56441 additions and 64188 deletions

View File

@@ -127,11 +127,11 @@ routing::VehicleType Response::GetVehicleType() const
UNREACHABLE();
}
RoutingApi::RoutingApi(std::string name, std::string token, uint32_t maxRPS)
: m_apiName(std::move(name))
, m_accessToken(std::move(token))
, m_maxRPS(maxRPS) {}
, m_maxRPS(maxRPS)
{}
Response RoutingApi::CalculateRoute(Params const & params, int32_t startTimeZoneUTC) const
{

View File

@@ -58,9 +58,7 @@ namespace google
// static
std::string const GoogleApi::kApiName = "google";
GoogleApi::GoogleApi(std::string const & token)
: RoutingApi(kApiName, token, kMaxRPS)
{}
GoogleApi::GoogleApi(std::string const & token) : RoutingApi(kApiName, token, kMaxRPS) {}
Response GoogleApi::CalculateRoute(Params const & params, int32_t startTimeZoneUTC) const
{
@@ -80,7 +78,7 @@ Response GoogleApi::CalculateRoute(Params const & params, int32_t startTimeZoneU
auto const startLatLon = leg.m_steps.front().m_startLocation;
apiRoute.m_waypoints.emplace_back(startLatLon.m_lat, startLatLon.m_lon);
for (const auto & step : leg.m_steps)
for (auto const & step : leg.m_steps)
{
auto const & prev = step.m_startLocation;
auto const & next = step.m_endLocation;
@@ -135,11 +133,9 @@ std::string GoogleApi::GetDirectionsURL(Params const & params, int32_t startTime
LOG(LDEBUG, ("&departure_time =", secondFromEpoch));
std::stringstream ss;
ss << kBaseUrl
<< "&origin=" << std::to_string(start.m_lat) << "," << std::to_string(start.m_lon)
ss << kBaseUrl << "&origin=" << std::to_string(start.m_lat) << "," << std::to_string(start.m_lon)
<< "&destination=" << std::to_string(finish.m_lat) << "," << std::to_string(finish.m_lon)
<< "&key=" << GetAccessToken()
<< "&alternatives=true"
<< "&key=" << GetAccessToken() << "&alternatives=true"
<< "&departure_time=" << secondFromEpoch;
return ss.str();

View File

@@ -32,6 +32,6 @@ private:
GoogleResponse MakeRequest(Params const & params, int32_t startTimeZoneUTC) const;
std::string GetDirectionsURL(Params const & params, int32_t startTimeZoneUTC) const;
};
} // namespace mapbox
} // namespace google
} // namespace api
} // namespace routing_quality

View File

@@ -27,6 +27,6 @@ std::string DebugPrint(LatLon const & latlon)
ss << "google::LatLon(" << latlon.m_lat << ", " << latlon.m_lon << ")";
return ss.str();
}
} // namespace mapbox
} // namespace google
} // namespace api
} // namespace routing_quality

View File

@@ -15,8 +15,7 @@ namespace google
{
struct LatLon
{
DECLARE_VISITOR(visitor(m_lat, "lat"),
visitor(m_lon, "lng"))
DECLARE_VISITOR(visitor(m_lat, "lat"), visitor(m_lon, "lng"))
bool operator==(LatLon const & rhs) const;
@@ -26,8 +25,7 @@ struct LatLon
struct Step
{
DECLARE_VISITOR(visitor(m_startLocation, "start_location"),
visitor(m_endLocation, "end_location"))
DECLARE_VISITOR(visitor(m_startLocation, "start_location"), visitor(m_endLocation, "end_location"))
bool operator==(Step const & rhs) const;
@@ -51,9 +49,7 @@ struct Distance
struct Leg
{
DECLARE_VISITOR(visitor(m_distance, "distance"),
visitor(m_duration, "duration"),
visitor(m_steps, "steps"))
DECLARE_VISITOR(visitor(m_distance, "distance"), visitor(m_duration, "duration"), visitor(m_steps, "steps"))
Distance m_distance;
Duration m_duration;
@@ -76,6 +72,6 @@ struct GoogleResponse
};
std::string DebugPrint(LatLon const & latlon);
} // namespace mapbox
} // namespace google
} // namespace api
} // namespace routing_quality

View File

@@ -55,9 +55,7 @@ namespace routing_quality::api::mapbox
// static
std::string const MapboxApi::kApiName = "mapbox";
MapboxApi::MapboxApi(std::string const & token)
: RoutingApi(kApiName, token, kMaxRPS)
{}
MapboxApi::MapboxApi(std::string const & token) : RoutingApi(kApiName, token, kMaxRPS) {}
Response MapboxApi::CalculateRoute(Params const & params, int32_t /* startTimeZoneUTC */) const
{
@@ -120,8 +118,7 @@ std::string MapboxApi::GetDirectionsURL(Params const & params) const
coords.emplace_back(mercator::ToLatLon(point));
std::ostringstream oss;
oss << kBaseURL << "directions/" << kDirectionsApiVersion << "/"
<< VehicleTypeToMapboxType(params.m_type) << "/";
oss << kBaseURL << "directions/" << kDirectionsApiVersion << "/" << VehicleTypeToMapboxType(params.m_type) << "/";
oss << LatLonsToString(coords) << "?";
oss << "access_token=" << GetAccessToken() << "&";
oss << "overview=simplified&"
@@ -130,4 +127,4 @@ std::string MapboxApi::GetDirectionsURL(Params const & params) const
return oss.str();
}
} // namespace mapbox::api::routing_quality
} // namespace routing_quality::api::mapbox

View File

@@ -4,7 +4,6 @@
#include "routing/routing_quality/api/mapbox/types.hpp"
#include <cstdint>
#include <string>
#include <utility>

View File

@@ -27,9 +27,7 @@ struct Geometry
struct Route
{
DECLARE_VISITOR(visitor(m_geometry, "geometry"),
visitor(m_duration, "duration"),
visitor(m_distance, "distance"))
DECLARE_VISITOR(visitor(m_geometry, "geometry"), visitor(m_duration, "duration"), visitor(m_distance, "distance"))
Geometry m_geometry;
double m_duration = 0.0;

View File

@@ -15,14 +15,14 @@ UNIT_TEST(RoutingQuality_Broad_Node_Jamaica)
{
TEST(CheckCarRoute({17.94727, -76.25429} /* start */, {17.94499, -76.25459} /* finish */,
{{{17.945150, -76.25442}}} /* reference point */),
());
());
}
UNIT_TEST(RoutingQuality_Broad_Way_Jamaica)
{
TEST(CheckCarRoute({18.10260, -76.98374} /* start */, {18.10031, -76.98374} /* finish */,
{{{18.10078, -76.98412}}} /* reference point */),
());
());
}
UNIT_TEST(RoutingQuality_Broad_Node_Spain)

View File

@@ -25,7 +25,7 @@ UNIT_TEST(RoutingQuality_TurkeyIzmirArea)
UNIT_TEST(RoutingQuality_BosniaAndHerzegovina)
{
TEST(CheckCarRoute({42.71401, 18.30412} /* start */, {42.95101, 18.08966} /* finish */,
{{{42.88222,17.9919}}} /* reference track */),
{{{42.88222, 17.9919}}} /* reference track */),
());
}
@@ -96,17 +96,22 @@ UNIT_TEST(RoutingQuality_KrasnoyarskBratsk)
UNIT_TEST(RoutingQuality_VoronezhSochi)
{
TEST(CheckCarRoute({51.65487, 39.21293} /* start */, {43.58547, 39.72311} /* finish */,
{{{46.14169, 39.85306}, {45.17069, 39.10869},
{45.02157, 39.12510}, {44.54344, 38.95853}}} /* reference track */),
{{{46.14169, 39.85306},
{45.17069, 39.10869},
{45.02157, 39.12510},
{44.54344, 38.95853}}} /* reference track */),
());
}
UNIT_TEST(RoutingQuality_BerlinkaWarsawPoland)
{
TEST(CheckCarRoute({54.41616, 20.05675} /* start */, {52.18937, 20.94026} /* finish */,
{{{54.24278, 19.66106}, {54.13679, 19.45166},
{54.06452, 19.62416}, {53.69769, 19.98204},
{53.11194, 20.40002}, {52.62966, 20.38488}}} /* reference track */),
{{{54.24278, 19.66106},
{54.13679, 19.45166},
{54.06452, 19.62416},
{53.69769, 19.98204},
{53.11194, 20.40002},
{52.62966, 20.38488}}} /* reference track */),
());
}

View File

@@ -15,7 +15,7 @@ UNIT_TEST(Ferry_RoutingQuality_FinlandBridgeInsteadOfFerry)
// TODO: This test doesn't pass because routing::RouteWeight::operator<
// prefer roads with less number of barriers. It will be more useful to consider
// barriers only with access=no/private/etc tag.
//UNIT_TEST(Ferry_RoutingQuality_RussiaToCrimeaFerry)
// UNIT_TEST(Ferry_RoutingQuality_RussiaToCrimeaFerry)
//{
// // From Russia to Crimea
// TEST(CheckCarRoute({45.34123, 36.67679} /* start */, {45.36479, 36.62194} /* finish */,

View File

@@ -12,11 +12,11 @@ UNIT_TEST(RoutingQuality_RussiaZelegonrad2Domodedovo)
{
// From Zelenograd to Domodedovo. MKAD should be preferred.
TEST(CheckCarRoute({55.98301, 37.21141} /* start */, {55.42081, 37.89361} /* finish */,
{{{55.99751, 37.23804}, // Through M-11 and MKAD.
{{{55.99751, 37.23804}, // Through M-11 and MKAD.
{56.00719, 37.28533},
{55.88759, 37.48068},
{55.83513, 37.39569}},
{{55.99775, 37.24941}, // Through M-10 and MKAD.
{{55.99775, 37.24941}, // Through M-10 and MKAD.
{55.88627, 37.43915},
{55.86882, 37.40784},
{55.58645, 37.71672},
@@ -69,7 +69,7 @@ UNIT_TEST(RoutingQuality_EnglandLondon)
// After map update to 190719 the route starts go throw Chernigov instead of using
// passby way. It should be fix and the test should be uncommented.
//UNIT_TEST(RoutingQuality_UkraineChernigov)
// UNIT_TEST(RoutingQuality_UkraineChernigov)
//{
// TEST(CheckCarRoute({51.29419, 31.25718} /* start */, {51.62678, 31.21787} /* finish */,
// {{{51.48362, 31.18757}}} /* reference point */),
@@ -111,9 +111,8 @@ UNIT_TEST(RoutingQuality_SlovenijaLjubljana)
());
}
// TODO: Uncomment this test when correct city boundaries or crossroads will be ready.
//UNIT_TEST(RoutingQuality_FrancePoitiers)
// UNIT_TEST(RoutingQuality_FrancePoitiers)
//{
// TEST(CheckCarRoute({46.63612, 0.35762} /* start */, {46.49, 0.36787} /* finish */,
// {{{46.58706, 0.39232}}} /* reference point */),
@@ -146,6 +145,5 @@ UNIT_TEST(RoutingQuality_SouthernDenmarkPastUnclassified)
TEST(CheckCarRoute({55.44681, 10.29} /* start */, {55.45877, 10.26456} /* finish */,
{{{55.45505, 10.26972}}} /* reference point */),
());
}
} // namespace

View File

@@ -30,9 +30,7 @@ UNIT_TEST(RoutingQuality_Sokol2Mayakovskaya)
Params params(VehicleType::Car, {55.80432, 37.51603} /* start */, {55.77019, 37.59558} /* finish */);
// All points lie on the alternate so the result should be 0.
ReferenceRoutes waypoints = {{
{55.79599, 37.54114}, {55.78142, 37.57364}, {55.77863, 37.57989}
}};
ReferenceRoutes waypoints = {{{55.79599, 37.54114}, {55.78142, 37.57364}, {55.77863, 37.57989}}};
TEST_EQUAL(CheckWaypoints(params, std::move(waypoints)), 0.0, ());
}

View File

@@ -39,8 +39,8 @@ void LogIfNotConsistent(RoutesBuilder::Result const & oldRes, RoutesBuilder::Res
bool const sameDistance = AlmostEqualAbs(oldRoute.m_distance, newRoute.m_distance, 1.0);
if (!sameETA || !sameDistance)
{
LOG(LINFO, ("old ETA:", oldRoute.m_eta, "old distance:", oldRoute.m_distance, "new ETA:",
newRoute.m_eta, "new distance:", newRoute.m_distance, start, finish));
LOG(LINFO, ("old ETA:", oldRoute.m_eta, "old distance:", oldRoute.m_distance, "new ETA:", newRoute.m_eta,
"new distance:", newRoute.m_distance, start, finish));
}
}
@@ -52,9 +52,7 @@ void FillInfoAboutBuildTimeGroupByPreviousResults(std::vector<std::string> & lab
bars.clear();
labels.clear();
std::sort(times.begin(), times.end(), [](auto const & a, auto const & b) {
return a.m_oldTime < b.m_oldTime;
});
std::sort(times.begin(), times.end(), [](auto const & a, auto const & b) { return a.m_oldTime < b.m_oldTime; });
size_t constexpr kSteps = 10;
size_t const step = times.size() / kSteps;
@@ -78,8 +76,8 @@ void FillInfoAboutBuildTimeGroupByPreviousResults(std::vector<std::string> & lab
startFrom = i + 1;
double const curRight = times[i].m_oldTime;
labels.emplace_back("[" + strings::to_string_dac(curLeft, 2 /* dac */) + "s, " +
strings::to_string_dac(curRight, 2 /* dac */) + "s]\\n" +
"Routes count:\\n" + std::to_string(curCount));
strings::to_string_dac(curRight, 2 /* dac */) + "s]\\n" + "Routes count:\\n" +
std::to_string(curCount));
if (curCount != 0)
{
curSumOld /= curCount;
@@ -92,8 +90,7 @@ void FillInfoAboutBuildTimeGroupByPreviousResults(std::vector<std::string> & lab
}
}
std::vector<double> GetBoostPercents(BenchmarkResults const & oldResults,
BenchmarkResults const & newResults)
std::vector<double> GetBoostPercents(BenchmarkResults const & oldResults, BenchmarkResults const & newResults)
{
std::vector<double> boostPercents;
for (size_t i = 0; i < oldResults.GetBuildTimes().size(); ++i)
@@ -135,9 +132,8 @@ static std::string const kPythonEtaDiffPercent = "eta_diff_percent.py";
// see here: https://github.com/mapsme/omim/pull/12401
static std::string const kPythonSmartDistr = "show_smart_boost_distr.py";
void RunBenchmarkStat(
std::vector<std::pair<RoutesBuilder::Result, std::string>> const & mapsmeResults,
std::string const & dirForResults)
void RunBenchmarkStat(std::vector<std::pair<RoutesBuilder::Result, std::string>> const & mapsmeResults,
std::string const & dirForResults)
{
BenchmarkResults benchmarkResults;
ErrorTypeCounter errorTypeCounter;
@@ -153,8 +149,7 @@ void RunBenchmarkStat(
}
auto pythonScriptPath = base::JoinPath(dirForResults, kPythonDistTimeBuilding);
CreatePythonScriptForDistribution(pythonScriptPath, "Route building time, seconds",
benchmarkResults.GetBuildTimes());
CreatePythonScriptForDistribution(pythonScriptPath, "Route building time, seconds", benchmarkResults.GetBuildTimes());
LOG(LINFO, ("Average route time building:", benchmarkResults.GetAverageBuildTime(), "seconds."));
@@ -168,10 +163,9 @@ void RunBenchmarkStat(
}
pythonScriptPath = base::JoinPath(dirForResults, kPythonGraphTimeAndCount);
CreatePythonGraphByPointsXY(pythonScriptPath,
"Building time, seconds" /* xlabel */,
"Percent of routes built less than" /* ylabel */,
{countToTimes}, {"mapsme"} /* legends */);
CreatePythonGraphByPointsXY(pythonScriptPath, "Building time, seconds" /* xlabel */,
"Percent of routes built less than" /* ylabel */, {countToTimes},
{"mapsme"} /* legends */);
pythonScriptPath = base::JoinPath(dirForResults, kPythonBarError);
@@ -179,14 +173,13 @@ void RunBenchmarkStat(
std::vector<double> heights;
FillLabelsAndErrorTypeDistribution(labels, heights, errorTypeCounter);
CreatePythonBarByMap(pythonScriptPath, labels, {heights}, {"mapsme"} /* legends */,
"Type of errors" /* xlabel */, "Number of errors" /* ylabel */);
CreatePythonBarByMap(pythonScriptPath, labels, {heights}, {"mapsme"} /* legends */, "Type of errors" /* xlabel */,
"Number of errors" /* ylabel */);
}
void RunBenchmarkComparison(
std::vector<std::pair<RoutesBuilder::Result, std::string>> && mapsmeResults,
std::vector<std::pair<RoutesBuilder::Result, std::string>> && mapsmeOldResults,
std::string const & dirForResults)
void RunBenchmarkComparison(std::vector<std::pair<RoutesBuilder::Result, std::string>> && mapsmeResults,
std::vector<std::pair<RoutesBuilder::Result, std::string>> && mapsmeOldResults,
std::string const & dirForResults)
{
BenchmarkResults benchmarkResults;
BenchmarkResults benchmarkOldResults;
@@ -227,8 +220,7 @@ void RunBenchmarkComparison(
LogIfNotConsistent(mapsmeOldResult, mapsmeResult);
CHECK(!mapsmeOldResult.m_routes.empty() && !mapsmeResult.m_routes.empty(), ());
auto const etaDiff =
(mapsmeOldResult.m_routes.back().m_eta - mapsmeResult.m_routes.back().m_eta);
auto const etaDiff = (mapsmeOldResult.m_routes.back().m_eta - mapsmeResult.m_routes.back().m_eta);
auto const etaDiffPercent = etaDiff / mapsmeOldResult.m_routes.back().m_eta * 100.0;
etaDiffs.emplace_back(etaDiff);
@@ -258,9 +250,8 @@ void RunBenchmarkComparison(
auto const newAverage = benchmarkResults.GetAverageBuildTime();
auto const averageTimeDiff = (oldAverage - newAverage) / oldAverage * 100.0;
LOG(LINFO, ("Average route time building. "
"Old version:", oldAverage,
"New version:", newAverage,
"(", -averageTimeDiff, "% )"));
"Old version:",
oldAverage, "New version:", newAverage, "(", -averageTimeDiff, "% )"));
std::vector<std::vector<m2::PointD>> graphics;
for (auto const & results : {benchmarkOldResults, benchmarkResults})
@@ -287,30 +278,26 @@ void RunBenchmarkComparison(
FillLabelsAndErrorTypeDistribution(labels, errorsCount, errorTypeCounter, errorTypeCounterOld);
pythonScriptPath = base::JoinPath(dirForResults, kPythonBarError);
CreatePythonBarByMap(pythonScriptPath, labels, errorsCount,
{"old mapsme", "new mapsme"} /* legends */, "Type of errors" /* xlabel */,
"Number of errors" /* ylabel */);
CreatePythonBarByMap(pythonScriptPath, labels, errorsCount, {"old mapsme", "new mapsme"} /* legends */,
"Type of errors" /* xlabel */, "Number of errors" /* ylabel */);
auto const boostPercents = GetBoostPercents(benchmarkOldResults, benchmarkResults);
pythonScriptPath = base::JoinPath(dirForResults, kPythonBarBoostPercentDistr);
CreatePythonScriptForDistribution(pythonScriptPath, "Boost percent" /* title */, boostPercents);
pythonScriptPath = base::JoinPath(dirForResults, kPythonEtaDiff);
CreatePythonScriptForDistribution(pythonScriptPath, "ETA diff distribution" /* title */,
etaDiffs);
CreatePythonScriptForDistribution(pythonScriptPath, "ETA diff distribution" /* title */, etaDiffs);
pythonScriptPath = base::JoinPath(dirForResults, kPythonEtaDiffPercent);
CreatePythonScriptForDistribution(pythonScriptPath, "ETA diff percent distribution" /* title */,
etaDiffsPercent);
CreatePythonScriptForDistribution(pythonScriptPath, "ETA diff percent distribution" /* title */, etaDiffsPercent);
std::vector<std::vector<double>> bars;
FillInfoAboutBuildTimeGroupByPreviousResults(labels, bars, std::move(times));
pythonScriptPath = base::JoinPath(dirForResults, kPythonSmartDistr);
CreatePythonBarByMap(
pythonScriptPath, labels, bars, {"old mapsme", "new mapsme"} /* legends */,
"Intervals of groups (build time in old mapsme)" /* xlabel */,
"Boost\\nRight column is so lower/higher than the left\\n how much the average build time "
"has decreased in each group)" /* ylabel */,
false /* drawPercents */);
CreatePythonBarByMap(pythonScriptPath, labels, bars, {"old mapsme", "new mapsme"} /* legends */,
"Intervals of groups (build time in old mapsme)" /* xlabel */,
"Boost\\nRight column is so lower/higher than the left\\n how much the average build time "
"has decreased in each group)" /* ylabel */,
false /* drawPercents */);
}
} // namespace routing_quality::routing_quality_tool

View File

@@ -12,8 +12,7 @@ using RouteResult = routing::routes_builder::RoutesBuilder::Result;
void RunBenchmarkStat(std::vector<std::pair<RouteResult, std::string>> const & mapsmeResults,
std::string const & dirForResults);
void RunBenchmarkComparison(
std::vector<std::pair<RouteResult, std::string>> && mapsmeResults,
std::vector<std::pair<RouteResult, std::string>> && mapsmeOldResults,
std::string const & dirForResults);
void RunBenchmarkComparison(std::vector<std::pair<RouteResult, std::string>> && mapsmeResults,
std::vector<std::pair<RouteResult, std::string>> && mapsmeOldResults,
std::string const & dirForResults);
} // namespace routing_quality::routing_quality_tool

View File

@@ -22,8 +22,7 @@ void ErrorTypeCounter::PushError(api::ResultCode code)
PushError(routingCode);
}
void FillLabelsAndErrorTypeDistribution(std::vector<std::string> & labels,
std::vector<double> & errorsTypeDistribution,
void FillLabelsAndErrorTypeDistribution(std::vector<std::string> & labels, std::vector<double> & errorsTypeDistribution,
ErrorTypeCounter const & counter)
{
errorsTypeDistribution.clear();
@@ -37,8 +36,7 @@ void FillLabelsAndErrorTypeDistribution(std::vector<std::string> & labels,
void FillLabelsAndErrorTypeDistribution(std::vector<std::string> & labels,
std::vector<std::vector<double>> & errorsTypeDistribution,
ErrorTypeCounter const & counter,
ErrorTypeCounter const & counterOld)
ErrorTypeCounter const & counter, ErrorTypeCounter const & counterOld)
{
errorsTypeDistribution.clear();
errorsTypeDistribution.resize(2);

View File

@@ -22,12 +22,10 @@ private:
std::map<std::string, size_t> m_errorCounter;
};
void FillLabelsAndErrorTypeDistribution(std::vector<std::string> & labels,
std::vector<double> & errorsTypeDistribution,
void FillLabelsAndErrorTypeDistribution(std::vector<std::string> & labels, std::vector<double> & errorsTypeDistribution,
ErrorTypeCounter const & counter);
void FillLabelsAndErrorTypeDistribution(std::vector<std::string> & labels,
std::vector<std::vector<double>> & errorsTypeDistribution,
ErrorTypeCounter const & counter,
ErrorTypeCounter const & counterOld);
ErrorTypeCounter const & counter, ErrorTypeCounter const & counterOld);
} // namespace routing_quality::routing_quality_tool

View File

@@ -1,6 +1,6 @@
#include "routing/routing_quality/routing_quality_tool/utils.hpp"
#include "routing/routing_quality/routing_quality_tool/benchmark_stat.hpp"
#include "routing/routing_quality/routing_quality_tool/error_type_counter.hpp"
#include "routing/routing_quality/routing_quality_tool/utils.hpp"
#include "routing/routing_quality/api/api.hpp"
@@ -28,8 +28,9 @@ DEFINE_string(api_results, "", "Path to directory with api router results.");
DEFINE_string(save_results, "", "The directory where results of tool will be saved.");
DEFINE_double(kml_percent, 0.0, "The percent of routes for which kml file will be generated."
"With kml files you can make screenshots with a desktop app");
DEFINE_double(kml_percent, 0.0,
"The percent of routes for which kml file will be generated."
"With kml files you can make screenshots with a desktop app");
DEFINE_bool(benchmark_stat, false, "Dump statistics about route time building.");
@@ -60,7 +61,8 @@ This tool takes two paths to directory with routes, that were dumped by routes_b
--kml_percent may be used in non-benchamrk mode for dumping kmls and visual comparison different routes.
)";
auto const addStringInfo = [&usage](auto const & arg, auto const & argValue) {
auto const addStringInfo = [&usage](auto const & arg, auto const & argValue)
{
using T = decltype(argValue);
usage << "\n\t" << arg << " is";
if (argValue == T{})
@@ -91,7 +93,7 @@ bool HasHelpFlags(int argc, char ** argv)
}
return false;
}
} // namespace
} // namespace
using namespace routing;
using namespace routes_builder;
@@ -166,8 +168,7 @@ void RunComparison(std::vector<std::pair<RoutesBuilder::Result, std::string>> &&
{
ErrorTypeCounter mapsmeErrorCounter;
ErrorTypeCounter anotherErrorCounter;
ComparisonType type = IsMapsmeVsApi() ? ComparisonType::MapsmeVsApi
: ComparisonType::MapsmeVsMapsme;
ComparisonType type = IsMapsmeVsApi() ? ComparisonType::MapsmeVsApi : ComparisonType::MapsmeVsMapsme;
RoutesSaver routesSaver(FLAGS_save_results, type);
std::vector<Result> results;
size_t apiErrors = 0;
@@ -212,16 +213,15 @@ void RunComparison(std::vector<std::pair<RoutesBuilder::Result, std::string>> &&
for (auto const & route : anotherResult.GetRoutes())
{
auto const similarity =
metrics::CompareByNumberOfMatchedWaypoints(mapsmeRoute.m_followedPolyline,
route.GetWaypoints());
metrics::CompareByNumberOfMatchedWaypoints(mapsmeRoute.m_followedPolyline, route.GetWaypoints());
if (maxSimilarity < similarity)
{
maxSimilarity = similarity;
if (maxSimilarity == 1.0)
{
etaDiff = 100.0 * std::abs(route.GetETA() - mapsmeRoute.GetETA()) /
std::max(route.GetETA(), mapsmeRoute.GetETA());
etaDiff =
100.0 * std::abs(route.GetETA() - mapsmeRoute.GetETA()) / std::max(route.GetETA(), mapsmeRoute.GetETA());
}
}
}
@@ -236,8 +236,7 @@ void RunComparison(std::vector<std::pair<RoutesBuilder::Result, std::string>> &&
std::vector<std::string> errorLabels;
std::vector<std::vector<double>> errorsCount;
FillLabelsAndErrorTypeDistribution(errorLabels, errorsCount, mapsmeErrorCounter,
anotherErrorCounter);
FillLabelsAndErrorTypeDistribution(errorLabels, errorsCount, mapsmeErrorCounter, anotherErrorCounter);
auto const pythonScriptPath = base::JoinPath(FLAGS_save_results, kPythonBarDistributionError);
CreatePythonBarByMap(pythonScriptPath, errorLabels, errorsCount,
@@ -247,14 +246,13 @@ void RunComparison(std::vector<std::pair<RoutesBuilder::Result, std::string>> &&
void CheckArgs()
{
bool const modeIsChosen = IsMapsmeVsApi() || IsMapsmeVsMapsme() || IsMapsmeBenchmarkStat() ||
IsMapsmeVsMapsmeBenchmarkStat();
bool const modeIsChosen =
IsMapsmeVsApi() || IsMapsmeVsMapsme() || IsMapsmeBenchmarkStat() || IsMapsmeVsMapsmeBenchmarkStat();
if (!modeIsChosen)
PrintHelpAndExit();
CHECK(!FLAGS_save_results.empty(),
("\n\n\t--save_results is required. Tool will save results there.",
"\n\nType --help for usage."));
("\n\n\t--save_results is required. Tool will save results there.", "\n\nType --help for usage."));
}
int Main(int argc, char ** argv)
@@ -269,12 +267,11 @@ int Main(int argc, char ** argv)
if (Platform::IsFileExistsByFullPath(FLAGS_save_results))
CheckDirExistence(FLAGS_save_results);
else
CHECK_EQUAL(Platform::MkDir(FLAGS_save_results), Platform::EError::ERR_OK,());
CHECK_EQUAL(Platform::MkDir(FLAGS_save_results), Platform::EError::ERR_OK, ());
CheckDirExistence(FLAGS_mapsme_results);
CHECK(0.0 <= FLAGS_kml_percent && FLAGS_kml_percent <= 100.0,
("--kml_percent should be in interval: [0.0, 100.0]."));
CHECK(0.0 <= FLAGS_kml_percent && FLAGS_kml_percent <= 100.0, ("--kml_percent should be in interval: [0.0, 100.0]."));
LOG(LINFO, ("Start loading mapsme results."));
auto mapsmeResults = LoadResults<RoutesBuilder::Result>(FLAGS_mapsme_results);
@@ -292,8 +289,7 @@ int Main(int argc, char ** argv)
LOG(LINFO, ("Benchmark different mapsme versions. Start loading old mapsme results."));
auto oldMapsmeResults = LoadResults<RoutesBuilder::Result>(FLAGS_mapsme_old_results);
LOG(LINFO, ("Receive:", oldMapsmeResults.size(), "routes from --mapsme_old_results."));
RunBenchmarkComparison(std::move(mapsmeResults), std::move(oldMapsmeResults),
FLAGS_save_results);
RunBenchmarkComparison(std::move(mapsmeResults), std::move(oldMapsmeResults), FLAGS_save_results);
}
else if (IsMapsmeVsMapsme())
{

View File

@@ -30,8 +30,7 @@ void PrintWithSpaces(std::string const & str, size_t maxN)
std::cout << " ";
}
std::vector<geometry::PointWithAltitude> ConvertToPointsWithAltitudes(
std::vector<ms::LatLon> const & latlons)
std::vector<geometry::PointWithAltitude> ConvertToPointsWithAltitudes(std::vector<ms::LatLon> const & latlons)
{
std::vector<geometry::PointWithAltitude> result;
result.reserve(latlons.size());
@@ -63,8 +62,7 @@ kml::BookmarkData CreateBookmark(m2::PointD const & point, bool isStart)
}
template <typename AnotherResult>
void SaveKmlFileDataTo(RoutesBuilder::Result const & mapsmeResult,
AnotherResult const & apiResult,
void SaveKmlFileDataTo(RoutesBuilder::Result const & mapsmeResult, AnotherResult const & apiResult,
std::string const & kmlFile)
{
static std::array<uint32_t, 5> const kColors = {
@@ -140,15 +138,15 @@ namespace routing_quality
{
namespace routing_quality_tool
{
Result::Result(std::string mapsmeDumpPath, std::string anotherDumpPath,
ms::LatLon const & start, ms::LatLon const & finish, double similarity,
double etaDiffPercent)
Result::Result(std::string mapsmeDumpPath, std::string anotherDumpPath, ms::LatLon const & start,
ms::LatLon const & finish, double similarity, double etaDiffPercent)
: m_mapsmeDumpPath(std::move(mapsmeDumpPath))
, m_anotherDumpPath(std::move(anotherDumpPath))
, m_start(start)
, m_finish(finish)
, m_similarity(similarity)
, m_etaDiffPercent(etaDiffPercent) {}
, m_etaDiffPercent(etaDiffPercent)
{}
bool Result::operator<(Result const & rhs) const
{
@@ -168,17 +166,14 @@ void RoutesSaver::PushRoute(Result const & result)
m_output << result.m_mapsmeDumpPath << " " << result.m_anotherDumpPath << std::endl;
}
void RoutesSaver::PushError(routing::RouterResultCode code,
ms::LatLon const & start,
ms::LatLon const & finish)
void RoutesSaver::PushError(routing::RouterResultCode code, ms::LatLon const & start, ms::LatLon const & finish)
{
CHECK_NOT_EQUAL(code, routing::RouterResultCode::NoError, ("Only errors codes."));
auto & ofstream = m_errorRoutes[code];
if (!ofstream.is_open())
{
std::string const fullpath =
base::JoinPath(m_targetDir, DebugPrint(code) + ".routes");
std::string const fullpath = base::JoinPath(m_targetDir, DebugPrint(code) + ".routes");
ofstream.open(fullpath);
CHECK(ofstream.good(), ("Can not open:", fullpath, "for writing."));
@@ -217,8 +212,7 @@ void RoutesSaver::TurnToNextFile()
std::string RoutesSaver::GetCurrentPath() const
{
std::string const fullpath =
base::JoinPath(m_targetDir, std::to_string(m_fileNumber) + ".routes");
std::string const fullpath = base::JoinPath(m_targetDir, std::to_string(m_fileNumber) + ".routes");
return fullpath;
}
@@ -241,18 +235,13 @@ void RoutesSaver::OpenOutputStream()
m_output << std::setprecision(20);
}
void RoutesSaver::WriteStartAndFinish(std::ofstream & output,
ms::LatLon const & start,
ms::LatLon const & finish)
void RoutesSaver::WriteStartAndFinish(std::ofstream & output, ms::LatLon const & start, ms::LatLon const & finish)
{
output << start.m_lat << " " << start.m_lon << " "
<< finish.m_lat << " " << finish.m_lon
<< std::endl;
output << start.m_lat << " " << start.m_lon << " " << finish.m_lat << " " << finish.m_lon << std::endl;
}
// This function creates python script that shows the distribution error.
void CreatePythonScriptForDistribution(std::string const & pythonScriptPath,
std::string const & title,
void CreatePythonScriptForDistribution(std::string const & pythonScriptPath, std::string const & title,
std::vector<double> const & values)
{
std::ofstream python(pythonScriptPath);
@@ -271,19 +260,19 @@ void CreatePythonScriptForDistribution(std::string const & pythonScriptPath,
import numpy as np
import matplotlib.pyplot as plt
a = np.hstack()" + pythonArray + R"()
a = np.hstack()" +
pythonArray + R"()
plt.hist(a, bins='auto') # arguments are passed to np.histogram
plt.title(")" + title + R"(")
plt.title(")" + title +
R"(")
plt.show()
)";
LOG(LINFO, ("Run: python", pythonScriptPath, "to look at:", title));
}
void CreatePythonGraphByPointsXY(std::string const & pythonScriptPath,
std::string const & xlabel,
std::string const & ylabel,
std::vector<std::vector<m2::PointD>> const & graphics,
void CreatePythonGraphByPointsXY(std::string const & pythonScriptPath, std::string const & xlabel,
std::string const & ylabel, std::vector<std::vector<m2::PointD>> const & graphics,
std::vector<std::string> const & legends)
{
CHECK_EQUAL(legends.size(), graphics.size(), ());
@@ -316,14 +305,19 @@ void CreatePythonGraphByPointsXY(std::string const & pythonScriptPath,
python << R"(
import pylab
legends = )" + legendsArray + R"(
xlist = )" + pythonArrayX + R"(
ylist = )" + pythonArrayY + R"(
legends = )" + legendsArray +
R"(
xlist = )" + pythonArrayX +
R"(
ylist = )" + pythonArrayY +
R"(
for (x, y, l) in zip(xlist, ylist, legends):
pylab.plot(x, y, label=l)
pylab.xlabel(")" + xlabel + R"(")
pylab.ylabel(")" + ylabel + R"(")
pylab.xlabel(")" +
xlabel + R"(")
pylab.ylabel(")" +
ylabel + R"(")
pylab.legend()
pylab.tight_layout()
pylab.show()
@@ -332,13 +326,9 @@ pylab.show()
LOG(LINFO, ("Run: python", pythonScriptPath, "to look at:", ylabel, "versus", xlabel));
}
void CreatePythonBarByMap(std::string const & pythonScriptPath,
std::vector<std::string> const & barLabels,
std::vector<std::vector<double>> const & barHeights,
std::vector<std::string> const & legends,
std::string const & xlabel,
std::string const & ylabel,
bool drawPercents)
void CreatePythonBarByMap(std::string const & pythonScriptPath, std::vector<std::string> const & barLabels,
std::vector<std::vector<double>> const & barHeights, std::vector<std::string> const & legends,
std::string const & xlabel, std::string const & ylabel, bool drawPercents)
{
std::ofstream python(pythonScriptPath);
CHECK(python.good(), ("Can not open:", pythonScriptPath, "for writing."));
@@ -354,9 +344,8 @@ void CreatePythonBarByMap(std::string const & pythonScriptPath,
else
counts.back() = ']';
std::string const formatString = drawPercents
? "f'{round(height, 2)}({round(height / summ * 100, 2)}%)'"
: "f'{round(height, 2)}'";
std::string const formatString =
drawPercents ? "f'{round(height, 2)}({round(height / summ * 100, 2)}%)'" : "f'{round(height, 2)}'";
python << R"(
import matplotlib
@@ -364,9 +353,12 @@ import matplotlib.pyplot as plt
import numpy as np
bar_width = 0.35
labels = )" + labelsArray + R"(
legends = )" + legendsArray + R"(
counts = )" + counts + R"(
labels = )" + labelsArray +
R"(
legends = )" + legendsArray +
R"(
counts = )" + counts +
R"(
x = np.arange(len(labels)) # the label locations
width = 0.35 # the width of the bars
@@ -377,8 +369,10 @@ for i in range(len(counts)):
bar = ax.bar(x + i * bar_width, counts[i], bar_width, label=legends[i])
bars.append(bar)
ax.set_ylabel(')" + ylabel + R"(')
ax.set_title(')" + xlabel + R"(')
ax.set_ylabel(')" +
ylabel + R"(')
ax.set_title(')" +
xlabel + R"(')
pos = (bar_width * (len(counts) - 1)) / 2
ax.set_xticks(x + pos)
ax.set_xticklabels(labels)
@@ -391,7 +385,8 @@ def autolabel(rects, counts_ith):
for rect in rects:
height = rect.get_height()
ax.annotate()" + formatString + R"(,
ax.annotate()" +
formatString + R"(,
xy=(rect.get_x() + rect.get_width() / 2, height),
xytext=(0, 3), # 3 points vertical offset
textcoords="offset points",
@@ -408,19 +403,12 @@ plt.show()
/// \brief |SimilarityCounter| groups routes that we compare by similarity, here we tune these groups.
// static
std::vector<SimilarityCounter::Interval> const SimilarityCounter::kIntervals = {
{"[0.0, 0.0]", 0, 0 + 1e-5},
{"[0.0, 0.1)", 0, 0.1},
{"[0.1, 0.2)", 0.1, 0.2},
{"[0.2, 0.3)", 0.2, 0.3},
{"[0.3, 0.6)", 0.3, 0.6},
{"[0.6, 0.8)", 0.6, 0.8},
{"[0.8, 1.0)", 0.8, 1.0},
{"[1.0, 1.0]", 1.0, 1.0 + 1e-5},
std::vector<SimilarityCounter::Interval> const SimilarityCounter::kIntervals = {
{"[0.0, 0.0]", 0, 0 + 1e-5}, {"[0.0, 0.1)", 0, 0.1}, {"[0.1, 0.2)", 0.1, 0.2}, {"[0.2, 0.3)", 0.2, 0.3},
{"[0.3, 0.6)", 0.3, 0.6}, {"[0.6, 0.8)", 0.6, 0.8}, {"[0.8, 1.0)", 0.8, 1.0}, {"[1.0, 1.0]", 1.0, 1.0 + 1e-5},
};
SimilarityCounter::SimilarityCounter(RoutesSaver & routesSaver)
: m_routesSaver(routesSaver)
SimilarityCounter::SimilarityCounter(RoutesSaver & routesSaver) : m_routesSaver(routesSaver)
{
for (auto const & interval : kIntervals)
m_routesCounter.emplace_back(interval.m_name, 0);
@@ -466,9 +454,8 @@ void SimilarityCounter::Push(Result const & result)
CHECK_LESS(m_currentInterval, m_routesCounter.size(), ());
if (m_routesCounter[m_currentInterval].m_routesNumber == 0)
{
LOG(LINFO,
("Save routes with:", m_routesCounter[m_currentInterval].m_intervalName,
"similarity to:", m_routesSaver.GetCurrentPath()));
LOG(LINFO, ("Save routes with:", m_routesCounter[m_currentInterval].m_intervalName,
"similarity to:", m_routesSaver.GetCurrentPath()));
}
CHECK_LESS(m_currentInterval, m_routesCounter.size(), ());
@@ -481,8 +468,7 @@ void SimilarityCounter::CreateKmlFiles(double percent, std::vector<Result> const
size_t realResultIndex = 0;
for (size_t intervalId = 0; intervalId < m_routesCounter.size(); ++intervalId)
{
std::string savePath =
base::JoinPath(m_routesSaver.GetTargetDir(), std::to_string(intervalId));
std::string savePath = base::JoinPath(m_routesSaver.GetTargetDir(), std::to_string(intervalId));
auto const currentSize = m_routesCounter[intervalId].m_routesNumber;
auto const resultSize = static_cast<size_t>(currentSize * percent / 100.0);
@@ -490,13 +476,10 @@ void SimilarityCounter::CreateKmlFiles(double percent, std::vector<Result> const
continue;
auto const mkdirRes = Platform::MkDir(savePath);
CHECK(mkdirRes == Platform::EError::ERR_OK ||
mkdirRes == Platform::EError::ERR_FILE_ALREADY_EXISTS,
CHECK(mkdirRes == Platform::EError::ERR_OK || mkdirRes == Platform::EError::ERR_FILE_ALREADY_EXISTS,
("Cannot create dir:", savePath));
LOG(LINFO, ("Saving", resultSize,
"kmls for:", m_routesCounter[intervalId].m_intervalName,
"to:", savePath));
LOG(LINFO, ("Saving", resultSize, "kmls for:", m_routesCounter[intervalId].m_intervalName, "to:", savePath));
auto const step = static_cast<size_t>(currentSize / resultSize);

View File

@@ -1,7 +1,7 @@
#pragma once
#include "routing/routing_quality/api/api.hpp"
#include "routing/routes_builder/routes_builder.hpp"
#include "routing/routing_quality/api/api.hpp"
#include "routing/routing_callbacks.hpp"
@@ -72,8 +72,7 @@ bool AreRoutesWithSameEnds(routing::routes_builder::RoutesBuilder::Result const
auto const & anotherFinish = anotherResult.GetFinishPoint();
double constexpr kEps = 1e-10;
return AlmostEqualAbs(start, anotherStart, kEps) &&
AlmostEqualAbs(finish, anotherFinish, kEps);
return AlmostEqualAbs(start, anotherStart, kEps) && AlmostEqualAbs(finish, anotherFinish, kEps);
}
template <typename AnotherResult>
@@ -95,8 +94,7 @@ bool FindAnotherResponse(routing::routes_builder::RoutesBuilder::Result const &
struct Result
{
Result(std::string mapsmeDumpPath, std::string anotherDumpPath,
ms::LatLon const & start, ms::LatLon const & finish,
Result(std::string mapsmeDumpPath, std::string anotherDumpPath, ms::LatLon const & start, ms::LatLon const & finish,
double similarity, double etaDiffPercent);
bool operator<(Result const & rhs) const;
@@ -170,24 +168,17 @@ private:
std::vector<Item> m_routesCounter;
};
void CreatePythonScriptForDistribution(std::string const & pythonScriptPath,
std::string const & title,
void CreatePythonScriptForDistribution(std::string const & pythonScriptPath, std::string const & title,
std::vector<double> const & values);
void CreatePythonGraphByPointsXY(std::string const & pythonScriptPath,
std::string const & xlabel,
std::string const & ylabel,
std::vector<std::vector<m2::PointD>> const & graphics,
void CreatePythonGraphByPointsXY(std::string const & pythonScriptPath, std::string const & xlabel,
std::string const & ylabel, std::vector<std::vector<m2::PointD>> const & graphics,
std::vector<std::string> const & legends);
/// \brief Create python file, that show bar graph, where labels of bars are keys of |stat| and
/// heights area values of |stat|.
void CreatePythonBarByMap(std::string const & pythonScriptPath,
std::vector<std::string> const & barLabels,
std::vector<std::vector<double>> const & barHeights,
std::vector<std::string> const & legends,
std::string const & xlabel,
std::string const & ylabel,
bool drawPercents = true);
void CreatePythonBarByMap(std::string const & pythonScriptPath, std::vector<std::string> const & barLabels,
std::vector<std::vector<double>> const & barHeights, std::vector<std::string> const & legends,
std::string const & xlabel, std::string const & ylabel, bool drawPercents = true);
} // namespace routing_quality_tool
} // namespace routing_quality

View File

@@ -15,8 +15,7 @@ namespace routing_quality
{
namespace metrics
{
Similarity CompareByNumberOfMatchedWaypoints(routing::FollowedPolyline polyline,
Waypoints const & waypoints)
Similarity CompareByNumberOfMatchedWaypoints(routing::FollowedPolyline polyline, Waypoints const & waypoints)
{
double constexpr kMaxDistanceFromRouteM = 15.0;
@@ -26,8 +25,7 @@ Similarity CompareByNumberOfMatchedWaypoints(routing::FollowedPolyline polyline,
for (size_t i = 0; i < size; ++i)
{
auto const & ll = waypoints[i];
m2::RectD const rect =
mercator::MetersToXY(ll.m_lon, ll.m_lat, kMaxDistanceFromRouteM /* metresR */);
m2::RectD const rect = mercator::MetersToXY(ll.m_lon, ll.m_lat, kMaxDistanceFromRouteM /* metresR */);
auto const iter = polyline.UpdateProjection(rect);
if (iter.IsValid())
{
@@ -45,8 +43,7 @@ Similarity CompareByNumberOfMatchedWaypoints(routing::FollowedPolyline polyline,
return result;
}
Similarity CompareByNumberOfMatchedWaypoints(routing::FollowedPolyline const & polyline,
ReferenceRoutes && candidates)
Similarity CompareByNumberOfMatchedWaypoints(routing::FollowedPolyline const & polyline, ReferenceRoutes && candidates)
{
Similarity bestResult = 0.0;
for (size_t j = 0; j < candidates.size(); ++j)
@@ -74,8 +71,7 @@ bool CheckRoute(Params const & params, ReferenceRoutes && referenceRoutes)
return CheckWaypoints(params, std::move(referenceRoutes)) == 1.0;
}
bool CheckCarRoute(ms::LatLon const & start, ms::LatLon const & finish,
ReferenceRoutes && referenceTracks)
bool CheckCarRoute(ms::LatLon const & start, ms::LatLon const & finish, ReferenceRoutes && referenceTracks)
{
Params const params(routing::VehicleType::Car, start, finish);
return CheckRoute(params, std::move(referenceTracks));

View File

@@ -24,10 +24,8 @@ using Similarity = double;
namespace metrics
{
Similarity CompareByNumberOfMatchedWaypoints(routing::FollowedPolyline polyline,
Waypoints const & waypoints);
Similarity CompareByNumberOfMatchedWaypoints(routing::FollowedPolyline const & polyline,
ReferenceRoutes && candidates);
Similarity CompareByNumberOfMatchedWaypoints(routing::FollowedPolyline polyline, Waypoints const & waypoints);
Similarity CompareByNumberOfMatchedWaypoints(routing::FollowedPolyline const & polyline, ReferenceRoutes && candidates);
} // namespace metrics
/// \brief Checks how many reference waypoints the route contains.
@@ -37,6 +35,5 @@ Similarity CheckWaypoints(Params const & params, ReferenceRoutes && referenceRou
/// \returns true if route from |start| to |finish| fully conforms one of |candidates|
/// and false otherwise.
bool CheckRoute(Params const & params, ReferenceRoutes && referenceRoutes);
bool CheckCarRoute(ms::LatLon const & start, ms::LatLon const & finish,
ReferenceRoutes && referenceRoutes);
bool CheckCarRoute(ms::LatLon const & start, ms::LatLon const & finish, ReferenceRoutes && referenceRoutes);
} // namespace routing_quality