All Packages Class Hierarchy This Package Previous Next Index
Class drasys.or.graph.sp.Dijkstra
drasys.or.graph.sp.Dijkstra
- public class Dijkstra
- implements SingleVertexI
A single vertex shortest path implementation using Dijkstra's algorithm.
This is an implementation that works well with both sparse and dense graphs but it ignores the connection properties.
This algorithm finds all of the paths between a root vertex and a set of candidate vertices.
This collection of paths forms a tree where the candidates that were reached from the root are leaves of the tree.
The path generation can be constrained by path count, path length and path cost.
The constraints all reduce the size of the path tree and can greatly improve performance.
By default the properties object is set to 'null'.
When the properties object is null, the algorithm behaves like it is using 'PropertiesAdapter'.
References:
Introduction to Algorithms
Thomas H. Cormen, et al / Hardcover / Published 1990
Graphs : Theory and Algorithms
K. Thulasiraman, M.N.S. Swamy / Paperback / Published 1992
Copyright (C) 1997,1998 by DRA Systems all rights reserved.
-
Dijkstra(GraphI)
- A constructor that sets the target graph.
-
Dijkstra(GraphI, PriorityQueueI)
- A constructor that sets the target graph and the 'PriorityQueueI' used by the algorithm.
-
candidates()
- Creates an Enumeration on the candidate vertices that were reached in the path generation.
-
generatePathsFrom(Object)
- Creates the single source shortest path tree from the root vertex to the candidate vertices.
-
generatePathsTo(Object)
- Creates the single destination shortest path tree from the candidate vertices to the root vertex.
-
getCost(VertexI)
- Gets the cost of the path between this candidate vertex and the root vertex.
-
getNearestCandidate()
- Returns the candidate vertex for the single shortest path generated.
-
getPath(VertexI)
- Creates a path Vector containing the elements in the path between the candidate vertex and the root.
-
pathElements(VertexI)
- Creates an Enumeration on the elements in the path from this candidate vertex to the root vertex.
-
setCandidate(boolean)
- Sets the candidate flags for all vertices.
-
setCandidate(Object, boolean)
- Sets the candidate flag for a specific vertex.
-
setListener(SingleVertexListenerI)
- Sets the listener to receive the shortest path events.
-
setMaxCost(double)
- Sets the maximum cost for any path.
-
setMaxLength(int)
- Sets the maximum number of edges in any path.
-
setMaxPaths(int)
- Sets the maximum number of paths the the algorithm will generate.
-
setProperties(PropertiesI)
- Sets the properties object that is used to access vertex and edge properties.
-
toString()
-
-
usesConnectionProperties()
- Returns false because this algorithm ignores the connection properties.
Dijkstra
public Dijkstra(GraphI graph)
- A constructor that sets the target graph.
Dijkstra
public Dijkstra(GraphI graph,
PriorityQueueI queue)
- A constructor that sets the target graph and the 'PriorityQueueI' used by the algorithm.
The queue's compare function will be set to 'CompareNumberReverse'.
usesConnectionProperties
public boolean usesConnectionProperties()
- Returns false because this algorithm ignores the connection properties.
- Returns:
- false
setListener
public void setListener(SingleVertexListenerI listener)
- Sets the listener to receive the shortest path events.
Passing a null argument disables events.
setProperties
public void setProperties(PropertiesI properties)
- Sets the properties object that is used to access vertex and edge properties.
If the argument is null, the algorithm behaves like it is using 'PropertiesAdapter'.
setMaxPaths
public void setMaxPaths(int maxPaths)
- Sets the maximum number of paths the the algorithm will generate.
The paths generated will be the 'maxPaths' shortest paths.
The default is Integer.MAX_VALUE.
setMaxLength
public void setMaxLength(int maxLength)
- Sets the maximum number of edges in any path.
The length of no path will be greater than this value.
The default is Integer.MAX_VALUE.
setMaxCost
public void setMaxCost(double maxCost)
- Sets the maximum cost for any path.
The cost of no path will be greater than this value.
The default is Double.POSITIVE_INFINITY.
setCandidate
public void setCandidate(boolean isCandidate)
- Sets the candidate flags for all vertices.
By default no vertices are marked as candidates.
setCandidate
public void setCandidate(Object key,
boolean isCandidate) throws VertexNotFoundException
- Sets the candidate flag for a specific vertex.
By default no vertices are marked as candidates.
generatePathsTo
public int generatePathsTo(Object rootKey) throws VertexNotFoundException, InvalidPropertyException
- Creates the single destination shortest path tree from the candidate vertices to the root vertex.
The paths will be directed from the candidate vertices to the root vertex.
- Returns:
- The number of paths generated.
generatePathsFrom
public int generatePathsFrom(Object rootKey) throws VertexNotFoundException, InvalidPropertyException
- Creates the single source shortest path tree from the root vertex to the candidate vertices.
The paths will be directed from the root vertex to the candidate vertices.
- Returns:
- The number of paths generated.
getNearestCandidate
public VertexI getNearestCandidate()
- Returns the candidate vertex for the single shortest path generated.
- Returns:
- Null if no paths were found.
candidates
public Enumeration candidates()
- Creates an Enumeration on the candidate vertices that were reached in the path generation.
The candidates are returned in order of the nearest first.
pathElements
public Enumeration pathElements(VertexI candidate) throws VertexNotFoundException
- Creates an Enumeration on the elements in the path from this candidate vertex to the root vertex.
The enumeration returns all the edges and the vertices in alternating order starting and ending with a vertex.
The edges are returned in order starting from the candidate vertex and ending at the root vertex.
Note that this is the most efficient way to sequence through a path.
The elements are returned in reverse path order if the root vertex is the source vertex.
- Throws: GraphError
- if the candidate is not owned by the graph.
getPath
public Vector getPath(VertexI candidate) throws VertexNotFoundException
- Creates a path Vector containing the elements in the path between the candidate vertex and the root.
The vector contains all the edges and the vertices in alternating order starting and ending with a vertex.
The elements will always be arranged in the order of forward path traversal.
- Throws: GraphError
- if the candidate is not owned by the graph.
getCost
public double getCost(VertexI candidate) throws VertexNotFoundException
- Gets the cost of the path between this candidate vertex and the root vertex.
- Returns:
- Double.POSITIVE_INFINITY if no path was found, zero if the candidate is the root.
- Throws: GraphError
- if the candidate is not owned by the graph.
toString
public String toString()
All Packages Class Hierarchy This Package Previous Next Index