Interface ShortestPathST
-
public interface ShortestPathST
An algorithm for computing the shortest path between two vertices in a graph.Given a graph \(G=(V,E)\), and a weight function \(w:E \rightarrow R\), one might ask what is the shortest path from a source vertex to a target vertex, where the 'shortest' is defined by comparing the sum of edges weights of each path. This interface computes such a path. It differ from the more known
ShortestPathSingleSource
, as it does not compute the paths from a source to all vertices, only to a specific target. This might be more efficient in some cases, as less than linear time and space can be used.A variant with a heuristic distance function is also available, see
ShortestPathHeuristicST
.Use
newInstance()
to get a default implementation of this interface. A builder obtained vianewBuilder()
may support different options to obtain different implementations.- Author:
- Barak Ugav
- See Also:
ShortestPathSingleSource
,ShortestPathAllPairs
,ShortestPathHeuristicST
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
ShortestPathST.Builder
A builder forShortestPathST
objects.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description <V,E>
Path<V,E>computeShortestPath(Graph<V,E> g, WeightFunction<E> w, V source, V target)
Compute the shortest path from a source vertex to a target vertex.static ShortestPathST.Builder
newBuilder()
Create a new S-T shortest path algorithm builder.static ShortestPathST
newInstance()
Create a new S-T shortest path algorithm object.
-
-
-
Method Detail
-
computeShortestPath
<V,E> Path<V,E> computeShortestPath(Graph<V,E> g, WeightFunction<E> w, V source, V target)
Compute the shortest path from a source vertex to a target vertex.If
g
is anIntGraph
, aIPath
object will be returned. In that case, its better to pass aIWeightFunction
asw
to avoid boxing/unboxing.- Type Parameters:
V
- the vertices typeE
- the edges type- Parameters:
g
- the graphw
- an edge weight functionsource
- the source vertextarget
- the target vertex- Returns:
- the shortest path from the source to the target, or
null
if there is no path
-
newInstance
static ShortestPathST newInstance()
Create a new S-T shortest path algorithm object.This is the recommended way to instantiate a new
ShortestPathST
object. TheShortestPathST.Builder
might support different options to obtain different implementations.- Returns:
- a default implementation of
ShortestPathST
-
newBuilder
static ShortestPathST.Builder newBuilder()
Create a new S-T shortest path algorithm builder.Use
newInstance()
for a default implementation.- Returns:
- a new builder that can build
ShortestPathST
objects
-
-