From 4c54c5ccd783cdeca96fa891589970ccd0bd61d3 Mon Sep 17 00:00:00 2001 From: Vladimir Byko-Ianko Date: Fri, 13 Feb 2015 18:52:03 +0300 Subject: [PATCH] Fixes after rebase. --- integration_tests/osrm_route_test.cpp | 4 +- integration_tests/osrm_test_tools.cpp | 69 +++++++++++---------------- integration_tests/osrm_turn_test.cpp | 2 +- routing/osrm_router.cpp | 21 +++----- routing/osrm_router.hpp | 8 ++-- 5 files changed, 39 insertions(+), 65 deletions(-) diff --git a/integration_tests/osrm_route_test.cpp b/integration_tests/osrm_route_test.cpp index 28f8ea3c83..faed8e7f7d 100644 --- a/integration_tests/osrm_route_test.cpp +++ b/integration_tests/osrm_route_test.cpp @@ -10,13 +10,13 @@ namespace { shared_ptr routerComponents = integration::GetAllMaps(); integration::CalculateRouteAndTestRouteLength(routerComponents, {37.53758809983519, 67.536162466434234}, - {0., 0.}, {37.40993977728661, 67.644784047393685}, 14296.); + {0., 0.}, {37.40993977728661, 67.644784047393685}, 14296.); } UNIT_TEST(RussiaMoscowGerPanfilovtsev22SolodchaPravdiRouteTest) { shared_ptr routerComponents = integration::GetAllMaps(); integration::CalculateRouteAndTestRouteLength(routerComponents, {37.409929478750627, 67.644798619710073}, - {0., 0.}, {39.836562407458047, 65.774372510437971}, 253275.); + {0., 0.}, {39.836562407458047, 65.774372510437971}, 253275.); } } diff --git a/integration_tests/osrm_test_tools.cpp b/integration_tests/osrm_test_tools.cpp index e65532ab6c..3578e73230 100644 --- a/integration_tests/osrm_test_tools.cpp +++ b/integration_tests/osrm_test_tools.cpp @@ -20,39 +20,6 @@ using namespace routing; namespace integration { - class OsrmRouterWrapper : public OsrmRouter - { - public: - OsrmRouterWrapper(Index const * index, CountryFileFnT const & fn) : - OsrmRouter(index, fn) {} - ResultCode SyncCalculateRoute(m2::PointD const & startPt, m2::PointD const & startDr, m2::PointD const & finalPt, Route & route) - { - SetFinalPoint(finalPt); - return CalculateRouteImpl(startPt, startDr, finalPt, route); - } - }; - - shared_ptr CreateSearchEngine(search::Engine::IndexType const * pIndex) - { - ASSERT(pIndex, ()); - Platform const & pl = GetPlatform(); - try - { - shared_ptr searchEngine(new search::Engine( - pIndex, - pl.GetReader(SEARCH_CATEGORIES_FILE_NAME), - pl.GetReader(PACKED_POLYGONS_FILE), - pl.GetReader(COUNTRIES_FILE), - languages::GetCurrentOrig())); - return searchEngine; - } - catch (RootException const &) - { - ASSERT(false, ()); - return nullptr; - } - } - shared_ptr CreateFeaturesFetcher(vector const & mapNames) { shared_ptr featuresFetcher(new model::FeaturesFetcher); @@ -71,16 +38,34 @@ namespace integration shared_ptr CreateSearchEngine(shared_ptr featuresFetcher) { - shared_ptr searchEngine = CreateSearchEngine(&featuresFetcher->GetIndex()); - if (!searchEngine.get()) + ASSERT(featuresFetcher.get(), ()); + search::Engine::IndexType const & index = featuresFetcher->GetIndex(); + + Platform const & pl = GetPlatform(); + try + { + shared_ptr searchEngine(new search::Engine( + &index, + pl.GetReader(SEARCH_CATEGORIES_FILE_NAME), + pl.GetReader(PACKED_POLYGONS_FILE), + pl.GetReader(COUNTRIES_FILE), + languages::GetCurrentOrig())); + return searchEngine; + } + catch (RootException const &) + { ASSERT(false, ()); - return searchEngine; + return nullptr; + } } - shared_ptr CreateOsrmRouter(shared_ptr featuresFetcher, + shared_ptr CreateOsrmRouter(shared_ptr featuresFetcher, shared_ptr searchEngine) { - shared_ptr osrmRouter(new OsrmRouterWrapper(&featuresFetcher->GetIndex(), + ASSERT(featuresFetcher.get(), ()); + ASSERT(searchEngine.get(), ()); + + shared_ptr osrmRouter(new OsrmRouter(&featuresFetcher->GetIndex(), [searchEngine] (m2::PointD const & pt) { return searchEngine->GetCountryFile(pt); @@ -95,11 +80,11 @@ namespace integration m_featuresFetcher(CreateFeaturesFetcher(mapNames)), m_searchEngine(CreateSearchEngine(m_featuresFetcher)), m_osrmRouter(CreateOsrmRouter(m_featuresFetcher, m_searchEngine)) {} - OsrmRouterWrapper * GetOsrmRouter() const { return m_osrmRouter.get(); } + OsrmRouter * GetOsrmRouter() const { return m_osrmRouter.get(); } private: shared_ptr m_featuresFetcher; shared_ptr m_searchEngine; - shared_ptr m_osrmRouter; + shared_ptr m_osrmRouter; }; void GetMapNames(vector & maps) @@ -137,10 +122,10 @@ namespace integration m2::PointD const & startPt, m2::PointD const & startDr, m2::PointD const & finalPt) { ASSERT(routerComponents.get(), ()); - OsrmRouterWrapper * osrmRouter = routerComponents->GetOsrmRouter(); + OsrmRouter * osrmRouter = routerComponents->GetOsrmRouter(); ASSERT(osrmRouter, ()); shared_ptr route(new Route("mapsme")); - OsrmRouter::ResultCode result = osrmRouter->SyncCalculateRoute(startPt, startDr, finalPt, *route.get()); + OsrmRouter::ResultCode result = osrmRouter->CalculateRouteImpl(startPt, startDr, finalPt, *route.get()); return RouteResultT(route, result); } diff --git a/integration_tests/osrm_turn_test.cpp b/integration_tests/osrm_turn_test.cpp index 128dc7014b..c737a45f14 100644 --- a/integration_tests/osrm_turn_test.cpp +++ b/integration_tests/osrm_turn_test.cpp @@ -12,7 +12,7 @@ UNIT_TEST(RussiaMoscowLenigradskiy39UturnTurnTest) shared_ptr routerComponents = integration::GetAllMaps(); RouteResultT const routeResult = integration::CalculateRoute(routerComponents, {37.537544383032568, 67.536216737893028}, - {0., 0.}, {37.538908531885973, 67.54544090660923}); + {0., 0.}, {37.538908531885973, 67.54544090660923}); shared_ptr const route = routeResult.first; OsrmRouter::ResultCode const result = routeResult.second; diff --git a/routing/osrm_router.cpp b/routing/osrm_router.cpp index dacd74c291..18bc1b581a 100644 --- a/routing/osrm_router.cpp +++ b/routing/osrm_router.cpp @@ -505,6 +505,12 @@ void OsrmRouter::CalculateRouteAsync(ReadyCallback const & callback) startPt = m_startPt; finalPt = m_finalPt; startDr = m_startDr; + + if (m_isFinalChanged) + m_cachedFinalNodes.clear(); + m_isFinalChanged = false; + + m_requestCancel = false; } try @@ -558,24 +564,9 @@ bool IsRouteExist(RawRouteData const & r) void OsrmRouter::FindWeightsMatrix(MultiroutingTaskPointT const & sources, MultiroutingTaskPointT const & targets, RawDataFacadeT &facade, vector &result) { - SearchEngineData engineData; NMManyToManyRouting pathFinder(&facade, engineData); - { - threads::MutexGuard params(m_paramsMutex); - UNUSED_VALUE(params); - if (m_isFinalChanged) - m_cachedFinalNodes.clear(); - m_isFinalChanged = false; - m_requestCancel = false; - } - - // 1. Find country file name and check that we are in the same MWM. - //string fName = m_countryFn(startPt); - //if (fName != m_countryFn(finalPt)) - // return PointsInDifferentMWM; - PhantomNodeArray sourcesTaskVector(sources.size()); PhantomNodeArray targetsTaskVector(targets.size()); for (int i = 0; i < sources.size(); ++i) diff --git a/routing/osrm_router.hpp b/routing/osrm_router.hpp index 14768215a4..1cfa3d291c 100644 --- a/routing/osrm_router.hpp +++ b/routing/osrm_router.hpp @@ -121,10 +121,8 @@ public: */ class RoutingIndexManager { -protected: - typedef function CountryFileFnT; -private: CountryFileFnT m_countryFn; + map m_mapping; public: @@ -134,7 +132,6 @@ public: RoutingMappingPtrT GetMappingByName(string const & fName, Index const * pIndex); -public: void Clear() { m_mapping.clear(); @@ -198,6 +195,8 @@ public: void ActivateAdditionalFeatures() {m_additionalFeatures = true;} + ResultCode CalculateRouteImpl(m2::PointD const & startPt, m2::PointD const & startDr, m2::PointD const & finalPt, Route & route); + protected: IRouter::ResultCode FindPhantomNodes(string const & fName, m2::PointD const & point, m2::PointD const & direction, FeatureGraphNodeVecT & res, size_t maxCount, RoutingMappingPtrT const & mapping); @@ -227,7 +226,6 @@ protected: vector & points, Route::TurnsT & turnsDir,Route::TimesT & times, turns::TurnsGeomT & turnsGeom); void CalculateRouteAsync(ReadyCallback const & callback); - ResultCode CalculateRouteImpl(m2::PointD const & startPt, m2::PointD const & startDr, m2::PointD const & finalPt, Route & route); private: typedef pair MwmOutT;