public class BetweennessCentrality
extends java.lang.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.
Modifier and Type  Class and Description 

static class 
BetweennessCentrality.PathCountOverflowException
An exception telling that the path count exceeded 64bit integer arithmetic.

Modifier and Type  Field and Description 

double[] 
betweenness
The array of betweenness value.

protected java.util.concurrent.atomic.AtomicInteger 
nextNode
The next node to be visited.

protected boolean 
stop
Whether to stop abruptly the visiting process.

Constructor and 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.

Modifier and Type  Method and Description 

void 
compute()
Computes betweenness centrality.

static void 
main(java.lang.String[] arg) 
protected final java.util.concurrent.atomic.AtomicInteger nextNode
protected volatile boolean stop
public final double[] betweenness
public BetweennessCentrality(ImmutableGraph graph, int requestedThreads, ProgressLogger pl)
graph
 a graph.requestedThreads
 the requested number of threads (0 for Runtime.availableProcessors()
).pl
 a progress logger, or null
.public BetweennessCentrality(ImmutableGraph graph, ProgressLogger pl)
graph
 a graph.pl
 a progress logger, or null
.public BetweennessCentrality(ImmutableGraph graph, int requestedThreads)
graph
 a graph.requestedThreads
 the requested number of threads (0 for Runtime.availableProcessors()
).public BetweennessCentrality(ImmutableGraph graph)
graph
 a graph.public void compute() throws java.lang.InterruptedException
betweenness
.java.lang.InterruptedException
public static void main(java.lang.String[] arg) throws java.io.IOException, java.lang.InterruptedException, JSAPException
java.io.IOException
java.lang.InterruptedException
JSAPException