|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.rblasch.convert.dijkstra.ShortestPathEngine
An implementation of Dijkstra's shortest path algorithm. It computes the shortest path (in distance) to all cities in the map. The output of the algorithm is the shortest distance from the start vertex to every other vertex, and the shortest path from the start vertex to every other.
Upon callingexecute(Vertex, Vertex)
,
the results of the algorithm are made available by calling
getPredecessor(Vertex)
and
getShortestDistance(Vertex)
.
To get the shortest path between the vertex destination and
the source vertex after running the algorithm, one would do:
List l = new ArrayList(); for (Object vertex = destination; vertex != null; vertex = engine.getPredecessor(vertex)) { l.add(vertex); } Collections.reverse(l); return l;
execute(Vertex, Vertex)
Field Summary | |
static int |
INFINITE_DISTANCE
Infinity value for distances. |
Constructor Summary | |
ShortestPathEngine(WeightedDirectedGraph map)
Constructor. |
Method Summary | |
void |
execute(Vertex start,
Vertex destination)
Run Dijkstra's shortest path algorithm on the map. |
int |
getMinWeight(Vertex start,
Vertex end)
Get the value of a segment. |
Vertex |
getPredecessor(Vertex vertex)
|
int |
getShortestDistance(Vertex vertex)
|
Path |
getShortestPath(Vertex start,
Vertex end)
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int INFINITE_DISTANCE
Constructor Detail |
public ShortestPathEngine(WeightedDirectedGraph map)
Method Detail |
public void execute(Vertex start, Vertex destination)
getPredecessor(Vertex)
and
getShortestDistance(Vertex)
upon completion of this method.
start
- the starting vertexdestination
- the destination vertex. If this argument is null
, the algorithm is
run on the entire graph, instead of being stopped as soon as the destination is reached.public Path getShortestPath(Vertex start, Vertex end)
public int getMinWeight(Vertex start, Vertex end)
public int getShortestDistance(Vertex vertex)
INFINITE_DISTANCE
if there is no route to the destination.public Vertex getPredecessor(Vertex vertex)
null
if there is no route to the destination.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |