use of org.gephi.graph.api.Graph in project gephi by gephi.
the class DynamicClusteringCoefficient method loop.
@Override
public void loop(GraphView window, Interval interval) {
Graph graph;
if (isDirected) {
graph = graphModel.getDirectedGraph(window);
} else {
graph = graphModel.getUndirectedGraph(window);
}
TimeRepresentation tr = graphModel.getConfiguration().getTimeRepresentation();
graph.readLock();
try {
clusteringCoefficientStat = new ClusteringCoefficient();
clusteringCoefficientStat.setDirected(isDirected);
clusteringCoefficientStat.triangles(graph);
//Columns
if (!averageOnly) {
double[] coefficients = clusteringCoefficientStat.getCoefficientReuslts();
int i = 0;
for (Node n : graph.getNodes()) {
double coef = coefficients[i++];
switch(tr) {
case INTERVAL:
n.setAttribute(dynamicCoefficientColumn, coef, new Interval(interval.getLow(), interval.getLow() + tick));
break;
case TIMESTAMP:
n.setAttribute(dynamicCoefficientColumn, coef, interval.getLow());
n.setAttribute(dynamicCoefficientColumn, coef, interval.getHigh());
break;
}
if (cancel) {
break;
}
}
}
} finally {
graph.readUnlockAll();
}
//Average
double avg = clusteringCoefficientStat.getAverageClusteringCoefficient();
graphModel.getGraphVisible().setAttribute(DYNAMIC_AVG_CLUSTERING_COEFFICIENT, avg, interval.getLow());
graphModel.getGraphVisible().setAttribute(DYNAMIC_AVG_CLUSTERING_COEFFICIENT, avg, interval.getHigh());
averages.put(interval.getLow(), avg);
averages.put(interval.getHigh(), avg);
}
use of org.gephi.graph.api.Graph in project gephi by gephi.
the class DynamicDegree method loop.
@Override
public void loop(GraphView window, Interval interval) {
Graph graph = graphModel.getGraph(window);
DirectedGraph directedGraph = null;
if (isDirected) {
directedGraph = graphModel.getDirectedGraph(window);
}
TimeRepresentation tr = graphModel.getConfiguration().getTimeRepresentation();
long sum = 0;
for (Node n : graph.getNodes().toArray()) {
int degree = graph.getDegree(n);
if (!averageOnly) {
switch(tr) {
case INTERVAL:
n.setAttribute(dynamicDegreeColumn, degree, new Interval(interval.getLow(), interval.getLow() + tick));
break;
case TIMESTAMP:
n.setAttribute(dynamicDegreeColumn, degree, interval.getLow());
n.setAttribute(dynamicDegreeColumn, degree, interval.getHigh());
break;
}
if (isDirected) {
int indegree = directedGraph.getInDegree(n);
int outdegree = directedGraph.getOutDegree(n);
switch(tr) {
case INTERVAL:
n.setAttribute(dynamicInDegreeColumn, indegree, new Interval(interval.getLow(), interval.getLow() + tick));
n.setAttribute(dynamicOutDegreeColumn, outdegree, new Interval(interval.getLow(), interval.getLow() + tick));
break;
case TIMESTAMP:
n.setAttribute(dynamicInDegreeColumn, indegree, interval.getLow());
n.setAttribute(dynamicInDegreeColumn, indegree, interval.getHigh());
n.setAttribute(dynamicOutDegreeColumn, outdegree, interval.getLow());
n.setAttribute(dynamicOutDegreeColumn, outdegree, interval.getHigh());
break;
}
}
}
sum += degree;
if (cancel) {
break;
}
}
double avg = sum / (double) graph.getNodeCount();
averages.put(interval.getLow(), avg);
averages.put(interval.getHigh(), avg);
graphModel.getGraphVisible().setAttribute(DYNAMIC_AVGDEGREE, avg, interval.getLow());
graphModel.getGraphVisible().setAttribute(DYNAMIC_AVGDEGREE, avg, interval.getHigh());
}
use of org.gephi.graph.api.Graph in project gephi by gephi.
the class DynamicNbNodes method loop.
@Override
public void loop(GraphView window, Interval interval) {
Graph graph = graphModel.getGraph(window);
int count = graph.getNodeCount();
graphModel.getGraphVisible().setAttribute(NB_NODES, count, interval.getLow());
graphModel.getGraphVisible().setAttribute(NB_NODES, count, interval.getHigh());
counts.put(interval.getLow(), count);
counts.put(interval.getHigh(), count);
}
use of org.gephi.graph.api.Graph in project gephi by gephi.
the class ClusteringCoefficientNGTest method testOneNodeClusteringCoefficient.
@Test
public void testOneNodeClusteringCoefficient() {
GraphModel graphModel = GraphGenerator.generateCompleteUndirectedGraph(1);
Graph graph = graphModel.getGraph();
ClusteringCoefficient cc = new ClusteringCoefficient();
cc.setDirected(false);
ArrayWrapper[] network = new ArrayWrapper[1];
int[] triangles = new int[1];
double[] nodeClustering = new double[1];
HashMap<String, Double> results = cc.computeClusteringCoefficient(graph, network, triangles, nodeClustering, false);
double avClusteringCoefficient = results.get("clusteringCoefficient");
assertEquals(avClusteringCoefficient, Double.NaN);
}
use of org.gephi.graph.api.Graph in project gephi by gephi.
the class ClusteringCoefficientNGTest method testTwoConectedNodesClusteringCoefficient.
@Test
public void testTwoConectedNodesClusteringCoefficient() {
GraphModel graphModel = GraphGenerator.generateCompleteUndirectedGraph(2);
Graph graph = graphModel.getGraph();
ClusteringCoefficient cc = new ClusteringCoefficient();
ArrayWrapper[] network = new ArrayWrapper[2];
int[] triangles = new int[2];
double[] nodeClustering = new double[2];
HashMap<String, Double> results = cc.computeClusteringCoefficient(graph, network, triangles, nodeClustering, false);
double avClusteringCoefficient = results.get("clusteringCoefficient");
assertEquals(avClusteringCoefficient, Double.NaN);
}
Aggregations