|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectedu.upc.dama.dex.tasks.Task
edu.upc.dama.dex.tasks.CompositeTask
edu.upc.dama.dex.algorithms.ShortestPath
edu.upc.dama.dex.algorithms.SinglePairShortestPath
edu.upc.dama.dex.algorithms.SinglePairShortestPathBFS
public class SinglePairShortestPathBFS
This class can be used to solve the single-pair shortest path problem in an unweighted graph.
Concretely, it consists in finding a path between two nodes with the condition that the total of edges which belong to the path is minimized. This implementation is based on the Breadth-First Search (BFS) algorithm.
It is possible to set some restrictions after constructing a new instance of this class and before running it in order to limit the results. Those restrictions are:
ShortestPath.setMaximumHops(int maxhops) method.
SinglePairShortestPathBFS.addEdge(int edgetype, short navigation)
for adding one edge type and its navigation and SinglePairShortestPathBFS.addAllEdges(short navigation)
for adding all edges types and their navigation.
Navigation
There are three kinds of edge navigation:
Algorithm.NAVIGATION_FORWARD: Allows to forward traverse edges.
Algorithm.NAVIGATION_BACKWARD: Allows to backward traverse edges.
Algorithm.NAVIGATION_UNDIRECTED: Allows to traverse edges in both directions.
SinglePairShortestPathBFS.getCost() method.
SinglePairShortestPath.getPathAsNodes() method.
SinglePairShortestPath.getPathAsEdges() method.
edu.upc.dama.dex.algorithms for further information related
to how to use this class.
NOTE: It is required to indicate the set of edge types before running this algorithm.
| Field Summary |
|---|
| Fields inherited from interface edu.upc.dama.dex.algorithms.Algorithm |
|---|
NAVIGATION_BACKWARD, NAVIGATION_FORWARD, NAVIGATION_UNDIRECTED |
| Constructor Summary | |
|---|---|
SinglePairShortestPathBFS(Graph graph,
long source,
long dest)
Creates a new instance of SinglePairShortestPathBFS. |
|
| Method Summary | |
|---|---|
void |
addAllEdges(short navigation)
Adds all the edge types contained in the graph and their navigation in order to restrict the set of edge types allowed and their direction while traversing the graph to find the path. |
void |
addEdge(int edgetype,
short navigation)
Adds an edge type and its navigation in order to restrict the set of edge types allowed and their direction while traversing the graph to find the path. |
void |
close()
Closes the instance. |
int |
getCost()
Returns the cost, that is, the total hops done while achieving the destination node from the source node. |
void |
run()
Runs the algorithm in order to solve the shortest path problem. |
| Methods inherited from class edu.upc.dama.dex.algorithms.SinglePairShortestPath |
|---|
existsShortestPath, getPathAsEdges, getPathAsNodes |
| Methods inherited from class edu.upc.dama.dex.algorithms.ShortestPath |
|---|
setMaximumHops |
| Methods inherited from class edu.upc.dama.dex.tasks.CompositeTask |
|---|
cancel, execute, init |
| Methods inherited from class edu.upc.dama.dex.tasks.Task |
|---|
main |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public SinglePairShortestPathBFS(Graph graph,
long source,
long dest)
SinglePairShortestPathBFS. After creating
this instance is required to indicate the set of edge types which will be
navigated through while traversing the graph in order to find the path.
graph - Graph on which the path will be found.source - The node identifier which identifies the source node at
which the algorithm execution will start.dest - The node identifier which identifies the destination node at
which the algorithm execution will end.| Method Detail |
|---|
public void addAllEdges(short navigation)
navigation - The direction that has to be followed while traversing
each edge during the execution of this algorithm. It must be
Algorithm.NAVIGATION_BACKWARD, Algorithm.NAVIGATION_FORWARD or
Algorithm.NAVIGATION_UNDIRECTED.
public void addEdge(int edgetype,
short navigation)
edgetype - The edge type to restrict the set of edges allowed
while traversing the graph during the execution of this algorithm.navigation - The direction that has to be followed while traversing
each edge of the given edge type during the execution of this algorithm.
It must be Algorithm.NAVIGATION_BACKWARD, Algorithm.NAVIGATION_FORWARD or
Algorithm.NAVIGATION_UNDIRECTED.public void close()
ShortestPathOnce executed, the instance becomes invalid.
close in class ShortestPathpublic int getCost()
-1 .
public void run()
throws java.lang.Throwable
ShortestPathThis method can be called only once.
run in class ShortestPathjava.lang.Throwable
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||