Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/openlr
diff options
context:
space:
mode:
authorVladimir Byko-Ianko <v.bykoianko@corp.mail.ru>2019-04-26 17:31:56 +0300
committerVladimir Byko-Ianko <v.bykoianko@corp.mail.ru>2019-04-26 17:31:56 +0300
commit611cced6e5b7b55211262723145ad0c61780b51d (patch)
tree79312bcc83641d46cd30a48ac5051e37526d375d /openlr
parenta2348f79c52f9bd32b2a6aed7184a56a296edeb7 (diff)
Review fixes.
Diffstat (limited to 'openlr')
-rw-r--r--openlr/candidate_paths_getter.cpp2
-rw-r--r--openlr/score_candidate_paths_getter.cpp33
-rw-r--r--openlr/score_candidate_paths_getter.hpp15
-rw-r--r--openlr/score_paths_connector.cpp46
-rw-r--r--openlr/stats.hpp6
5 files changed, 50 insertions, 52 deletions
diff --git a/openlr/candidate_paths_getter.cpp b/openlr/candidate_paths_getter.cpp
index 9d469dba77..5f96b25e31 100644
--- a/openlr/candidate_paths_getter.cpp
+++ b/openlr/candidate_paths_getter.cpp
@@ -70,7 +70,7 @@ bool CandidatePathsGetter::GetLineCandidatesForPoints(
if (i != points.size() - 1 && points[i].m_distanceToNextPoint == 0)
{
LOG(LINFO, ("Distance to next point is zero. Skipping the whole segment"));
- ++m_stats.m_dnpIsZero;
+ ++m_stats.m_zeroDistToNextPointCount;
return false;
}
diff --git a/openlr/score_candidate_paths_getter.cpp b/openlr/score_candidate_paths_getter.cpp
index 7de742bcbd..a035d892d6 100644
--- a/openlr/score_candidate_paths_getter.cpp
+++ b/openlr/score_candidate_paths_getter.cpp
@@ -21,6 +21,7 @@
#include <queue>
#include <set>
#include <tuple>
+#include <utility>
using namespace routing;
using namespace std;
@@ -42,16 +43,16 @@ double ToAngleInDeg(uint32_t angleInBuckets)
uint32_t BearingInDeg(m2::PointD const & a, m2::PointD const & b)
{
auto const angle = location::AngleToBearing(base::RadToDeg(ang::AngleTo(a, b)));
- CHECK_LESS_OR_EQUAL(angle, 360.0, ("Angle should be less than or equal to 360."));
- CHECK_GREATER_OR_EQUAL(angle, 0.0, ("Angle should be greater than or equal to 0."));
+ CHECK_LESS_OR_EQUAL(angle, 360.0, ());
+ CHECK_GREATER_OR_EQUAL(angle, 0.0, ());
return angle;
}
double DifferenceInDeg(double a1, double a2)
{
auto const diff = 180.0 - abs(abs(a1 - a2) - 180.0);
- CHECK_LESS_OR_EQUAL(diff, 180.0, ("Difference should be less than or equal to 360."));
- CHECK_GREATER_OR_EQUAL(diff, 0.0, ("Difference should be greater than or equal to 0."));
+ CHECK_LESS_OR_EQUAL(diff, 180.0, ());
+ CHECK_GREATER_OR_EQUAL(diff, 0.0, ());
return diff;
}
} // namespace
@@ -91,7 +92,7 @@ bool ScoreCandidatePathsGetter::GetLineCandidatesForPoints(
if (i != points.size() - 1 && points[i].m_distanceToNextPoint == 0)
{
LOG(LINFO, ("Distance to next point is zero. Skipping the whole segment"));
- ++m_stats.m_dnpIsZero;
+ ++m_stats.m_zeroDistToNextPointCount;
return false;
}
@@ -122,9 +123,10 @@ bool ScoreCandidatePathsGetter::GetLineCandidatesForPoints(
void ScoreCandidatePathsGetter::GetAllSuitablePaths(ScoreEdgeVec const & startLines,
bool isLastPoint, double bearDistM,
FunctionalRoadClass functionalRoadClass,
- FormOfWay formOfWay, vector<LinkPtr> & allPaths)
+ FormOfWay formOfWay,
+ vector<shared_ptr<Link>> & allPaths)
{
- queue<LinkPtr> q;
+ queue<shared_ptr<Link>> q;
for (auto const & e : startLines)
{
@@ -132,9 +134,8 @@ void ScoreCandidatePathsGetter::GetAllSuitablePaths(ScoreEdgeVec const & startLi
if (!PassesRestrictionV3(e.m_edge, functionalRoadClass, formOfWay, m_infoGetter, roadScore))
continue;
- auto const u =
- make_shared<Link>(nullptr /* parent */, e.m_edge, 0 /* distanceM */, e.m_score, roadScore);
- q.push(u);
+ q.push(
+ make_shared<Link>(nullptr /* parent */, e.m_edge, 0 /* distanceM */, e.m_score, roadScore));
}
// Filling |allPaths| staring from |startLines| which have passed functional road class
@@ -150,7 +151,7 @@ void ScoreCandidatePathsGetter::GetAllSuitablePaths(ScoreEdgeVec const & startLi
if (u->m_distanceM + currentEdgeLen >= bearDistM)
{
- allPaths.push_back(u);
+ allPaths.emplace_back(move(u));
continue;
}
@@ -187,7 +188,7 @@ void ScoreCandidatePathsGetter::GetAllSuitablePaths(ScoreEdgeVec const & startLi
}
void ScoreCandidatePathsGetter::GetBestCandidatePaths(
- vector<LinkPtr> const & allPaths, bool isLastPoint, uint32_t requiredBearing,
+ vector<shared_ptr<Link>> const & allPaths, bool isLastPoint, uint32_t requiredBearing,
double bearDistM, m2::PointD const & startPoint, ScorePathVec & candidates)
{
CHECK_GREATER_OR_EQUAL(requiredBearing, 0, ());
@@ -196,9 +197,9 @@ void ScoreCandidatePathsGetter::GetBestCandidatePaths(
multiset<CandidatePath, greater<>> candidatePaths;
BearingPointsSelector pointsSelector(static_cast<uint32_t>(bearDistM), isLastPoint);
- for (auto const & l : allPaths)
+ for (auto const & link : allPaths)
{
- auto const bearStartPoint = pointsSelector.GetStartPoint(l->GetStartEdge());
+ auto const bearStartPoint = pointsSelector.GetStartPoint(link->GetStartEdge());
// Number of edges counting from the last one to check bearing on. According to OpenLR spec
// we have to check bearing on a point that is no longer than 25 meters traveling down the path.
@@ -213,7 +214,7 @@ void ScoreCandidatePathsGetter::GetBestCandidatePaths(
// ^ this one.
// So we want to check them all.
uint32_t traceBackIterationsLeft = 3;
- for (auto part = l; part; part = part->m_parent)
+ for (auto part = link; part; part = part->m_parent)
{
if (traceBackIterationsLeft == 0)
break;
@@ -274,7 +275,7 @@ void ScoreCandidatePathsGetter::GetLineCandidates(openlr::LocationReferencePoint
auto const startPoint = MercatorBounds::FromLatLon(p.m_latLon);
- vector<LinkPtr> allPaths;
+ vector<shared_ptr<Link>> allPaths;
GetAllSuitablePaths(startLines, isLastPoint, bearDistM, p.m_functionalRoadClass, p.m_formOfWay,
allPaths);
diff --git a/openlr/score_candidate_paths_getter.hpp b/openlr/score_candidate_paths_getter.hpp
index de4ade1c42..cef4b1ee4c 100644
--- a/openlr/score_candidate_paths_getter.hpp
+++ b/openlr/score_candidate_paths_getter.hpp
@@ -32,12 +32,9 @@ public:
std::vector<ScorePathVec> & lineCandidates);
private:
- struct Link;
- using LinkPtr = std::shared_ptr<Link>;
-
struct Link
{
- Link(LinkPtr const & parent, Graph::Edge const & edge, double distanceM,
+ Link(std::shared_ptr<Link> const & parent, Graph::Edge const & edge, double distanceM,
Score pointScore, Score rfcScore)
: m_parent(parent)
, m_edge(edge)
@@ -52,7 +49,7 @@ private:
Graph::Edge GetStartEdge() const;
- LinkPtr const m_parent;
+ std::shared_ptr<Link> const m_parent;
Graph::Edge const m_edge;
double const m_distanceM;
Score const m_pointScore;
@@ -65,7 +62,7 @@ private:
{
CandidatePath() = default;
- CandidatePath(LinkPtr const path, Score pointScore, Score rfcScore, Score bearingScore)
+ CandidatePath(std::shared_ptr<Link> const path, Score pointScore, Score rfcScore, Score bearingScore)
: m_path(path)
, m_pointScore(pointScore)
, m_roadScore(rfcScore)
@@ -77,7 +74,7 @@ private:
Score GetScore() const { return m_pointScore + m_roadScore + m_bearingScore; }
- LinkPtr m_path = nullptr;
+ std::shared_ptr<Link> m_path = nullptr;
Score m_pointScore = 0;
Score m_roadScore = 0;
Score m_bearingScore = 0;
@@ -100,9 +97,9 @@ private:
/// then should be taken the member |m_parent| of the item and so on till the beginning.
void GetAllSuitablePaths(ScoreEdgeVec const & startLines, bool isLastPoint,
double bearDistM, FunctionalRoadClass functionalRoadClass,
- FormOfWay formOfWay, std::vector<LinkPtr> & allPaths);
+ FormOfWay formOfWay, std::vector<std::shared_ptr<Link>> & allPaths);
- void GetBestCandidatePaths(std::vector<LinkPtr> const & allPaths, bool isLastPoint,
+ void GetBestCandidatePaths(std::vector<std::shared_ptr<Link>> const & allPaths, bool isLastPoint,
uint32_t requiredBearing, double bearDistM,
m2::PointD const & startPoint, ScorePathVec & candidates);
diff --git a/openlr/score_paths_connector.cpp b/openlr/score_paths_connector.cpp
index 2dd60c980f..bf2b427062 100644
--- a/openlr/score_paths_connector.cpp
+++ b/openlr/score_paths_connector.cpp
@@ -106,7 +106,7 @@ bool ValidatePathByLength(Graph::EdgeVector const & path, double distanceToNextP
// 0 <= |pathDiffRatio| <= 1. The more pathDiffRatio the closer |distanceToNextPoint| and |pathLen|.
double const pathDiffRatio =
- 1.0 - AbsDifference(distanceToNextPoint, pathLen) / max(distanceToNextPoint, pathLen);
+ 1.0 - abs(distanceToNextPoint - pathLen) / max(distanceToNextPoint, pathLen);
bool const shortPath = path.size() <= 2;
double constexpr kMinValidPathDiffRation = 0.6;
@@ -162,9 +162,9 @@ bool ScorePathsConnector::FindBestPath(vector<LocationReferencePoint> const & po
if (!ValidatePathByLength(path, distanceToNextPoint, pathLenScore))
continue;
- result.emplace_back(pathLenScore + GetScoreForUniformity(path) +
- fromCandidates[fromInd].m_score + toCandidates[toInd].m_score,
- move(path));
+ auto const score = pathLenScore + GetScoreForUniformity(path) +
+ fromCandidates[fromInd].m_score + toCandidates[toInd].m_score;
+ result.emplace_back(score, move(path));
}
}
@@ -235,42 +235,42 @@ bool ScorePathsConnector::FindShortestPath(Graph::Edge const & from, Graph::Edge
auto const state = q.top();
q.pop();
- auto const & u = state.m_edge;
+ auto const & stateEdge = state.m_edge;
// TODO(mgsergio): Unify names: use either score or distance.
- auto const us = state.m_score;
+ auto const stateScore = state.m_score;
- if (us > maxPathLength + lengthToleranceM)
+ if (stateScore > maxPathLength + lengthToleranceM)
continue;
- if (us > scores[u])
+ if (stateScore > scores[stateEdge])
continue;
- if (u == to)
+ if (stateEdge == to)
{
- for (auto e = u; e != from; e = links[e])
- path.emplace_back(e);
+ for (auto edge = stateEdge; edge != from; edge = links[edge])
+ path.emplace_back(edge);
path.emplace_back(from);
reverse(begin(path), end(path));
return true;
}
Graph::EdgeVector edges;
- m_graph.GetOutgoingEdges(u.GetEndJunction(), edges);
- for (auto const & e : edges)
+ m_graph.GetOutgoingEdges(stateEdge.GetEndJunction(), edges);
+ for (auto const & edge : edges)
{
- if (!ConformLfrcnpV3(e, lowestFrcToNextPoint, m_infoGetter))
+ if (!ConformLfrcnpV3(edge, lowestFrcToNextPoint, m_infoGetter))
continue;
- CHECK(!u.IsFake(), ());
- CHECK(!e.IsFake(), ());
+ CHECK(!stateEdge.IsFake(), ());
+ CHECK(!edge.IsFake(), ());
- auto const it = scores.find(e);
- auto const eScore = us + EdgeLength(e);
+ auto const it = scores.find(edge);
+ auto const eScore = stateScore + EdgeLength(edge);
if (it == end(scores) || it->second > eScore)
{
- scores[e] = eScore;
- links[e] = u;
- q.emplace(e, eScore);
+ scores[edge] = eScore;
+ links[edge] = stateEdge;
+ q.emplace(edge, eScore);
}
}
}
@@ -305,11 +305,11 @@ bool ScorePathsConnector::ConnectAdjacentCandidateLines(Graph::EdgeVector const
if (!found)
return false;
- // Skip the last edge from |from| because it already took its place at begin(shortestPath).
+ CHECK_EQUAL(from.back(), shortestPath.front(), ());
resultPath.insert(resultPath.end(), from.cbegin(), prev(from.cend()));
resultPath.insert(resultPath.end(), shortestPath.cbegin(), shortestPath.cend());
- // Skip the first edge from |to| because it already took its place at prev(end(shortestPath)).
+ CHECK_EQUAL(to.front(), shortestPath.back(), ());
resultPath.insert(resultPath.end(), next(to.begin()), to.end());
return !resultPath.empty();
diff --git a/openlr/stats.hpp b/openlr/stats.hpp
index a5f0a0e5ac..2461198388 100644
--- a/openlr/stats.hpp
+++ b/openlr/stats.hpp
@@ -20,7 +20,7 @@ struct alignas(kCacheLineSize) Stats
m_noCandidateFound += s.m_noCandidateFound;
m_noShortestPathFound += s.m_noShortestPathFound;
m_wrongOffsets += s.m_wrongOffsets;
- m_dnpIsZero += s.m_dnpIsZero;
+ m_zeroDistToNextPointCount += s.m_zeroDistToNextPointCount;
}
void Report() const
@@ -28,7 +28,7 @@ struct alignas(kCacheLineSize) Stats
LOG(LINFO, ("Total routes handled:", m_routesHandled));
LOG(LINFO, ("Failed:", m_routesFailed));
LOG(LINFO, ("No candidate lines:", m_noCandidateFound));
- LOG(LINFO, ("Wrong distance to next point:", m_dnpIsZero));
+ LOG(LINFO, ("Wrong distance to next point:", m_zeroDistToNextPointCount));
LOG(LINFO, ("Wrong offsets:", m_wrongOffsets));
LOG(LINFO, ("No shortest path:", m_noShortestPathFound));
}
@@ -39,7 +39,7 @@ struct alignas(kCacheLineSize) Stats
uint32_t m_noShortestPathFound = 0;
uint32_t m_wrongOffsets = 0;
// Number of zeroed distance-to-next point values in the input.
- uint32_t m_dnpIsZero = 0;
+ uint32_t m_zeroDistToNextPointCount = 0;
};
} // namespace V2
} // namespace openlr