|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.graphstream.algorithm.BetweennessCentrality
public class BetweennessCentrality
Compute the "betweenness" centrality of each vertex of a given graph.
The betweenness centrality counts how many shortest paths between each pair of nodes of the graph pass by a node. It does it for all nodes of the graph.
This algorithm, by default, stores the centrality values for each edge inside the "Cb" attribute. You can change this attribute name at construction time.
This algorithm does not accept multi-graphs (p-graphs with p>1) yet.
This algorithm does not take into account edge direction yet.
By default the
weight attribute name is "weight", you can activate the weights using
setWeighted()
. You can change the weight attribute name using the
dedicated constructor or the setWeightAttributeName(String)
method.
This method implicitly enable weights in the computation. Use
setUnweighted()
to disable weights.
The result of the computation is stored on each node inside the "Cb"
attribute. You can change the name of this attribute using the dedicated
constructor or the setCentralityAttributeName(String)
method.
As the computing of centrality can take a lot of time, you can provide a
progress 'callback' to get notified each time the algorithm finished
processing a node (however the centrality values are usable only when the
algorithm finished). See the registerProgressIndicator(Progress)
method.
By default the algorithm performs on a graph considered as not weighted with complexity O(nm). You can specify that the graph edges contain weights in which case the algorithm complexity is O(nm + n^2 log n).
Graph graph = new SingleGraph("Betweenness Test"); // E----D AB=1, BC=5, CD=3, DE=2, BE=6, EA=4 // /| | Cb(A)=4 // / | | Cb(B)=2 // A | | Cb(C)=0 // \ | | Cb(D)=2 // \| | Cb(E)=4 // B----C Node A = graph.addNode("A"); Node B = graph.addNode("B"); Node E = graph.addNode("E"); Node C = graph.addNode("C"); Node D = graph.addNode("D"); graph.addEdge("AB", "A", "B"); graph.addEdge("BE", "B", "E"); graph.addEdge("BC", "B", "C"); graph.addEdge("ED", "E", "D"); graph.addEdge("CD", "C", "D"); graph.addEdge("AE", "A", "E"); bcb.setWeight(A, B, 1); bcb.setWeight(B, E, 6); bcb.setWeight(B, C, 5); bcb.setWeight(E, D, 2); bcb.setWeight(C, D, 3); bcb.setWeight(A, E, 4); BetweennessCentrality bcb = new BetweennessCentrality(); bcb.setWeightAttributeName("weight"); bcb.init(graph); bcb.compute(); System.out.println("A="+ graph.getNode("A").getAttribute("Cb")); System.out.println("B="+ graph.getNode("B").getAttribute("Cb")); System.out.println("C="+ graph.getNode("C").getAttribute("Cb")); System.out.println("D="+ graph.getNode("D").getAttribute("Cb")); System.out.println("E="+ graph.getNode("E").getAttribute("Cb"));
This is based on the algorithm described in "A Faster Algorithm for Betweenness Centrality", Ulrik Brandes, Journal of Mathematical Sociology, 2001, and in "On variants of shortest-path betweenness centrality and their generic computation", of the same author, 2008.
Nested Class Summary | |
---|---|
static interface |
BetweennessCentrality.Progress
Interface allowing to be notified of the algorithm progress. |
Constructor Summary | |
---|---|
BetweennessCentrality()
New centrality algorithm that will perform as if the graph was unweighted. |
|
BetweennessCentrality(String centralityAttributeName)
New centrality algorithm that will perform as if the graph was unweighted. |
|
BetweennessCentrality(String centralityAttributeName,
String weightAttributeName)
New centrality algorithm that will perform on a weighted graph, taking the weight of each edge in the given weightAttributeName . |
Method Summary | |
---|---|
void |
betweennessCentrality(org.graphstream.graph.Graph graph)
Compute the betweenness centrality on the given graph for each node. |
double |
centrality(org.graphstream.graph.Node node)
The centrality value of the given node. |
void |
compute()
Compute the betweenness centrality on the given graph for each node. |
String |
getCentralityAttributeName()
Name of the attribute used to store centrality values on nodes. |
String |
getWeightAttributeName()
Name of the attribute used to retrieve weights on edges. |
void |
init(org.graphstream.graph.Graph graph)
Setup the algorithm to work on the given graph. |
void |
registerProgressIndicator(BetweennessCentrality.Progress progress)
Specify an interface to call in order to indicate the algorithm progress. |
void |
setCentrality(org.graphstream.graph.Node node,
double centrality)
Set the centrality of the given node. |
void |
setCentralityAttributeName(String centralityAttributeName)
Specify the name of the attribute used to store the computed centrality values for each node. |
void |
setUnweighted()
Consider all the edges to have the weight. |
void |
setWeight(org.graphstream.graph.Node from,
org.graphstream.graph.Node to,
double weight)
Set the weight of the edge between 'from' and 'to'. |
void |
setWeightAttributeName(String weightAttributeName)
Specify the name of the weight attribute to retrieve edge attributes. |
void |
setWeighted()
Consider the edges to have a weight. |
double |
weight(org.graphstream.graph.Node from,
org.graphstream.graph.Node to)
The weight of the edge between 'from' and 'to'. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public BetweennessCentrality()
public BetweennessCentrality(String centralityAttributeName)
centralityAttributeName
argument.
centralityAttributeName
- The name of the attribute used to store the result of the
algorithm on each node.public BetweennessCentrality(String centralityAttributeName, String weightAttributeName)
weightAttributeName
.
The result of the algorithm is stored for each node using the given
centralityAttributeName
. If an edge has no weight attribute,
it is considered as having a weight of one.
centralityAttributeName
- Name to use to store the centrality results on each node.weightAttributeName
- Name to use to retrieve the edge weights.Method Detail |
---|
public String getWeightAttributeName()
public String getCentralityAttributeName()
public void setWeightAttributeName(String weightAttributeName)
public void setWeighted()
setWeightAttributeName(String)
. If an edge has no weight the
value 1.0 is used.
public void setUnweighted()
public void setCentralityAttributeName(String centralityAttributeName)
public void registerProgressIndicator(BetweennessCentrality.Progress progress)
public void init(org.graphstream.graph.Graph graph)
init
in interface Algorithm
graph
- The graph this algorithm is using.public void compute()
compute
in interface Algorithm
Algorithm.init(Graph)
public void betweennessCentrality(org.graphstream.graph.Graph graph)
init(Graph)
then compute()
.
public double centrality(org.graphstream.graph.Node node)
node
- Extract the centrality of this node.
public void setCentrality(org.graphstream.graph.Node node, double centrality)
node
- The node to modify.centrality
- The centrality to store on the node.public void setWeight(org.graphstream.graph.Node from, org.graphstream.graph.Node to, double weight)
from
- The source node.to
- The target node.weight
- The weight to store on the edge between 'from' and 'to'.public double weight(org.graphstream.graph.Node from, org.graphstream.graph.Node to)
from
- The origin node.to
- The target node.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |