diff --git a/routing/osrm_helpers.cpp b/routing/osrm_helpers.cpp index 42d60f3481..c7b0bde0cb 100644 --- a/routing/osrm_helpers.cpp +++ b/routing/osrm_helpers.cpp @@ -37,7 +37,7 @@ void Point2PhantomNode::FindNearestSegment(FeatureType const & ft, m2::PointD co void Point2PhantomNode::operator()(FeatureType const & ft) { - //TODO(gardster) Extract GEOM_LINE check into CatModel. + //TODO(gardster) Extract GEOM_LINE check into CarModel. if (ft.GetFeatureType() != feature::GEOM_LINE || !CarModel::Instance().IsRoad(ft)) return; @@ -72,7 +72,7 @@ double Point2PhantomNode::CalculateDistance(OsrmMappingTypes::FtSeg const & s) c void Point2PhantomNode::CalculateWeight(OsrmMappingTypes::FtSeg const & seg, m2::PointD const & segPt, NodeID const & nodeId, - bool calcFromRight, int & weight) const + bool calcFromRight, int & weight, int & offset) const { // nodeId can be INVALID_NODE_ID when reverse node is absent. This node has no weight. if (nodeId == INVALID_NODE_ID || m_routingMapping.m_dataFacade.GetOutDegree(nodeId) == 0) @@ -140,7 +140,8 @@ void Point2PhantomNode::CalculateWeight(OsrmMappingTypes::FtSeg const & seg, ft.ParseGeometry(FeatureType::BEST_GEOMETRY); minWeight = GetMinNodeWeight(nodeId, ft.GetPoint(segment.m_pointEnd)); } - weight = max(static_cast(minWeight * ratio), 0); + offset = minWeight; + weight = max(static_cast(minWeight * ratio), 0) - minWeight; } EdgeWeight Point2PhantomNode::GetMinNodeWeight(NodeID node, m2::PointD const & point) const @@ -263,7 +264,7 @@ void Point2PhantomNode::MakeResult(vector & res, size_t maxCou node.segmentPoint = m_candidates[j].m_point; node.mwmName = mwmName; - CalculateOffsets(node); + CalculateWeights(node); } res.erase(remove_if(res.begin(), res.end(), [](FeatureGraphNode const & f) @@ -273,17 +274,14 @@ void Point2PhantomNode::MakeResult(vector & res, size_t maxCou res.end()); } -void Point2PhantomNode::CalculateOffsets(FeatureGraphNode & node) const +void Point2PhantomNode::CalculateWeights(FeatureGraphNode & node) const { + // Need to initialize weights for correct work of PhantomNode::GetForwardWeightPlusOffset + // and PhantomNode::GetReverseWeightPlusOffset. CalculateWeight(node.segment, node.segmentPoint, node.node.forward_node_id, - true /* calcFromRight */, node.node.forward_weight); + true /* calcFromRight */, node.node.forward_weight, node.node.forward_offset); CalculateWeight(node.segment, node.segmentPoint, node.node.reverse_node_id, - false /* calcFromRight */, node.node.reverse_weight); - - // Need to initialize weights for correct work of PhantomNode::GetForwardWeightPlusOffset - // and PhantomNode::GetReverseWeightPlusOffset. - node.node.forward_offset = 0; - node.node.reverse_offset = 0; + false /* calcFromRight */, node.node.reverse_weight, node.node.reverse_offset); } void Point2Node::operator()(FeatureType const & ft) @@ -292,7 +290,7 @@ void Point2Node::operator()(FeatureType const & ft) return; uint32_t const featureId = ft.GetID().m_index; for (auto const n : m_routingMapping.m_segMapping.GetNodeIdByFid(featureId)) - n_nodeIds.push_back(n); + m_nodeIds.push_back(n); } } // namespace helpers } // namespace routing diff --git a/routing/osrm_helpers.hpp b/routing/osrm_helpers.hpp index 730f39498a..4f9a9748f1 100644 --- a/routing/osrm_helpers.hpp +++ b/routing/osrm_helpers.hpp @@ -58,13 +58,13 @@ private: /// Calculates part of a node weight in the OSRM format. Projection point @segPt divides node on /// two parts. So we find weight of a part, set by the @calcFromRight parameter. void CalculateWeight(OsrmMappingTypes::FtSeg const & seg, m2::PointD const & segPt, - NodeID const & nodeId, bool calcFromRight, int & weight) const; + NodeID const & nodeId, bool calcFromRight, int & weight, int & offset) const; /// Returns minimal weight of the node. EdgeWeight GetMinNodeWeight(NodeID node, m2::PointD const & point) const; /// Calculates weights and offsets section of the routing tasks. - void CalculateOffsets(FeatureGraphNode & node) const; + void CalculateWeights(FeatureGraphNode & node) const; m2::PointD m_point; m2::PointD const m_direction; @@ -79,11 +79,11 @@ private: class Point2Node { RoutingMapping const & m_routingMapping; - vector & n_nodeIds; + vector & m_nodeIds; public: Point2Node(RoutingMapping const & routingMapping, vector & nodeID) - : m_routingMapping(routingMapping), n_nodeIds(nodeID) + : m_routingMapping(routingMapping), m_nodeIds(nodeID) { } diff --git a/routing/osrm_router.cpp b/routing/osrm_router.cpp index 038e35e60d..73865cb3ad 100644 --- a/routing/osrm_router.cpp +++ b/routing/osrm_router.cpp @@ -1,4 +1,3 @@ -#include "car_model.hpp" #include "cross_mwm_router.hpp" #include "online_cross_fetcher.hpp" #include "osrm2feature_map.hpp" @@ -414,8 +413,6 @@ OsrmRouter::ResultCode OsrmRouter::MakeTurnAnnotation( LOG(LDEBUG, ("Shortest path length:", routingResult.shortestPathLength)); - //! @todo: Improve last segment time calculation - CarModel const & carModel = CarModel::Instance(); #ifdef DEBUG size_t lastIdx = 0; #endif @@ -506,7 +503,20 @@ OsrmRouter::ResultCode OsrmRouter::MakeTurnAnnotation( auto startIdx = seg.m_pointStart; auto endIdx = seg.m_pointEnd; - bool const needTime = (segmentIndex == 0) || (segmentIndex == numSegments - 1); + if (segmentIndex == 0) + { + if (pathSegments[segmentIndex].node == routingResult.sourceEdge.node.forward_node_id) + estimatedTime += -routingResult.sourceEdge.node.forward_weight/10; + else + estimatedTime += -routingResult.sourceEdge.node.reverse_weight/10; + } + if (segmentIndex == numSegments - 1) + { + if (pathSegments[segmentIndex].node == routingResult.sourceEdge.node.forward_node_id) + estimatedTime += routingResult.sourceEdge.node.forward_weight/10; + else + estimatedTime += routingResult.sourceEdge.node.reverse_weight/10; + } if (segmentIndex == 0 && k == startK && segBegin.IsValid()) startIdx = (seg.m_pointEnd > seg.m_pointStart) ? segBegin.m_pointStart : segBegin.m_pointEnd; @@ -518,16 +528,12 @@ OsrmRouter::ResultCode OsrmRouter::MakeTurnAnnotation( for (auto idx = startIdx; idx <= endIdx; ++idx) { points.push_back(ft.GetPoint(idx)); - if (needTime && idx > startIdx) - estimatedTime += MercatorBounds::DistanceOnEarth(ft.GetPoint(idx - 1), ft.GetPoint(idx)) / carModel.GetSpeed(ft); } } else { for (auto idx = startIdx; idx > endIdx; --idx) { - if (needTime) - estimatedTime += MercatorBounds::DistanceOnEarth(ft.GetPoint(idx - 1), ft.GetPoint(idx)) / carModel.GetSpeed(ft); points.push_back(ft.GetPoint(idx)); } points.push_back(ft.GetPoint(endIdx)); diff --git a/xcode/indexer/indexer.xcodeproj/project.pbxproj b/xcode/indexer/indexer.xcodeproj/project.pbxproj index 098c52a48a..453303d521 100644 --- a/xcode/indexer/indexer.xcodeproj/project.pbxproj +++ b/xcode/indexer/indexer.xcodeproj/project.pbxproj @@ -48,8 +48,6 @@ 670D04AD1B0BA8580013A7AC /* interval_index_101.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 670D04AA1B0BA8580013A7AC /* interval_index_101.hpp */; }; 670EE56C1B60033A001E8064 /* features_vector.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 670EE56A1B60033A001E8064 /* features_vector.cpp */; }; 670EE56D1B60033A001E8064 /* unique_index.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 670EE56B1B60033A001E8064 /* unique_index.hpp */; }; - 670F291F1BA86D5400F2ABF4 /* drules_city_rank_table.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 670F291D1BA86D5400F2ABF4 /* drules_city_rank_table.cpp */; }; - 670F29201BA86D5400F2ABF4 /* drules_city_rank_table.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 670F291E1BA86D5400F2ABF4 /* drules_city_rank_table.hpp */; }; 6726C1D11A49DAAC005EEA39 /* feature_meta.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6726C1CF1A49DAAC005EEA39 /* feature_meta.cpp */; }; 6726C1D21A49DAAC005EEA39 /* feature_meta.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 6726C1D01A49DAAC005EEA39 /* feature_meta.hpp */; }; 674125131B4C02F100A3E828 /* map_style_reader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 674125101B4C02F100A3E828 /* map_style_reader.cpp */; }; @@ -195,8 +193,6 @@ 670D05AB1B0E07040013A7AC /* defaults.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = defaults.xcconfig; path = ../defaults.xcconfig; sourceTree = ""; }; 670EE56A1B60033A001E8064 /* features_vector.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = features_vector.cpp; sourceTree = ""; }; 670EE56B1B60033A001E8064 /* unique_index.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = unique_index.hpp; sourceTree = ""; }; - 670F291D1BA86D5400F2ABF4 /* drules_city_rank_table.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = drules_city_rank_table.cpp; sourceTree = ""; }; - 670F291E1BA86D5400F2ABF4 /* drules_city_rank_table.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = drules_city_rank_table.hpp; sourceTree = ""; }; 6726C1CF1A49DAAC005EEA39 /* feature_meta.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = feature_meta.cpp; sourceTree = ""; }; 6726C1D01A49DAAC005EEA39 /* feature_meta.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = feature_meta.hpp; sourceTree = ""; }; 674125101B4C02F100A3E828 /* map_style_reader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = map_style_reader.cpp; sourceTree = ""; }; @@ -321,10 +317,6 @@ isa = PBXGroup; children = ( 670C61571AB068C100C38A8C /* Libs */, - 678FB4181BB43D8900C49B9C /* drules_selector_parser.cpp */, - 678FB4191BB43D8900C49B9C /* drules_selector_parser.hpp */, - 678FB41A1BB43D8900C49B9C /* drules_selector.cpp */, - 678FB41B1BB43D8900C49B9C /* drules_selector.hpp */, 670C611F1AB065E100C38A8C /* testingmain.cpp */, 670C60F91AB065B100C38A8C /* categories_test.cpp */, 670C60FA1AB065B100C38A8C /* cell_coverer_test.cpp */, @@ -407,8 +399,6 @@ 6758AECE1BB4413000C26E27 /* drules_selector_parser.hpp */, 6758AECF1BB4413000C26E27 /* drules_selector.cpp */, 6758AED01BB4413000C26E27 /* drules_selector.hpp */, - 670F291D1BA86D5400F2ABF4 /* drules_city_rank_table.cpp */, - 670F291E1BA86D5400F2ABF4 /* drules_city_rank_table.hpp */, 674125101B4C02F100A3E828 /* map_style_reader.cpp */, 674125111B4C02F100A3E828 /* map_style_reader.hpp */, 674125121B4C02F100A3E828 /* map_style.hpp */, @@ -511,7 +501,6 @@ buildActionMask = 2147483647; files = ( 675341361A3F540F00A0A8C3 /* mercator.hpp in Headers */, - 670F29201BA86D5400F2ABF4 /* drules_city_rank_table.hpp in Headers */, 6753414E1A3F540F00A0A8C3 /* types_mapping.hpp in Headers */, 6753411F1A3F540F00A0A8C3 /* feature_loader.hpp in Headers */, 675341151A3F540F00A0A8C3 /* feature_covering.hpp in Headers */, @@ -676,7 +665,6 @@ 675341211A3F540F00A0A8C3 /* feature_utils.cpp in Sources */, 670C61151AB065B100C38A8C /* interval_index_test.cpp in Sources */, 670C61121AB065B100C38A8C /* geometry_serialization_test.cpp in Sources */, - 670F291F1BA86D5400F2ABF4 /* drules_city_rank_table.cpp in Sources */, 675341231A3F540F00A0A8C3 /* feature_visibility.cpp in Sources */, 670C610F1AB065B100C38A8C /* checker_test.cpp in Sources */, 675341161A3F540F00A0A8C3 /* feature_data.cpp in Sources */, diff --git a/xcode/routing/routing.xcodeproj/project.pbxproj b/xcode/routing/routing.xcodeproj/project.pbxproj index fb25ed31db..ad58900978 100644 --- a/xcode/routing/routing.xcodeproj/project.pbxproj +++ b/xcode/routing/routing.xcodeproj/project.pbxproj @@ -70,6 +70,8 @@ A1616E2B1B6B60AB003F078E /* router_delegate.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A1616E291B6B60AB003F078E /* router_delegate.cpp */; }; A1616E2C1B6B60AB003F078E /* router_delegate.hpp in Headers */ = {isa = PBXBuildFile; fileRef = A1616E2A1B6B60AB003F078E /* router_delegate.hpp */; }; A1616E2E1B6B60B3003F078E /* astar_progress.hpp in Headers */ = {isa = PBXBuildFile; fileRef = A1616E2D1B6B60B3003F078E /* astar_progress.hpp */; }; + A17B42981BCFBD0E00A1EAE4 /* osrm_helpers.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A17B42961BCFBD0E00A1EAE4 /* osrm_helpers.cpp */; settings = {ASSET_TAGS = (); }; }; + A17B42991BCFBD0E00A1EAE4 /* osrm_helpers.hpp in Headers */ = {isa = PBXBuildFile; fileRef = A17B42971BCFBD0E00A1EAE4 /* osrm_helpers.hpp */; settings = {ASSET_TAGS = (); }; }; A1876BC61BB19C4300C9C743 /* speed_camera.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A1876BC41BB19C4300C9C743 /* speed_camera.cpp */; settings = {ASSET_TAGS = (); }; }; A1876BC71BB19C4300C9C743 /* speed_camera.hpp in Headers */ = {isa = PBXBuildFile; fileRef = A1876BC51BB19C4300C9C743 /* speed_camera.hpp */; settings = {ASSET_TAGS = (); }; }; /* End PBXBuildFile section */ @@ -140,6 +142,8 @@ A1616E291B6B60AB003F078E /* router_delegate.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = router_delegate.cpp; sourceTree = ""; }; A1616E2A1B6B60AB003F078E /* router_delegate.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = router_delegate.hpp; sourceTree = ""; }; A1616E2D1B6B60B3003F078E /* astar_progress.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = astar_progress.hpp; sourceTree = ""; }; + A17B42961BCFBD0E00A1EAE4 /* osrm_helpers.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = osrm_helpers.cpp; path = ../../routing/osrm_helpers.cpp; sourceTree = ""; }; + A17B42971BCFBD0E00A1EAE4 /* osrm_helpers.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = osrm_helpers.hpp; path = ../../routing/osrm_helpers.hpp; sourceTree = ""; }; A1876BC41BB19C4300C9C743 /* speed_camera.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = speed_camera.cpp; sourceTree = ""; }; A1876BC51BB19C4300C9C743 /* speed_camera.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = speed_camera.hpp; sourceTree = ""; }; /* End PBXFileReference section */ @@ -169,6 +173,8 @@ 675343EF1A3F640D00A0A8C3 = { isa = PBXGroup; children = ( + A17B42961BCFBD0E00A1EAE4 /* osrm_helpers.cpp */, + A17B42971BCFBD0E00A1EAE4 /* osrm_helpers.hpp */, 670D05A61B0E02560013A7AC /* defaults.xcconfig */, 675343FA1A3F640D00A0A8C3 /* routing */, 675343F91A3F640D00A0A8C3 /* Products */, @@ -277,6 +283,7 @@ 6753441C1A3F644F00A0A8C3 /* route.hpp in Headers */, A1616E2C1B6B60AB003F078E /* router_delegate.hpp in Headers */, 67C7D4301B4EB48F00FE41AA /* turns_sound.hpp in Headers */, + A17B42991BCFBD0E00A1EAE4 /* osrm_helpers.hpp in Headers */, 67C7D42E1B4EB48F00FE41AA /* turns_sound_settings.hpp in Headers */, 670EE55E1B6001E7001E8064 /* routing_session.hpp in Headers */, 670EE55F1B6001E7001E8064 /* routing_settings.hpp in Headers */, @@ -365,6 +372,7 @@ 670D049E1B0B4A970013A7AC /* nearest_edge_finder.cpp in Sources */, 674F9BD61B0A580E00704FFA /* turns_generator.cpp in Sources */, 675344171A3F644F00A0A8C3 /* osrm_router.cpp in Sources */, + A17B42981BCFBD0E00A1EAE4 /* osrm_helpers.cpp in Sources */, 674F9BD21B0A580E00704FFA /* road_graph_router.cpp in Sources */, A1876BC61BB19C4300C9C743 /* speed_camera.cpp in Sources */, 671F58BD1B874EC80032311E /* followed_polyline.cpp in Sources */,