|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectde.ipk_gatersleben.ag_nw.centilib.utils.CentralityHandler
public class CentralityHandler
This class contains only static members and manages all centralities in CentiLib. You can get a list of available centralities with getCentList() or use the static fields for a specific centrality.
Use isPossible(graph, centName) to test whether a graph meets the requirements for a given centrality.
The method getParameter(centName) returns null
if no parameter value is needed for the given centrality. Otherwise it returns an instance of the abstract class CentralityParameter
.
If so, you will need to set a parameter value with setValue(value).
To compute a graph or node centrality call getGraphCentralityValue(..) or getScorer(..). See the documentation for details.
To store computed values, activate the cache function with useCache(true). Be sure to remove these values with removeFromCache(graph) if a graph changes. Otherwise you may work with unreliable values.
To compute centralities for a weighted graph, first set the edge weights with GraphCachingUtils.setEdgeWeights(graph, weights) after activating the cache. Afterwards use the CentralityHandler as you would normally do.
You may also activate a faster computation of shortest-path based centralities by calling useBrandes(true). To start the computations use startBrandes(). For example:
Collection<VertexCentrality<V,E> > cents = new HashSet<VertexCentrality<V, E> >();
CentralityHandler.useCache(true);
CentralityHandler.useBrandes(true);
if(CentratiyHandler.isPossible(graph,CentralityHandler.STRESS)
cents.add( CentralityHandler.getScorer(graph, CentralityHandler.STRESS, null, true));
if(CentralityHandler.isPossible(graph,CentralityHandler.SPBETWEENNESS))
cents.add( CentralityHandler.getScorer(graph, CentralityHandler.SPBETWEENNESS, null, true));
CentralityHandler.startBrandes();
Field Summary | |
---|---|
static String |
AVERAGEDISTANCE
|
static String |
CENTROID
|
static String |
CLOSENESS
|
static String |
CLUSTERINGCOEFFICIENT
|
static String |
CURRENTFLOWBETWEENNESS
|
static String |
CURRENTFLOWCLOSENESS
|
static String |
DEGREE
|
static String |
DIAMETER
|
static String |
ECCENTRICITY
|
static String |
EIGENVECTOR
|
static String |
HITSAUTHS
|
static String |
HITSHUBS
|
static String |
HUBBEL
|
static String |
INDEGREE
|
static String |
KATZ
|
static String |
OUTDEGREE
|
static String |
PAGERANK
|
static String |
RADIALITY
|
static String |
SPBETWEENNESS
|
static String |
STRESS
|
static String |
WIENERINDEX
|
Constructor Summary | |
---|---|
CentralityHandler()
|
Method Summary | ||
---|---|---|
static
|
getAvailableCentNames(Graph<V,E> graph)
Returns a list with the names of already computed centralities for the given graph. |
|
static Collection<String> |
getCentList()
Returns the list of all known node centralities |
|
static String |
getErrorMessage()
Returns a String with errors that occured in one of this classes methods. |
|
static Collection<String> |
getGraphCentList()
Returns the list of all known graph centralities. |
|
static
|
getGraphCentralityValue(Graph<V,E> graph,
String centName,
boolean compute)
Computes the graph centralities. |
|
static
|
getParameter(
Use the method getParameter(graph, centName) instead. |
|
static
|
getParameter(Graph<V,E> graph,
String centName)
If the given centrality needs a parameter value, this method returns an instance of the abstract class CentralityParameter . |
|
static
|
getScorer(Graph<V,E> graph,
String centName,
CentralityParameter param,
boolean createScorer)
Returns an instance of VertexCentrality for the given centrality. |
|
static
|
isPossible(Graph<V,E> graph,
String centName)
Tests whether a graph meets the requirements for the given centrality, i.e. |
|
static void |
removeFromCache(Graph<?,?> graph)
Removes the given graph and all its values from the cache. |
|
static void |
startBrandes()
If useBrandes(true) was called, this method starts the computation of all shortest-path based centralities which were invoked with getScorer(..). |
|
static void |
useBrandes(boolean use)
Compute the shortest-path based centralities in one run. |
|
static void |
useCache(boolean use)
Activate or deactivate the cache. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String CENTROID
public static final String CLOSENESS
public static final String CURRENTFLOWBETWEENNESS
public static final String CURRENTFLOWCLOSENESS
public static final String DEGREE
public static final String ECCENTRICITY
public static final String EIGENVECTOR
public static final String HITSAUTHS
public static final String HITSHUBS
public static final String HUBBEL
public static final String INDEGREE
public static final String KATZ
public static final String OUTDEGREE
public static final String PAGERANK
public static final String RADIALITY
public static final String SPBETWEENNESS
public static final String STRESS
public static final String AVERAGEDISTANCE
public static final String CLUSTERINGCOEFFICIENT
public static final String DIAMETER
public static final String WIENERINDEX
Constructor Detail |
---|
public CentralityHandler()
Method Detail |
---|
public static Collection<String> getCentList()
public static Collection<String> getGraphCentList()
public static void useBrandes(boolean use)
Compute the shortest-path based centralities in one run. Use the method getScorer(..) for all needed centralities as you would
normaly do and call startBrandes() afterwards. (see the introduction of this class for an example)
If false is given, pending computations will be started before disabling this feature. Otherwise already created instances which didn't compute their values yet, would never be able to do so.
use
- sets whether to use this feature or notpublic static void startBrandes()
public static void useCache(boolean use)
use
- sets whether to use the cache or notpublic static void removeFromCache(Graph<?,?> graph)
graph
- the graph to removepublic static <V,E> boolean isPossible(Graph<V,E> graph, String centName)
V
- Type of nodesE
- Type of edgesgraph
- the graph to testcentName
- the centrality to test the graph for
public static <V,E> CentralityParameter getParameter(centilib, Graph<V,E> graph, String centName, boolean setValue)
Use the method getParameter(graph, centName) instead.
If the given centrality needs a parameter value, this method will return an instance of the abstract class CentralityParameter. The CentiLib instance is used to ask the user for a value (only needed, if the CentiLib GUI is used). If you want to ask him later use false for 'setValue' and call the method askUserForValue() later.
V
- Type of nodesE
- Type of edgescentilib
- used to ask the user for a valuegraph
- the graph the given centrality shall be computed forcentName
- the centrality to get the parameter for, if neddedsetValue
- whether to ask the user for a value now or not
CentralityParameter
if the given centrality needs a parameter value, null otherwisepublic static <V,E> CentralityParameter getParameter(Graph<V,E> graph, String centName)
CentralityParameter
. You have to set a value with setValue(value). You can get the range
with getMinValue() and getMaxValue();
V
- Type of nodesE
- Type of edgesgraph
- the graph the given centrality shall be computed forcentName
- the centrality to get the parameter for
public static String getErrorMessage()
public static <V,E> Collection<String> getAvailableCentNames(Graph<V,E> graph)
graph
- the graph to get already computed centralities for
public static <V,E> Double getGraphCentralityValue(Graph<V,E> graph, String centName, boolean compute)
V
- Type of nodesE
- Type of edgesgraph
- the graph to compute the centralitycentName
- the centrality to computecompute
- if true: compute the centrality if it does not exist in the cache
public static <V,E> VertexCentrality<V,E> getScorer(Graph<V,E> graph, String centName, CentralityParameter param, boolean createScorer)
Returns an instance of VertexCentrality
for the given centrality. If the centrality needs a parameter
use getParameter(graph, centName). The parameter 'createScorer' determines whether to
compute the centrality, if it isn't already available in the cache.
If useBrandes(true) was called, shortest-path based centralities will be computed immediatly. Instead getScorer(.., true) will return an instance, which does not contain any values yet. You also have to start the appropriate computations by calling startBrandes(). The following example shows how to compute all centralities, which do not need a parameter, for a given graph.
CentralityHandler.useCache(true);
CentralityHandler.useBrandes(true);
Collection<VertexCentrality<V,E> > cents = new HashSet<VertexCentrality<V,E> >();
VertexCentrality<V,E> cent;
for(String centName : CentralityHandler.getCentList())
if(CentralityHandler.isPossible(graph,centName)){
cent = CentralityHandler.getScorer(graph,centName,null,true);
if(cent != null)
cents.add(cent);
}
CentralityHandler.startBrandes();
V
- Type of nodesE
- Type of edgesgraph
- The graph to compute the given centrality for.centName
- The name of the requested centrality.param
- The parameter for the given centrality, if needed, null otherwise.createScorer
- Determines whether to compute the centrality if it is not available in the cache or not.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |