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
diff options
context:
space:
mode:
authorMikhail Gorbushin <m.gorbushin@corp.mail.ru>2019-05-16 16:55:14 +0300
committerDaria Volvenkova <d.volvenkova@corp.mail.ru>2019-05-17 18:45:59 +0300
commitcabbc20ee4585ef1b3f9aa23966a82b54d3bc673 (patch)
tree8fd2d3e8c2862a7d9ae2dcebeaee1b7302500fa5 /routing
parentceab008497f5510b988d65245652657254ff678c (diff)
[routing] fix progress
Diffstat (limited to 'routing')
-rw-r--r--routing/base/astar_progress.cpp28
-rw-r--r--routing/base/astar_progress.hpp7
-rw-r--r--routing/index_router.cpp31
-rw-r--r--routing/routing_tests/astar_progress_test.cpp28
4 files changed, 61 insertions, 33 deletions
diff --git a/routing/base/astar_progress.cpp b/routing/base/astar_progress.cpp
index 86b1a0bfeb..eda451152d 100644
--- a/routing/base/astar_progress.cpp
+++ b/routing/base/astar_progress.cpp
@@ -43,7 +43,6 @@ double AStarSubProgress::UpdateProgress(m2::PointD const & current, m2::PointD c
double const newProgress = m_contributionCoef * part;
m_currentProgress = std::max(newProgress, m_currentProgress);
-
return m_currentProgress;
}
@@ -61,9 +60,12 @@ double AStarSubProgress::GetMaxContribution() const { return m_contributionCoef;
// AStarProgress -------------------------------------------------------------------------
+// static
+double const AStarProgress::kMaxPercent = 99.0;
+
AStarProgress::AStarProgress()
{
- m_subProgresses.emplace_back(AStarSubProgress(1.0));
+ m_subProgresses.emplace_back(AStarSubProgress(kMaxPercent / 100.0));
}
AStarProgress::~AStarProgress()
@@ -76,7 +78,14 @@ void AStarProgress::AppendSubProgress(AStarSubProgress const & subProgress)
m_subProgresses.emplace_back(subProgress);
}
-void AStarProgress::EraseLastSubProgress()
+void AStarProgress::DropLastSubProgress()
+{
+ CHECK(!m_subProgresses.empty(), ());
+ auto const last = std::prev(m_subProgresses.end());
+ m_subProgresses.erase(last);
+}
+
+void AStarProgress::PushAndDropLastSubProgress()
{
CHECK(m_subProgresses.begin() != m_subProgresses.end(), ());
CHECK(m_subProgresses.begin() != std::prev(m_subProgresses.end()), ());
@@ -84,17 +93,20 @@ void AStarProgress::EraseLastSubProgress()
auto prevLast = std::prev(std::prev(m_subProgresses.end()));
prevLast->Flush(m_subProgresses.back().GetMaxContribution());
- CHECK(!m_subProgresses.empty(), ());
- auto const last = std::prev(m_subProgresses.end());
- m_subProgresses.erase(last);
+ DropLastSubProgress();
}
double AStarProgress::UpdateProgress(m2::PointD const & current, m2::PointD const & end)
{
- return UpdateProgressImpl(m_subProgresses.begin(), current, end) * 100.0;
+ double const newProgress = UpdateProgressImpl(m_subProgresses.begin(), current, end) * 100.0;
+ m_lastPercentValue = std::max(m_lastPercentValue, newProgress);
+
+ ASSERT_LESS_OR_EQUAL(m_lastPercentValue, kMaxPercent, ());
+ m_lastPercentValue = std::min(m_lastPercentValue, kMaxPercent);
+ return m_lastPercentValue;
}
-double AStarProgress::GetLastPercent() const { return m_lastValue * 100.0; }
+double AStarProgress::GetLastPercent() const { return m_lastPercentValue; }
double AStarProgress::UpdateProgressImpl(ListItem subProgress, m2::PointD const & current,
m2::PointD const & end)
diff --git a/routing/base/astar_progress.hpp b/routing/base/astar_progress.hpp
index abb9aed486..e52e9118f8 100644
--- a/routing/base/astar_progress.hpp
+++ b/routing/base/astar_progress.hpp
@@ -37,11 +37,14 @@ private:
class AStarProgress
{
public:
+ static double const kMaxPercent;
+
AStarProgress();
~AStarProgress();
double GetLastPercent() const;
- void EraseLastSubProgress();
+ void PushAndDropLastSubProgress();
+ void DropLastSubProgress();
void AppendSubProgress(AStarSubProgress const & subProgress);
double UpdateProgress(m2::PointD const & current, m2::PointD const & end);
@@ -52,7 +55,7 @@ private:
m2::PointD const & end);
// This value is in range: [0, 1].
- double m_lastValue = 0.0;
+ double m_lastPercentValue = 0.0;
std::list<AStarSubProgress> m_subProgresses;
};
diff --git a/routing/index_router.cpp b/routing/index_router.cpp
index 3524c7a5af..66df863395 100644
--- a/routing/index_router.cpp
+++ b/routing/index_router.cpp
@@ -58,11 +58,11 @@ using namespace std;
namespace
{
size_t constexpr kMaxRoadCandidates = 12;
-float constexpr kProgressInterval = 2;
+double constexpr kProgressInterval = 0.5;
uint32_t constexpr kVisitPeriodForLeaps = 10;
uint32_t constexpr kVisitPeriod = 40;
-double constexpr kLeapsStageContribution = 0.3;
+double constexpr kLeapsStageContribution = 0.15;
// If user left the route within this range(meters), adjust the route. Else full rebuild.
double constexpr kAdjustRangeM = 5000.0;
@@ -442,7 +442,7 @@ RouterResultCode IndexRouter::DoCalculateRoute(Checkpoints const & checkpoints,
AStarSubProgress subProgress(startCheckpoint, finishCheckpoint, contributionCoef);
progress.AppendSubProgress(subProgress);
SCOPE_GUARD(eraseProgress, [&progress]() {
- progress.EraseLastSubProgress();
+ progress.PushAndDropLastSubProgress();
});
auto const result = CalculateSubroute(checkpoints, i, delegate, progress, subrouteStarter,
@@ -555,7 +555,7 @@ RouterResultCode IndexRouter::CalculateSubroute(Checkpoints const & checkpoints,
RoutingResult<JointSegment, RouteWeight> routingResult;
uint32_t visitCount = 0;
- auto lastValue = progress.GetLastPercent();
+ double lastValue = progress.GetLastPercent();
auto const onVisitJunctionJoints = [&](JointSegment const & from, JointSegment const & to)
{
++visitCount;
@@ -631,7 +631,7 @@ RouterResultCode IndexRouter::CalculateSubroute(Checkpoints const & checkpoints,
RouterResultCode const result = FindPath<Vertex, Edge, Weight>(params, mwmIds, routingResult, mode);
if (mode == WorldGraphMode::LeapsOnly)
- progress.EraseLastSubProgress();
+ progress.PushAndDropLastSubProgress();
if (result != RouterResultCode::NoError)
return result;
@@ -845,7 +845,7 @@ RouterResultCode IndexRouter::ProcessLeapsJoints(vector<Segment> const & input,
}
SCOPE_GUARD(progressGuard, [&progress]() {
- progress.EraseLastSubProgress();
+ progress.PushAndDropLastSubProgress();
});
progress.AppendSubProgress(AStarSubProgress(1.0 - kLeapsStageContribution));
@@ -906,6 +906,7 @@ RouterResultCode IndexRouter::ProcessLeapsJoints(vector<Segment> const & input,
set<NumMwmId> mwmIds;
IndexGraphStarterJoints<IndexGraphStarter> jointStarter(starter);
+ size_t maxStart = 0;
auto const runAStarAlgorithm = [&](size_t start, size_t end, WorldGraphMode mode,
RoutingResult<JointSegment, RouteWeight> & routingResult)
@@ -926,12 +927,18 @@ RouterResultCode IndexRouter::ProcessLeapsJoints(vector<Segment> const & input,
using Edge = IndexGraphStarterJoints<IndexGraphStarter>::Edge;
using Weight = IndexGraphStarterJoints<IndexGraphStarter>::Weight;
- auto const contribCoef = static_cast<double>(end - start + 1) / (input.size());
+ maxStart = max(maxStart, start);
+ auto const contribCoef = static_cast<double>(end - maxStart + 1) / (input.size());
auto const startPoint = starter.GetPoint(input[start], true /* front */);
auto const endPoint = starter.GetPoint(input[end], true /* front */);
progress.AppendSubProgress({startPoint, endPoint, contribCoef});
- SCOPE_GUARD(progressGuard, [&progress]() {
- progress.EraseLastSubProgress();
+
+ RouterResultCode resultCode = RouterResultCode::NoError;
+ SCOPE_GUARD(progressGuard, [&]() {
+ if (resultCode == RouterResultCode::NoError)
+ progress.PushAndDropLastSubProgress();
+ else
+ progress.DropLastSubProgress();
});
uint32_t visitCount = 0;
@@ -959,7 +966,8 @@ RouterResultCode IndexRouter::ProcessLeapsJoints(vector<Segment> const & input,
nullptr /* prevRoute */, delegate,
onVisitJunctionJoints, checkLength);
- return FindPath<Vertex, Edge, Weight>(params, mwmIds, routingResult, mode);
+ resultCode = FindPath<Vertex, Edge, Weight>(params, mwmIds, routingResult, mode);
+ return resultCode;
};
deque<vector<Segment>> paths;
@@ -977,7 +985,8 @@ RouterResultCode IndexRouter::ProcessLeapsJoints(vector<Segment> const & input,
paths.pop_back();
ASSERT(!subroute.empty(), ());
- paths.emplace_back(vector<Segment>(dropFirstSegment ? subroute.cbegin() + 1 : subroute.cbegin(), subroute.cend()));
+ paths.emplace_back(vector<Segment>(dropFirstSegment ? subroute.cbegin() + 1
+ : subroute.cbegin(), subroute.cend()));
dropFirstSegment = true;
prevStart = start;
diff --git a/routing/routing_tests/astar_progress_test.cpp b/routing/routing_tests/astar_progress_test.cpp
index 5c32a2d606..5d02332b90 100644
--- a/routing/routing_tests/astar_progress_test.cpp
+++ b/routing/routing_tests/astar_progress_test.cpp
@@ -14,12 +14,16 @@ UNIT_TEST(DirectedAStarProgressCheck)
AStarProgress progress;
progress.AppendSubProgress({start, finish, 1.0 /* contributionCoef */});
- TEST_LESS(progress.UpdateProgress(start, finish), 0.1f, ());
- TEST_LESS(progress.UpdateProgress(middle, finish), 50.5f, ());
- TEST_GREATER(progress.UpdateProgress(middle, finish), 49.5f, ());
- TEST_GREATER(progress.UpdateProgress(finish, finish), 99.9f, ());
+ TEST_LESS(progress.UpdateProgress(start, finish), 0.1, ());
+ TEST_LESS(progress.UpdateProgress(middle, finish), 51.0, ());
+ TEST_GREATER(progress.UpdateProgress(middle, finish), 49.0, ());
- progress.EraseLastSubProgress();
+ static auto constexpr kEps = 0.001;
+ TEST_GREATER(progress.UpdateProgress(finish, finish),
+ AStarProgress::kMaxPercent - kEps,
+ ());
+
+ progress.PushAndDropLastSubProgress();
}
UNIT_TEST(DirectedAStarDegradationCheck)
@@ -39,8 +43,8 @@ UNIT_TEST(DirectedAStarDegradationCheck)
auto value3 = progressSecond.UpdateProgress(start, finish);
TEST_GREATER_OR_EQUAL(value1, value3, ());
- progressFirst.EraseLastSubProgress();
- progressSecond.EraseLastSubProgress();
+ progressFirst.PushAndDropLastSubProgress();
+ progressSecond.PushAndDropLastSubProgress();
}
UNIT_TEST(RangeCheckTest)
@@ -54,9 +58,9 @@ UNIT_TEST(RangeCheckTest)
progress.AppendSubProgress({start, finish, 1.0 /* contributionCoef */});
TEST_EQUAL(progress.UpdateProgress(preStart, finish), 0.0, ());
TEST_EQUAL(progress.UpdateProgress(postFinish, finish), 0.0, ());
- TEST_EQUAL(progress.UpdateProgress(finish, finish), 100.0, ());
+ TEST_EQUAL(progress.UpdateProgress(finish, finish), AStarProgress::kMaxPercent, ());
- progress.EraseLastSubProgress();
+ progress.PushAndDropLastSubProgress();
}
UNIT_TEST(BidirectedAStarProgressCheck)
@@ -70,9 +74,9 @@ UNIT_TEST(BidirectedAStarProgressCheck)
progress.AppendSubProgress({start, finish, 1.0 /* contributionCoef */});
progress.UpdateProgress(fWave, finish);
float result = progress.UpdateProgress(bWave, start);
- TEST_GREATER(result, 49.5, ());
- TEST_LESS(result, 50.5, ());
+ TEST_GREATER(result, 49.0, ());
+ TEST_LESS(result, 51.0, ());
- progress.EraseLastSubProgress();
+ progress.PushAndDropLastSubProgress();
}
} // namespace routing_test