MCPcopy Create free account
hub / github.com/comaps/comaps / FindPath

Method FindPath

libs/routing/base/astar_algorithm.hpp:450–520  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

448template <typename Vertex, typename Edge, typename Weight>
449template <typename P>
450typename 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

Callers

nothing calls this directly

Calls 7

GetTargetMethod · 0.80
ClearMethod · 0.45
HeuristicCostEstimateMethod · 0.45
IsCancelledMethod · 0.45
GetWeightMethod · 0.45
ReconstructPathMethod · 0.45
GetDistanceMethod · 0.45

Tested by

no test coverage detected