org.neo4j.graphalgo.impl.centrality
Class ShortestPathBasedCentrality<CentralityType,ShortestPathCostType>

java.lang.Object
  extended by org.neo4j.graphalgo.impl.centrality.ShortestPathBasedCentrality<CentralityType,ShortestPathCostType>
Type Parameters:
CentralityType - The result datatype. Values of this is stored for every node and accumulated during calculation.
ShortestPathCostType - The datatype used by the SingleSourceShortestPath to represent path weights.
Direct Known Subclasses:
BetweennessCentrality, ClosenessCentrality, Eccentricity, NetworkDiameter, NetworkRadius, StressCentrality

public abstract class ShortestPathBasedCentrality<CentralityType,ShortestPathCostType>
extends Object

This serves as a base class for all centrality algorithms based on shortest paths. All these algorithms make use of the SingleSourceShortestPath object to calculate the shortest paths which can be adapted for the kind of graph to run the calculation on and set up with proper calculation limits. The main purpose of this class, except containing everything common to these algorithms, is to open up for parallel computation of several of these algorithms at the same time. This could be made possible by reusing the SingleSourceShortestPath computation made for every node.

Author:
Patrik Larsson

Field Summary
protected  Map<Node,CentralityType> centralities
          This map over centrality values is made available to the algorithms inheriting this class.
protected  CostAccumulator<CentralityType> centralityAccumulator
           
protected  boolean doneCalculation
           
protected  Set<Node> nodeSet
           
protected  SingleSourceShortestPath<ShortestPathCostType> singleSourceShortestPath
           
protected  CentralityType zeroValue
           
 
Constructor Summary
ShortestPathBasedCentrality(SingleSourceShortestPath<ShortestPathCostType> singleSourceShortestPath, CostAccumulator<CentralityType> centralityAccumulator, CentralityType zeroValue, Set<Node> nodeSet)
          Default constructor.
 
Method Summary
protected  void addCentralityToNode(Node node, CentralityType value)
          This adds a value to a given node in the centralities Map.
 void calculate()
          Runs the calculation.
 CentralityType getCentrality(Node node)
          This can be used to retrieve the result for every node.
abstract  void processShortestPaths(Node node, SingleSourceShortestPath<ShortestPathCostType> singleSourceShortestPath)
          This is the abstract method all centrality algorithms based on this class need to implement.
 void reset()
          The calculation is normally only done once, this resets it so it can be run again.
protected  void setCentralityForNode(Node node, CentralityType value)
          This sets a value for a given node in the centralities Map.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

singleSourceShortestPath

protected SingleSourceShortestPath<ShortestPathCostType> singleSourceShortestPath

centralityAccumulator

protected CostAccumulator<CentralityType> centralityAccumulator

zeroValue

protected CentralityType zeroValue

nodeSet

protected Set<Node> nodeSet

doneCalculation

protected boolean doneCalculation

centralities

protected Map<Node,CentralityType> centralities
This map over centrality values is made available to the algorithms inheriting this class. It is supposed to be filled with the method addCentralityToNode.

Constructor Detail

ShortestPathBasedCentrality

public ShortestPathBasedCentrality(SingleSourceShortestPath<ShortestPathCostType> singleSourceShortestPath,
                                   CostAccumulator<CentralityType> centralityAccumulator,
                                   CentralityType zeroValue,
                                   Set<Node> nodeSet)
Default constructor.

Parameters:
singleSourceShortestPath - The underlying shortest path algorithm.
centralityAccumulator - When centralities are built through sums, this makes it possible to call addCentralityToNode several times, which then uses this object to add values together.
zeroValue - The default value to start with.
nodeSet - The set of nodes values should be stored for.
Method Detail

reset

public void reset()
The calculation is normally only done once, this resets it so it can be run again. Also used locally for initialization.


addCentralityToNode

protected void addCentralityToNode(Node node,
                                   CentralityType value)
This adds a value to a given node in the centralities Map. If the Map does not contain the node, it is added.

Parameters:
node -
value -

setCentralityForNode

protected void setCentralityForNode(Node node,
                                    CentralityType value)
This sets a value for a given node in the centralities Map. If the Map does not contain the node, it is added.

Parameters:
node -
value -

getCentrality

public CentralityType getCentrality(Node node)
This can be used to retrieve the result for every node. Will return null if the node is not contained in the node set initially given.

Parameters:
node -
Returns:

calculate

public void calculate()
Runs the calculation. This should not need to be called explicitly, since all attempts to retrieve any kind of result should automatically call this.


processShortestPaths

public abstract void processShortestPaths(Node node,
                                          SingleSourceShortestPath<ShortestPathCostType> singleSourceShortestPath)
This is the abstract method all centrality algorithms based on this class need to implement. It is called once for every node in the node set, along with a SingleSourceShortestPath starting in that node.

Parameters:
node -
singleSourceShortestPath -


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