org.neo4j.graphalgo.impl.shortestpath
Class SingleSourceShortestPathDijkstra<CostType>

java.lang.Object
  extended by org.neo4j.graphalgo.impl.shortestpath.Dijkstra<CostType>
      extended by org.neo4j.graphalgo.impl.shortestpath.SingleSourceShortestPathDijkstra<CostType>
Type Parameters:
CostType - The datatype the edge weights are represented by.
All Implemented Interfaces:
SingleSourceShortestPath<CostType>, SingleSourceSingleSinkShortestPath<CostType>

public class SingleSourceShortestPathDijkstra<CostType>
extends Dijkstra<CostType>
implements SingleSourceShortestPath<CostType>

Dijkstra implementation to solve the single source shortest path problem for weighted networks.

Author:
Patrik Larsson

Nested Class Summary
 
Nested classes/interfaces inherited from class org.neo4j.graphalgo.impl.shortestpath.Dijkstra
Dijkstra.DijstraIterator
 
Field Summary
protected  HashMap<Node,CostType> distances
           
 
Fields inherited from class org.neo4j.graphalgo.impl.shortestpath.Dijkstra
calculateAllShortestPaths, costAccumulator, costComparator, costEvaluator, costRelationTypes, doneCalculation, endNode, foundPathsCost, foundPathsMiddleNodes, maxCost, maxNodesToTraverse, maxRelationShipsToTraverse, numberOfNodesTraversed, numberOfTraversedRelationShips, predecessors1, predecessors2, relationDirection, startCost, startNode
 
Constructor Summary
SingleSourceShortestPathDijkstra(CostType startCost, Node startNode, CostEvaluator<CostType> costEvaluator, CostAccumulator<CostType> costAccumulator, Comparator<CostType> costComparator, Direction relationDirection, RelationshipType... costRelationTypes)
           
 
Method Summary
 boolean calculate()
          Makes the main calculation If some limit is set, the shortest path(s) that could be found within those limits will be calculated.
 boolean calculate(Node targetNode)
          Internal calculate method that will run the calculation until either the limit is reached or a result has been generated for a given node.
 boolean calculateMultiple(Node targetNode)
          Same as calculate(), but will set the flag to calculate all shortest paths.
 CostType getCost()
          A call to this will run the algorithm to find the cost for the shortest paths between the start node and the end node, if not calculated before.
 CostType getCost(Node targetNode)
          A call to this will run the algorithm, if not already done, and return the cost for the shortest paths between the start node and the target node.
 Direction getDirection()
          This can be used to retrieve the Direction in which relationships should be in the shortest path(s).
 List<PropertyContainer> getPath()
          A call to this will run the algorithm to find a single shortest path, if not already done, and return it as an alternating list of Node/Relationship.
 List<PropertyContainer> getPath(Node targetNode)
          A call to this will run the algorithm to find a single shortest path, if not already done, and return it as an alternating list of Node/Relationship.
 List<Node> getPathAsNodes()
          A call to this will run the algorithm to find a single shortest path, if not already done, and return it as a list of nodes.
 List<Node> getPathAsNodes(Node targetNode)
          A call to this will run the algorithm, if not already done, and return the found path to the target node if found as a list of nodes.
 List<Relationship> getPathAsRelationships()
          A call to this will run the algorithm to find a single shortest path, if not already done, and return it as a list of Relationships.
 List<Relationship> getPathAsRelationships(Node targetNode)
          A call to this will run the algorithm to find a single shortest path, if not already done, and return it as a list of Relationships.
 List<List<PropertyContainer>> getPaths()
          A call to this will run the algorithm to find all shortest paths, if not already done, and return them as alternating lists of Node/Relationship.
 List<List<PropertyContainer>> getPaths(Node targetNode)
          A call to this will run the algorithm to find all shortest paths, if not already done, and return them as alternating lists of Node/Relationship.
 List<List<Node>> getPathsAsNodes()
          A call to this will run the algorithm to find all shortest paths, if not already done, and return them as lists of nodes.
 List<List<Node>> getPathsAsNodes(Node targetNode)
          A call to this will run the algorithm to find all shortest paths, if not already done, and return them as lists of nodes.
 List<List<Relationship>> getPathsAsRelationships()
          A call to this will run the algorithm to find all shortest paths, if not already done, and return them as lists of relationships.
 List<List<Relationship>> getPathsAsRelationships(Node targetNode)
          A call to this will run the algorithm to find all shortest paths, if not already done, and return them as lists of relationships.
 List<Node> getPredecessorNodes(Node node)
           
 Map<Node,List<Relationship>> getPredecessors()
          This can be used to retrieve the entire data structure representing the predecessors for every node.
 RelationshipType[] getRelationshipTypes()
          This can be used to retrieve the types of relationships that are traversed.
 void reset()
          Resets the result data to force the computation to be run again when some result is asked for.
 void setEndNode(Node endNode)
          Set the end node.
 
