edu.upc.dama.dex.algorithms
Class SinglePairShortestPathDijkstra

java.lang.Object
  extended by edu.upc.dama.dex.tasks.Task
      extended by edu.upc.dama.dex.tasks.CompositeTask
          extended by edu.upc.dama.dex.algorithms.ShortestPath
              extended by edu.upc.dama.dex.algorithms.SinglePairShortestPath
                  extended by edu.upc.dama.dex.algorithms.SinglePairShortestPathDijkstra
All Implemented Interfaces:
Algorithm

public class SinglePairShortestPathDijkstra
extends SinglePairShortestPath

This class can be used to solve the single-pair shortest path problem in a weighted graph.

Concretely, it consists in finding a path between two nodes with the condition that the sum of the weights of the edges which belong to the path is minimized. This implementation is based on the Dijkstra 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:

Navigation

There are three kinds of edge navigation:

For each instance of this class, it is only allowed to run the algorithm once. After the execution, we can retrieve the following results: Please, see 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.

Author:
Sparsity Technologies

Field Summary
 
Fields inherited from interface edu.upc.dama.dex.algorithms.Algorithm
NAVIGATION_BACKWARD, NAVIGATION_FORWARD, NAVIGATION_UNDIRECTED
 
Constructor Summary
SinglePairShortestPathDijkstra(Graph graph, long source, long dest)
          Creates a new instance of SinglePairShortestPathDijkstra.
 
Method Summary
 void addWeightedEdge(int edgetype, short navigation, long attributetype)
          Adds an edge type, its navigation and its attribute containing the weight 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.
 java.lang.Double getCost()
          Returns the cost, that is, the sum of the weights of the edges which belong to the path.
 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

SinglePairShortestPathDijkstra

public SinglePairShortestPathDijkstra(Graph graph,
                                      long source,
                                      long dest)
Creates a new instance of SinglePairShortestPathDijkstra. 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.

Parameters:
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

addWeightedEdge

public void addWeightedEdge(int edgetype,
                            short navigation,
                            long attributetype)
Adds an edge type, its navigation and its attribute containing the weight in order to restrict the set of edge types allowed and their direction while traversing the graph to find the path. It is possible to add as many edge types as all the different edge types contained in the graph.

Parameters:
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.
attributetype - The attribute identifier of the given edge type which contains the weight value.

getCost

public java.lang.Double getCost()
Returns the cost, that is, the sum of the weights of the edges which belong to the path. If there isn't any shortest path found, it returns -1 .

Returns:
The sum of the weights of the edges which belong to the path.

close

public void close()
Description copied from class: ShortestPath
Closes the instance.

Once executed, the instance becomes invalid.

Specified by:
close in class ShortestPath

run

public void run()
         throws java.lang.Throwable
Description copied from class: ShortestPath
Runs the algorithm in order to solve the shortest path problem.

This method can be called only once.

Specified by:
run in class ShortestPath
Throws:
java.lang.Throwable