Package com.gengoai.graph.algorithms
Class DijkstraShortestPath<V>
- java.lang.Object
-
- com.gengoai.graph.algorithms.DijkstraShortestPath<V>
-
- Type Parameters:
V
- the Vertex type parameter
- All Implemented Interfaces:
GraphSearch<V>
,ShortestPath<V>
,SingleSourceShortestPath<V>
public class DijkstraShortestPath<V> extends Object implements SingleSourceShortestPath<V>, ShortestPath<V>, GraphSearch<V>
Implementation of Dijkstra's algorithm for finding the shortest paths between vertices in a graph.
- Author:
- David B. Bracewell
-
-
Constructor Summary
Constructors Constructor Description DijkstraShortestPath(Graph<V> graph)
Instantiates a new Dijkstra shortest path.DijkstraShortestPath(Graph<V> graph, boolean treatUndirected)
Instantiates a new Dijkstra shortest path.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description double
distance(V source, V target)
The distance between the two vertices.List<Edge<V>>
path(V source, V target)
The shortest path (list of edges) from the source to target vertex.void
reset()
Resets cached dataList<Edge<V>>
search(V startingPoint, V endingPoint)
Searches for a path from the given starting point to the given ending pointCounter<V>
singleSourceShortestDistance(V source)
The distance between the source vertex and all other vertices in the graphListMultimap<V,Edge<V>>
singleSourceShortestPath(V source)
The path (list of edges) between the source vertex and all other vertices in the graph
-
-
-
Method Detail
-
search
public List<Edge<V>> search(V startingPoint, V endingPoint)
Description copied from interface:GraphSearch
Searches for a path from the given starting point to the given ending point- Specified by:
search
in interfaceGraphSearch<V>
- Parameters:
startingPoint
- the starting pointendingPoint
- the ending point- Returns:
- the path as a list of edges (empty list if no path exists)
-
singleSourceShortestDistance
public Counter<V> singleSourceShortestDistance(V source)
Description copied from interface:SingleSourceShortestPath
The distance between the source vertex and all other vertices in the graph- Specified by:
singleSourceShortestDistance
in interfaceSingleSourceShortestPath<V>
- Parameters:
source
- the source vertex- Returns:
- Counter of target vertices and their distances.
-
singleSourceShortestPath
public ListMultimap<V,Edge<V>> singleSourceShortestPath(V source)
Description copied from interface:SingleSourceShortestPath
The path (list of edges) between the source vertex and all other vertices in the graph- Specified by:
singleSourceShortestPath
in interfaceSingleSourceShortestPath<V>
- Parameters:
source
- the source vertex- Returns:
- ListMultimap of target vertices and paths from source to target.
-
distance
public double distance(V source, V target)
Description copied from interface:ShortestPath
The distance between the two vertices.- Specified by:
distance
in interfaceShortestPath<V>
- Parameters:
source
- the starting (source) vertextarget
- the target vertex- Returns:
- the distance from source to target (Positive Infinity if no path exists).
-
path
public List<Edge<V>> path(V source, V target)
Description copied from interface:ShortestPath
The shortest path (list of edges) from the source to target vertex.- Specified by:
path
in interfaceShortestPath<V>
- Parameters:
source
- the starting (source) vertextarget
- the target vertex- Returns:
- List of edges from source to target representing the shortest path.
-
reset
public void reset()
Resets cached data
-
-