Methods inherited from class org.neo4j.graphalgo.impl.shortestpath.Dijkstra
calculateMultiple, limitMaxCostToTraverse, limitMaxNodesToTraverse, limitMaxRelationShipsToTraverse, limitReached, limitReached, setStartNode
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.neo4j.graphalgo.impl.shortestpath.SingleSourceShortestPath
setStartNode
 

Field Detail

distances

protected HashMap<Node,CostType> distances
Constructor Detail

SingleSourceShortestPathDijkstra

public SingleSourceShortestPathDijkstra(CostType startCost,
                                        Node startNode,
                                        CostEvaluator<CostType> costEvaluator,
                                        CostAccumulator<CostType> costAccumulator,
                                        Comparator<CostType> costComparator,
                                        Direction relationDirection,
                                        RelationshipType... costRelationTypes)
See Also:
Dijkstra
Method Detail

reset

public void reset()
Description copied from class: Dijkstra
Resets the result data to force the computation to be run again when some result is asked for.

Specified by:
reset in interface SingleSourceShortestPath<CostType>
Specified by:
reset in interface SingleSourceSingleSinkShortestPath<CostType>
Overrides:
reset in class Dijkstra<CostType>

calculateMultiple

public boolean calculateMultiple(Node targetNode)
Same as calculate(), but will set the flag to calculate all shortest paths. It sets the flag and then calls calculate.

Returns:

calculate

public boolean calculate()
Description copied from class: Dijkstra
Makes the main calculation If some limit is set, the shortest path(s) that could be found within those limits will be calculated.

Overrides:
calculate in class Dijkstra<CostType>
Returns:
True if a path was found.

calculate

public boolean calculate(Node targetNode)
Internal calculate method that will run the calculation until either the limit is reached or a result has been generated for a given node.


setEndNode

public void setEndNode(Node endNode)
Description copied from class: Dijkstra
Set the end node. Will reset the calculation.

Specified by:
setEndNode in interface SingleSourceSingleSinkShortestPath<CostType>
Overrides:
setEndNode in class Dijkstra<CostType>
Parameters:
endNode - the endNode to set

getCost

public CostType getCost(Node targetNode)
Description copied from interface: SingleSourceShortestPath
A call to this will run the algorithm, if not already done, and return the cost for the shortest paths between the start node and the target node.

Specified by:
getCost in interface SingleSourceShortestPath<CostType>
Returns:
The total weight of the shortest path(s).
See Also:
Dijkstra

getPaths

public List<List<PropertyContainer>> getPaths(Node targetNode)
Description copied from interface: SingleSourceShortestPath
A call to this will run the algorithm to find all shortest paths, if not already done, and return them as alternating lists of Node/Relationship.

Specified by:
getPaths in interface SingleSourceShortestPath<CostType>
Returns:
A list of the paths as alternating lists of Node/Relationship.

getPathsAsNodes

public List<List<Node>> getPathsAsNodes(Node targetNode)
Description copied from interface: SingleSourceShortestPath
A call to this will run the algorithm to find all shortest paths, if not already done, and return them as lists of nodes.

Specified by:
getPathsAsNodes in interface SingleSourceShortestPath<CostType>
Returns:
A list of the paths as lists of nodes.

getPathsAsRelationships

public List<List<Relationship>> getPathsAsRelationships(Node targetNode)
Description copied from interface: SingleSourceShortestPath
A call to this will run the algorithm to find all shortest paths, if not already done, and return them as lists of relationships.

Specified by:
getPathsAsRelationships in interface SingleSourceShortestPath<CostType>
Returns:
A list of the paths as lists of relationships.

getPath

public List<PropertyContainer> getPath(Node targetNode)
Description copied from interface: SingleSourceShortestPath
A call to this will run the algorithm to find a single shortest path, if not already done, and return it as an alternating list of Node/Relationship.

Specified by:
getPath in interface SingleSourceShortestPath<CostType>
Returns:
The path as an alternating list of Node/Relationship.

getPathAsNodes

public List<Node> getPathAsNodes(Node targetNode)
Description copied from interface: SingleSourceShortestPath
A call to this will run the algorithm, if not already done, and return the found path to the target node if found as a list of nodes.

Specified by:
getPathAsNodes in interface SingleSourceShortestPath<CostType>
Returns:
The path as a list of nodes.

getPathAsRelationships

public List<Relationship> getPathAsRelationships(Node targetNode)
Description copied from interface: SingleSourceShortestPath
A call to this will run the algorithm to find a single shortest path, if not already done, and return it as a list of Relationships.

Specified by:
getPathAsRelationships in interface SingleSourceShortestPath<CostType>
Returns:
The path as a list of Relationships.

