Class BetweennessCentrality
public class BetweennessCentrality extends Object
To use this class you first create an instance, and then invoke compute()
.
After that, you can peek at the field betweenness
to discover the betweenness of each node.
For every three distinct nodes s, t and v, let σ_{st} be the number of shortest paths from s to t, and σ_{st}(v) the number of such paths on which v lies. The betweenness centrality of node v is defined to be the sum of δ_{st}(v)=σ_{st}(v) / σ_{st} over all pairs of distinct nodes s, t different from v (the summand is assumed to be zero whenever the denominator is zero).
Brandes's approach consists in performing a breadthfirst visit from every node, recording the distance of the node from the current source. After each visit, nodes are considered in decreasing order of distance, and for each of them we consider the arcs (v,w) such that the distance of w is exactly one plus the distance of v: in this case we say that v is a parent of w. Such parents are used to compute the values of δ (exactly as in the original algorithm, but without any need to keep an explicit set of parents, which is important since this class is memory intensive).
Every visit is independent and is carried out by a separate thread. The only contention point is the update of the array accumulating the betweenness score, which is negligible. The downside is that running on k cores requires approximately k times the memory of the sequential algorithm, as only the graph and the betweenness array will be shared.
This class keeps carefully track of overflows in path counters, and will throw an exception in case they happen. Thanks to David Gleich for making me note this serious problem, which is often overlooked.

Nested Class Summary
Nested Classes Modifier and Type Class Description static class
BetweennessCentrality.PathCountOverflowException
An exception telling that the path count exceeded 64bit integer arithmetic. 
Field Summary
Fields Modifier and Type Field Description double[]
betweenness
The array of betweenness value.protected AtomicInteger
nextNode
The next node to be visited.protected boolean
stop
Whether to stop abruptly the visiting process. 
Constructor Summary
Constructors Constructor Description BetweennessCentrality(ImmutableGraph graph)
Creates a new class for computing betweenness centrality, using as many threads as the number of available processors.BetweennessCentrality(ImmutableGraph graph, int requestedThreads)
Creates a new class for computing betweenness centrality.BetweennessCentrality(ImmutableGraph graph, int requestedThreads, ProgressLogger pl)
Creates a new class for computing betweenness centrality.BetweennessCentrality(ImmutableGraph graph, ProgressLogger pl)
Creates a new class for computing betweenness centrality, using as many threads as the number of available processors. 
Method Summary

Field Details

nextNode
The next node to be visited. 
stop
protected volatile boolean stopWhether to stop abruptly the visiting process. 
betweenness
public final double[] betweennessThe array of betweenness value.


Constructor Details

BetweennessCentrality
Creates a new class for computing betweenness centrality. Parameters:
graph
 a graph.requestedThreads
 the requested number of threads (0 forRuntime.availableProcessors()
).pl
 a progress logger, ornull
.

BetweennessCentrality
Creates a new class for computing betweenness centrality, using as many threads as the number of available processors. Parameters:
graph
 a graph.pl
 a progress logger, ornull
.

BetweennessCentrality
Creates a new class for computing betweenness centrality. Parameters:
graph
 a graph.requestedThreads
 the requested number of threads (0 forRuntime.availableProcessors()
).

BetweennessCentrality
Creates a new class for computing betweenness centrality, using as many threads as the number of available processors. Parameters:
graph
 a graph.


Method Details

compute
Computes betweenness centrality. Results can be found inbetweenness
. Throws:
InterruptedException

main
