Package algs
Class DijkstraDirected
java.lang.Object
algs.DijkstraDirected
Dijkstra's algorithm.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Functional interface for edge weights. -
Constructor Summary
ConstructorDescriptionCreate an instance of Dijkstra's algorithm for graph g.Create an instance of Dijkstra's algorithm to compute shortest paths from s to all other vertices in g. -
Method Summary
Modifier and TypeMethodDescriptiondouble
Get the length of the shortest path from vertex s to vertex f.Get the edges on the shortest path from vertex s to vertex f.Get the vertices on the shortest path from vertex s to vertex f.void
Initialize the algorithm.void
run()
Compute shortest paths from s to all vertices.void
Compute shortest path from vertex s to vertex f.
-
Constructor Details
-
DijkstraDirected
Create an instance of Dijkstra's algorithm for graph g. Assumes that the weight for edge e is (Double)e.getObject().- Parameters:
g
- the graph
-
DijkstraDirected
Create an instance of Dijkstra's algorithm to compute shortest paths from s to all other vertices in g.- Parameters:
g
- the graphw
- function taking an Edge and returning the weight for the edge (as a double)
-
-
Method Details
-
init
Initialize the algorithm.- Parameters:
s
- starting vertex
-
run
public void run()Compute shortest paths from s to all vertices. -
run
Compute shortest path from vertex s to vertex f.- Parameters:
f
- finish vertex; if null, compute the shortest path to all vertices
-
getPathVertices
Get the vertices on the shortest path from vertex s to vertex f.- Parameters:
f
- finish vertex- Returns:
- the vertices on the shortest path from vertex s to vertex f
-
getPathEdges
Get the edges on the shortest path from vertex s to vertex f.- Parameters:
f
- finish vertex- Returns:
- the edges on the shortest path from vertex s to vertex f
-
getDist
Get the length of the shortest path from vertex s to vertex f.- Parameters:
f
- finish vertex- Returns:
- the length of the shortest path from vertex s to vertex f
-