diff --git a/map/traffic_manager.cpp b/map/traffic_manager.cpp index c356005b71..ff5b1fc800 100644 --- a/map/traffic_manager.cpp +++ b/map/traffic_manager.cpp @@ -38,9 +38,9 @@ TrafficManager::CacheEntry::CacheEntry(time_point const & requestT {} TrafficManager::TrafficManager(GetMwmsByRectFn const & getMwmsByRectFn, size_t maxCacheSizeBytes, - traffic::RoutingObserver & routingObserver) + traffic::TrafficObserver & observer) : m_getMwmsByRectFn(getMwmsByRectFn) - , m_routingObserver(routingObserver) + , m_observer(observer) , m_currentDataVersion(0) , m_state(TrafficState::Disabled) , m_maxCacheSizeBytes(maxCacheSizeBytes) @@ -95,7 +95,7 @@ void TrafficManager::SetEnabled(bool enabled) UpdateMyPosition(m_currentPosition.first); } - m_routingObserver.OnTrafficEnabled(enabled); + m_observer.OnTrafficEnabled(enabled); } void TrafficManager::Clear() @@ -319,7 +319,10 @@ void TrafficManager::OnTrafficDataResponse(traffic::TrafficInfo const & info) // Update cache. size_t constexpr kElementSize = sizeof(traffic::TrafficInfo::RoadSegmentId) + sizeof(traffic::SpeedGroup); - size_t const dataSize = info.GetColoring().size() * kElementSize; + + // Note. It's necessary to multiply by two because routing and rendering use individual caches. + size_t const dataSize = 2 * info.GetColoring().size() * kElementSize; + it->second.m_isLoaded = true; m_currentCacheSizeBytes += (dataSize - it->second.m_dataSize); it->second.m_dataSize = dataSize; CheckCacheSize(); @@ -332,7 +335,7 @@ void TrafficManager::OnTrafficDataResponse(traffic::TrafficInfo const & info) UpdateState(); // Update traffic colors for routing. - m_routingObserver.OnTrafficInfoAdded(info); + m_observer.OnTrafficInfoAdded(info); } void TrafficManager::CheckCacheSize() @@ -353,7 +356,7 @@ void TrafficManager::CheckCacheSize() { m_currentCacheSizeBytes -= it->second.m_dataSize; m_drapeEngine->ClearTrafficCache(mwmId); - m_routingObserver.OnTrafficInfoRemoved(mwmId); + m_observer.OnTrafficInfoRemoved(mwmId); } m_mwmCache.erase(it); ++itSeen; diff --git a/map/traffic_manager.hpp b/map/traffic_manager.hpp index 1540782e7a..303aba6140 100644 --- a/map/traffic_manager.hpp +++ b/map/traffic_manager.hpp @@ -58,7 +58,7 @@ public: using GetMwmsByRectFn = function(m2::RectD const &)>; TrafficManager(GetMwmsByRectFn const & getMwmsByRectFn, size_t maxCacheSizeBytes, - traffic::RoutingObserver & routingObserver); + traffic::TrafficObserver & observer); ~TrafficManager(); void SetStateListener(TrafficStateChangedFn const & onStateChangedFn); @@ -95,7 +95,7 @@ private: bool IsEnabled() const; GetMwmsByRectFn m_getMwmsByRectFn; - traffic::RoutingObserver & m_routingObserver; + traffic::TrafficObserver & m_observer; ref_ptr m_drapeEngine; atomic m_currentDataVersion; diff --git a/routing/edge_estimator.cpp b/routing/edge_estimator.cpp index 13911d50cc..42f2c0df98 100644 --- a/routing/edge_estimator.cpp +++ b/routing/edge_estimator.cpp @@ -44,8 +44,8 @@ double CarEdgeEstimator::CalcEdgesWeight(uint32_t featureId, RoadGeometry const double result = 0.0; double const speedMPS = road.GetSpeed() * kKMPH2MPS; - uint8_t const dir = start < finish ? TrafficInfo::RoadSegmentId::kForwardDirection - : TrafficInfo::RoadSegmentId::kReverseDirection; + uint8_t const dir = pointFrom < pointTo ? TrafficInfo::RoadSegmentId::kForwardDirection + : TrafficInfo::RoadSegmentId::kReverseDirection; for (uint32_t i = start; i < finish; ++i) { double factor = 1.0; @@ -55,8 +55,7 @@ double CarEdgeEstimator::CalcEdgesWeight(uint32_t featureId, RoadGeometry const m_trafficInfo->GetSpeedGroup(TrafficInfo::RoadSegmentId(featureId, i, dir)); CHECK_LESS(speedGroup, SpeedGroup::Count, ()); double const percentage = - 0.01 * - static_cast(kSpeedGroupThresholdPercentage[static_cast(speedGroup)]); + 0.01 * static_cast(kSpeedGroupThresholdPercentage[static_cast(speedGroup)]); factor = 1.0 / percentage; } result += factor * TimeBetweenSec(road.GetPoint(i), road.GetPoint(i + 1), speedMPS); diff --git a/routing/routing_session.hpp b/routing/routing_session.hpp index 942113da9e..94ae541cee 100644 --- a/routing/routing_session.hpp +++ b/routing/routing_session.hpp @@ -38,7 +38,7 @@ struct SpeedCameraRestriction SpeedCameraRestriction() : m_index(0), m_maxSpeedKmH(numeric_limits::max()) {} }; -class RoutingSession : public traffic::RoutingObserver, public traffic::TrafficInfoGetter +class RoutingSession : public traffic::TrafficObserver, public traffic::TrafficInfoGetter { friend void UnitTest_TestFollowRoutePercentTest(); diff --git a/routing/routing_tests/applying_traffic_test.cpp b/routing/routing_tests/applying_traffic_test.cpp index adae50868f..d2010553a5 100644 --- a/routing/routing_tests/applying_traffic_test.cpp +++ b/routing/routing_tests/applying_traffic_test.cpp @@ -85,43 +85,62 @@ unique_ptr BuildXXGraph(shared_ptr estimator) return graph; } -// Route through XX graph without any traffic info. -UNIT_TEST(XXGraph_EmptyTrafficColoring) +class ApplingTrafficTest { - classificator::Load(); - shared_ptr estimator = - EdgeEstimator::CreateForCar(*make_shared()->GetVehicleModel()); +public: + ApplingTrafficTest() + { + classificator::Load(); + m_estimator = EdgeEstimator::CreateForCar(*make_shared()->GetVehicleModel()); + } - unique_ptr graph = BuildXXGraph(estimator); + shared_ptr m_estimator; +}; + +// Route through XX graph without any traffic info. +UNIT_CLASS_TEST(ApplingTrafficTest, XXGraph_EmptyTrafficColoring) +{ + unique_ptr graph = BuildXXGraph(m_estimator); IndexGraphStarter starter(*graph, RoadPoint(1, 0) /* start */, RoadPoint(6, 1) /* finish */); vector const expectedGeom = {{2 /* x */, 0 /* y */}, {1, 1}, {2, 2}, {3, 3}}; TestRouteGeometry(starter, AStarAlgorithm::Result::OK, expectedGeom); } // Route through XX graph with SpeedGroup::G0 on F3. -UNIT_TEST(XXGraph_G0onF3) +UNIT_CLASS_TEST(ApplingTrafficTest, XXGraph_G0onF3) { - classificator::Load(); - shared_ptr estimator = - EdgeEstimator::CreateForCar(*make_shared()->GetVehicleModel()); TrafficInfo::Coloring coloring = { {{3 /* feature id */, 0 /* segment id */, TrafficInfo::RoadSegmentId::kForwardDirection}, SpeedGroup::G0}}; shared_ptr trafficInfo = make_shared(); trafficInfo->SetColoringForTesting(coloring); - estimator->SetTrafficInfo(trafficInfo); + m_estimator->SetTrafficInfo(trafficInfo); - unique_ptr graph = BuildXXGraph(estimator); + unique_ptr graph = BuildXXGraph(m_estimator); IndexGraphStarter starter(*graph, RoadPoint(1, 0) /* start */, RoadPoint(6, 1) /* finish */); vector const expectedGeom = {{2 /* x */, 0 /* y */}, {3, 0}, {3, 1}, {2, 2}, {3, 3}}; TestRouteGeometry(starter, AStarAlgorithm::Result::OK, expectedGeom); } -// Route through XX graph SpeedGroup::G1 on F3 and F6, SpeedGroup::G4 on F8 and F4. -UNIT_TEST(XXGraph_G0onF3andF6andG4onF8andF4) +// Route through XX graph with SpeedGroup::G0 in reverse direction on F3. +UNIT_CLASS_TEST(ApplingTrafficTest, XXGraph_G0onF3ReverseDir) +{ + TrafficInfo::Coloring coloring = { + {{3 /* feature id */, 0 /* segment id */, TrafficInfo::RoadSegmentId::kReverseDirection}, + SpeedGroup::G0}}; + shared_ptr trafficInfo = make_shared(); + trafficInfo->SetColoringForTesting(coloring); + m_estimator->SetTrafficInfo(trafficInfo); + + unique_ptr graph = BuildXXGraph(m_estimator); + IndexGraphStarter starter(*graph, RoadPoint(1, 0) /* start */, RoadPoint(6, 1) /* finish */); + vector const expectedGeom = {{2 /* x */, 0 /* y */}, {1, 1}, {2, 2}, {3, 3}}; + TestRouteGeometry(starter, AStarAlgorithm::Result::OK, expectedGeom); +} + +// Route through XX graph SpeedGroup::G1 on F3 and F6, SpeedGroup::G4 on F8 and F4. +UNIT_CLASS_TEST(ApplingTrafficTest, XXGraph_G0onF3andF6andG4onF8andF4) { - shared_ptr estimator = - EdgeEstimator::CreateForCar(*make_shared()->GetVehicleModel()); TrafficInfo::Coloring coloring = { {{3 /* feature id */, 0 /* segment id */, TrafficInfo::RoadSegmentId::kForwardDirection}, SpeedGroup::G0}, @@ -133,9 +152,9 @@ UNIT_TEST(XXGraph_G0onF3andF6andG4onF8andF4) SpeedGroup::G4}}; shared_ptr trafficInfo = make_shared(); trafficInfo->SetColoringForTesting(coloring); - estimator->SetTrafficInfo(trafficInfo); + m_estimator->SetTrafficInfo(trafficInfo); - unique_ptr graph = BuildXXGraph(estimator); + unique_ptr graph = BuildXXGraph(m_estimator); IndexGraphStarter starter(*graph, RoadPoint(1, 0) /* start */, RoadPoint(6, 1) /* finish */); vector const expectedGeom = {{2 /* x */, 0 /* y */}, {3, 0}, {3, 1}, {2, 2}, {3, 3}}; TestRouteGeometry(starter, AStarAlgorithm::Result::OK, expectedGeom); diff --git a/traffic/traffic_info.hpp b/traffic/traffic_info.hpp index 53f485b49c..af257c17f9 100644 --- a/traffic/traffic_info.hpp +++ b/traffic/traffic_info.hpp @@ -93,10 +93,10 @@ private: int64_t m_currentDataVersion = 0; }; -class RoutingObserver +class TrafficObserver { public: - virtual ~RoutingObserver() = default; + virtual ~TrafficObserver() = default; virtual void OnTrafficEnabled(bool enable) = 0; virtual void OnTrafficInfoAdded(traffic::TrafficInfo const & info) = 0;