Interface ShortestPathSingleSource.Result<V,E>
- Type Parameters:
V- the vertices typeE- the edges type
- All Known Subinterfaces:
ShortestPathSingleSource.IResult
- Enclosing interface:
ShortestPathSingleSource
ShortestPathSingleSource problem.- Author:
- Barak Ugav
-
Method Summary
Modifier and TypeMethodDescriptionbacktrackEdge(V target) Get the last edge on the shortest path from the source to the given target.doubleGet the distance to a target vertex.Get shortest path to a target vertex.graph()Get the graph on which the shortest paths were computed on.default booleanisReachable(V target) Check if a target vertex is reachable from the source.Get the set of vertices reachable from the source.Get the shortest path tree.shortestPathTree(boolean directed) Get the shortest path tree, optionally directed or undirected.source()Get the source vertex from which all shortest paths were computed from.
-
Method Details
-
distance
Get the distance to a target vertex.- Parameters:
target- a target vertex in the graph- Returns:
- the sum of the shortest path edges from the source to the target, or
Double.POSITIVE_INFINITYif no such path found - Throws:
NoSuchVertexException- iftargetis not a vertex in the graph
-
getPath
Get shortest path to a target vertex.- Parameters:
target- a target vertex in the graph- Returns:
- the shortest path from the source to the target or
nullif no such path found. - Throws:
NoSuchVertexException- iftargetis not a vertex in the graph
-
backtrackEdge
Get the last edge on the shortest path from the source to the given target.The backtrack edge is an in-edge of the given target vertex. The set of all backtrack edges of all vertices define the shortest path tree of the source, and each shortest path can be constructed from them.
- Parameters:
target- a target vertex in the graph- Returns:
- the backtrack edge, the last edge on the shortest path from the source to the
given target, or
nullif there is no path to the target or the target is the source - Throws:
NoSuchVertexException- iftargetis not a vertex in the graph
-
isReachable
Check if a target vertex is reachable from the source.- Parameters:
target- a target vertex in the graph- Returns:
trueif the target is reachable from the source,falseotherwise- Throws:
NoSuchVertexException- iftargetis not a vertex in the graph
-
reachableVertices
-
shortestPathTree
Get the shortest path tree.The shortest path tree is constructed from the vertices and edges used by any shortest path. It contains only the vertices reachable from the source, and for each vertex other than the source the graph will contains the edge that was used to reach it (see
backtrackEdge(Object)). If there are \(k\) reachable vertices, the graph will contain \(k-1\) edges.The returned graph will be directed if the original graph is directed. In such case, the tree is directed from the source to the other vertices. To control the directionality of the returned graph, use
shortestPathTree(boolean).- Returns:
- undirected shortest path tree
-
shortestPathTree
Get the shortest path tree, optionally directed or undirected.The shortest path tree is constructed from the vertices and edges used by any shortest path. It contains only the vertices reachable from the source, and for each vertex other than the source the graph will contains the edge that was used to reach it (see
backtrackEdge(Object)). If there are \(k\) reachable vertices, the graph will contain \(k-1\) edges.- Parameters:
directed- iftruethe returned tree will be directed. If the original graph was undirected and a directed tree is created, the edges in the tree will be directed from the source towards the other vertices- Returns:
- un/directed shortest path tree
-
source
V source()Get the source vertex from which all shortest paths were computed from.- Returns:
- the source vertex
-
graph
-