org.neo4j.graphalgo.impl.shortestpath
Class SingleSourceShortestPathBFS

java.lang.Object
  extended by org.neo4j.graphalgo.impl.shortestpath.SingleSourceShortestPathBFS
All Implemented Interfaces:
SingleSourceShortestPath<Integer>

public class SingleSourceShortestPathBFS
extends Object
implements SingleSourceShortestPath<Integer>

Breadth first search to find all shortest uniform paths from a node to all others. I.e. assume the cost 1 for all relationships. This can be done by Dijkstra with the right arguments, but this should be faster.

Author:
Patrik Larsson

Field Summary
protected  long depth
           
protected  HashMap<Node,Integer> distances
           
protected  long maxDepth
           
protected  HashMap<Node,List<Relationship>> predecessors
           
protected  Direction relationShipDirection
           
protected  RelationshipType[] relationShipTypes
           
protected  Node startNode
           
 
Constructor Summary
SingleSourceShortestPathBFS(Node startNode, Direction relationShipDirection, RelationshipType... relationShipTypes)
           
 
Method Summary
 boolean calculate()
          Internal calculate method that will do the calculation.
 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.
 Integer 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(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(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(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(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(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(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 limitDepth(long maxDepth)
          This sets the maximum depth to scan.
 boolean processNextNode()
          Iterator-style "next" method.
 void reset()
          This resets the calculation if we for some reason would like to redo it.
 void setStartNode(Node node)
          This sets the start node.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

startNode

protected Node startNode

relationShipDirection

protected Direction relationShipDirection

relationShipTypes

protected RelationshipType[] relationShipTypes

distances

protected HashMap<Node,Integer> distances

predecessors

protected HashMap<Node,List<Relationship>> predecessors

maxDepth

protected long maxDepth

depth

protected long depth
Constructor Detail

SingleSourceShortestPathBFS

public SingleSourceShortestPathBFS(Node startNode,
                                   Direction relationShipDirection,
                                   RelationshipType... relationShipTypes)
Method Detail

limitDepth

public void limitDepth(long maxDepth)
This sets the maximum depth to scan.


setStartNode

public void setStartNode(Node node)
Description copied from interface: SingleSourceShortestPath
This sets the start node. The found paths will start in this node.

Specified by:
setStartNode in interface SingleSourceShortestPath<Integer>
Parameters:
node - The start node.
See Also:
SingleSourceShortestPath

reset

public void reset()
Description copied from interface: SingleSourceShortestPath
This resets the calculation if we for some reason would like to redo it.

Specified by:
reset in interface SingleSourceShortestPath<Integer>
See Also:
SingleSourceShortestPath

getCost

public Integer 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<Integer>
Returns:
The total weight of the shortest path(s).
See Also:
SingleSourceShortestPath

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<Integer>
Returns:
The path as an alternating list of Node/Relationship.
See Also:
SingleSourceShortestPath

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<Integer>
Returns:
The path as a list of nodes.
See Also:
SingleSourceShortestPath

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<Integer>
Returns:
The path as a list of Relationships.
See Also:
SingleSourceShortestPath

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<Integer>
Returns:
A list of the paths as alternating lists of Node/Relationship.
See Also:
SingleSourceShortestPath

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<Integer>
Returns:
A list of the paths as lists of nodes.
See Also:
SingleSourceShortestPath

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<Integer>
Returns:
A list of the paths as lists of relationships.
See Also:
SingleSourceShortestPath

processNextNode

public boolean processNextNode()
Iterator-style "next" method.

Returns:
True if advance was made. False if no more computation could be done.

calculate

public boolean calculate()
Internal calculate method that will do the calculation. This can however be called externally to manually trigger the calculation.


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.


getPredecessorNodes

public List<Node> getPredecessorNodes(Node node)
Specified by:
getPredecessorNodes in interface SingleSourceShortestPath<Integer>
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<Integer>
Returns:
See Also:
SingleSourceShortestPath

getDirection

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

Specified by:
getDirection in interface SingleSourceShortestPath<Integer>
Returns:
The direction.
See Also:
SingleSourceShortestPath

getRelationshipTypes

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

Specified by:
getRelationshipTypes in interface SingleSourceShortestPath<Integer>
Returns:
The relationship type(s).
See Also:
SingleSourceShortestPath


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