getShortestPath method

Path getShortestPath(
  1. String destination, [
  2. String? start
])

Engages Dijkstra and returns the shortest path from start to destination

Implementation

Path getShortestPath(String destination, [String? start]) {
  Path path =
      _dijkstra.solveByString(start ?? currentEdge!.source.id, destination);

  if (currentEdge != null && path.path.length > 1) {
    EpitaphVertex targetVertex = currentEdge!.target;

    if (!targetVertex.equalsById(path.path.elementAt(1))) {
      path.path.addFirst(targetVertex);
      currentEdge = _graph.getEdgeByString(
          path.path.first.id, path.path.elementAt(1).id);
    }
  }

  return path;
}