From 9046058f42d73db174acd6d6cda6fecc34b63c78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=BE=D0=B1=D1=80=D1=8B=D0=B8=CC=86=20=D0=AD=D1=8D?= =?UTF-8?q?=D1=85?= Date: Fri, 14 Apr 2017 18:02:04 +0300 Subject: [PATCH] [routing] Bidirectional Astar optimization --- routing/base/astar_algorithm.hpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/routing/base/astar_algorithm.hpp b/routing/base/astar_algorithm.hpp index a17738210f..b1ba850a9e 100644 --- a/routing/base/astar_algorithm.hpp +++ b/routing/base/astar_algorithm.hpp @@ -110,6 +110,8 @@ private: BidirectionalStepContext(bool forward, TVertexType const & startVertex, TVertexType const & finalVertex, TGraphType & graph) : forward(forward), startVertex(startVertex), finalVertex(finalVertex), graph(graph) + , m_piRT(graph.HeuristicCostEstimate(finalVertex, startVertex)) + , m_piFS(graph.HeuristicCostEstimate(startVertex, finalVertex)) { bestVertex = forward ? startVertex : finalVertex; pS = ConsistentHeuristic(bestVertex); @@ -128,19 +130,17 @@ private: { double const piF = graph.HeuristicCostEstimate(v, finalVertex); double const piR = graph.HeuristicCostEstimate(v, startVertex); - double const piRT = graph.HeuristicCostEstimate(finalVertex, startVertex); - double const piFS = graph.HeuristicCostEstimate(startVertex, finalVertex); if (forward) { /// @todo careful: with this "return" here and below in the Backward case /// the heuristic becomes inconsistent but still seems to work. /// return HeuristicCostEstimate(v, finalVertex); - return 0.5 * (piF - piR + piRT); + return 0.5 * (piF - piR + m_piRT); } else { // return HeuristicCostEstimate(v, startVertex); - return 0.5 * (piR - piF + piFS); + return 0.5 * (piR - piF + m_piFS); } } @@ -156,6 +156,8 @@ private: TVertexType const & startVertex; TVertexType const & finalVertex; TGraph & graph; + double const m_piRT; + double const m_piFS; priority_queue, greater> queue; map bestDistance;