getCost

public CostType getCost()
Description copied from interface: SingleSourceSingleSinkShortestPath
A call to this will run the algorithm to find the cost for the shortest paths between the start node and the end node, if not calculated before. This will usually find a single shortest path.

Specified by:
getCost in interface SingleSourceSingleSinkShortestPath<CostType>
Overrides:
getCost in class Dijkstra<CostType>
Returns:
The cost for the found path(s).

getPath

public List<PropertyContainer> getPath()
Description copied from interface: SingleSourceSingleSinkShortestPath
A call to this will run the algorithm to find a single shortest path, if not already done, and return it as an alternating list of Node/Relationship.

Specified by:
getPath in interface SingleSourceSingleSinkShortestPath<CostType>
Overrides:
getPath in class Dijkstra<CostType>
Returns:
One of the shortest paths found or null.

getPathAsNodes

public List<Node> getPathAsNodes()
Description copied from interface: SingleSourceSingleSinkShortestPath
A call to this will run the algorithm to find a single shortest path, if not already done, and return it as a list of nodes.

Specified by:
getPathAsNodes in interface SingleSourceSingleSinkShortestPath<CostType>
Overrides:
getPathAsNodes in class Dijkstra<CostType>
Returns:
One of the shortest paths found or null.

getPathAsRelationships

public List<Relationship> getPathAsRelationships()
Description copied from interface: SingleSourceSingleSinkShortestPath
A call to this will run the algorithm to find a single shortest path, if not already done, and return it as a list of Relationships.

Specified by:
getPathAsRelationships in interface SingleSourceSingleSinkShortestPath<CostType>
Overrides:
getPathAsRelationships in class Dijkstra<CostType>
Returns:
One of the shortest paths found or null.

getPaths

public List<List<PropertyContainer>> getPaths()
Description copied from interface: SingleSourceSingleSinkShortestPath
A call to this will run the algorithm to find all shortest paths, if not already done, and return them as alternating lists of Node/Relationship.

Specified by:
getPaths in interface SingleSourceSingleSinkShortestPath<CostType>
Overrides:
getPaths in class Dijkstra<CostType>
Returns:
All the found paths or null.

getPathsAsNodes

public List<List<Node>> getPathsAsNodes()
Description copied from interface: SingleSourceSingleSinkShortestPath
A call to this will run the algorithm to find all shortest paths, if not already done, and return them as lists of nodes.

Specified by:
getPathsAsNodes in interface SingleSourceSingleSinkShortestPath<CostType>
Overrides:
getPathsAsNodes in class Dijkstra<CostType>
Returns:
All the found paths or null.

getPathsAsRelationships

public List<List<Relationship>> getPathsAsRelationships()
Description copied from interface: SingleSourceSingleSinkShortestPath
A call to this will run the algorithm to find all shortest paths, if not already done, and return them as lists of relationships.

Specified by:
getPathsAsRelationships in interface SingleSourceSingleSinkShortestPath<CostType>
Overrides:
getPathsAsRelationships in class Dijkstra<CostType>
Returns:
All the found paths or null.

getPredecessorNodes

public List<Node> getPredecessorNodes(Node node)
Specified by:
getPredecessorNodes in interface SingleSourceShortestPath<CostType>
Returns:
The nodes previous to the argument node in all found shortest paths or null if there are no such nodes.
See Also:
SingleSourceShortestPath

getPredecessors

public Map<Node,List<Relationship>> getPredecessors()
Description copied from interface: SingleSourceShortestPath
This can be used to retrieve the entire data structure representing the predecessors for every node.

Specified by:
getPredecessors in interface SingleSourceShortestPath<CostType>
Returns:
See Also:
SingleSourceShortestPath

getDirection

public Direction getDirection()
Description copied from interface: SingleSourceSingleSinkShortestPath
This can be used to retrieve the Direction in which relationships should be in the shortest path(s).

Specified by:
getDirection in interface SingleSourceShortestPath<CostType>
Specified by:
getDirection in interface SingleSourceSingleSinkShortestPath<CostType>
Overrides:
getDirection in class Dijkstra<CostType>
Returns:
the relationDirection
See Also:
SingleSourceShortestPath

getRelationshipTypes

public RelationshipType[] getRelationshipTypes()
Description copied from interface: SingleSourceSingleSinkShortestPath
This can be used to retrieve the types of relationships that are traversed.

Specified by:
getRelationshipTypes in interface SingleSourceShortestPath<CostType>
Specified by:
getRelationshipTypes in interface SingleSourceSingleSinkShortestPath<CostType>
Overrides:
getRelationshipTypes in class Dijkstra<CostType>
Returns:
the costRelationType
See Also:
SingleSourceShortestPath


Copyright © 2002-2012 The Neo4j Graph Database Project. All Rights Reserved.