| 448 | template <typename Vertex, typename Edge, typename Weight> |
| 449 | template <typename P> |
| 450 | typename AStarAlgorithm<Vertex, Edge, Weight>::Result AStarAlgorithm<Vertex, Edge, Weight>::FindPath( |
| 451 | P & params, RoutingResult<Vertex, Weight> & result) const |
| 452 | { |
| 453 | auto const epsilon = params.m_weightEpsilon; |
| 454 | |
| 455 | result.Clear(); |
| 456 | |
| 457 | auto & graph = params.m_graph; |
| 458 | auto const & finalVertex = params.m_finalVertex; |
| 459 | auto const & startVertex = params.m_startVertex; |
| 460 | |
| 461 | Context context(graph); |
| 462 | PeriodicPollCancellable periodicCancellable(params.m_cancellable); |
| 463 | Result resultCode = Result::NoPath; |
| 464 | |
| 465 | auto const heuristicDiff = [&](Vertex const & vertexFrom, Vertex const & vertexTo) |
| 466 | { return graph.HeuristicCostEstimate(vertexFrom, finalVertex) - graph.HeuristicCostEstimate(vertexTo, finalVertex); }; |
| 467 | |
| 468 | auto const fullToReducedLength = [&](Vertex const & vertexFrom, Vertex const & vertexTo, Weight const length) |
| 469 | { return length - heuristicDiff(vertexFrom, vertexTo); }; |
| 470 | |
| 471 | auto const reducedToFullLength = [&](Vertex const & vertexFrom, Vertex const & vertexTo, Weight const reducedLength) |
| 472 | { return reducedLength + heuristicDiff(vertexFrom, vertexTo); }; |
| 473 | |
| 474 | auto visitVertex = [&](Vertex const & vertex) |
| 475 | { |
| 476 | if (periodicCancellable.IsCancelled()) |
| 477 | { |
| 478 | resultCode = Result::Cancelled; |
| 479 | return false; |
| 480 | } |
| 481 | |
| 482 | params.m_onVisitedVertexCallback(vertex, finalVertex); |
| 483 | |
| 484 | if (vertex == finalVertex) |
| 485 | { |
| 486 | resultCode = Result::OK; |
| 487 | return false; |
| 488 | } |
| 489 | |
| 490 | return true; |
| 491 | }; |
| 492 | |
| 493 | auto const adjustEdgeWeight = [&](Vertex const & vertexV, Edge const & edge) |
| 494 | { |
| 495 | auto const reducedWeight = fullToReducedLength(vertexV, edge.GetTarget(), edge.GetWeight()); |
| 496 | |
| 497 | CHECK_GREATER_OR_EQUAL(reducedWeight, -epsilon, ("Invariant violated.")); |
| 498 | |
| 499 | return std::max(reducedWeight, kZeroDistance); |
| 500 | }; |
| 501 | |
| 502 | auto const reducedToRealLength = [&](State const & state) |
| 503 | { return reducedToFullLength(startVertex, state.vertex, state.distance); }; |
| 504 | |
| 505 | auto const filterStates = [&](State const & state) |
| 506 | { return params.m_checkLengthCallback(reducedToRealLength(state)); }; |
| 507 |
nothing calls this directly
no test coverage detected