use of org.gephi.graph.api.DirectedGraph in project gephi by gephi.
the class Degree method calculateAverageDegree.
protected double calculateAverageDegree(Graph graph, boolean isDirected, boolean updateAttributes) {
double averageDegree = 0;
DirectedGraph directedGraph = null;
if (isDirected) {
directedGraph = (DirectedGraph) graph;
}
Progress.start(progress, graph.getNodeCount());
for (Node n : graph.getNodes()) {
int inDegree = 0;
int outDegree = 0;
int degree = 0;
if (isDirected) {
inDegree = calculateInDegree(directedGraph, n);
outDegree = calculateOutDegree(directedGraph, n);
}
degree = calculateDegree(graph, n);
if (updateAttributes) {
n.setAttribute(DEGREE, degree);
if (isDirected) {
n.setAttribute(INDEGREE, inDegree);
n.setAttribute(OUTDEGREE, outDegree);
updateDegreeDists(inDegree, outDegree, degree);
} else {
updateDegreeDists(degree);
}
}
averageDegree += degree;
if (isCanceled) {
break;
}
Progress.progress(progress);
}
averageDegree /= (isDirected ? 2.0 : 1.0) * graph.getNodeCount();
return averageDegree;
}
use of org.gephi.graph.api.DirectedGraph in project gephi by gephi.
the class ClusteringCoefficientNGTest method testSpecial2DirectedGraphClusteringCoefficient.
@Test
public void testSpecial2DirectedGraphClusteringCoefficient() {
GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getGraphModel();
DirectedGraph directedGraph = graphModel.getDirectedGraph();
Node node1 = graphModel.factory().newNode("0");
Node node2 = graphModel.factory().newNode("1");
Node node3 = graphModel.factory().newNode("2");
Node node4 = graphModel.factory().newNode("3");
directedGraph.addNode(node1);
directedGraph.addNode(node2);
directedGraph.addNode(node3);
directedGraph.addNode(node4);
Edge edge21 = graphModel.factory().newEdge(node2, node1);
Edge edge24 = graphModel.factory().newEdge(node2, node4);
Edge edge31 = graphModel.factory().newEdge(node3, node1);
Edge edge32 = graphModel.factory().newEdge(node3, node2);
Edge edge43 = graphModel.factory().newEdge(node4, node3);
directedGraph.addEdge(edge21);
directedGraph.addEdge(edge24);
directedGraph.addEdge(edge31);
directedGraph.addEdge(edge32);
directedGraph.addEdge(edge43);
DirectedGraph graph = graphModel.getDirectedGraph();
ClusteringCoefficient cc = new ClusteringCoefficient();
ArrayWrapper[] network = new ArrayWrapper[4];
int[] triangles = new int[4];
double[] nodeClustering = new double[4];
HashMap<String, Double> results = cc.computeClusteringCoefficient(graph, network, triangles, nodeClustering, true);
double avClusteringCoefficient = results.get("clusteringCoefficient");
double res = 0.4167;
double diff = 0.01;
assertTrue(Math.abs(avClusteringCoefficient - res) < diff);
}
use of org.gephi.graph.api.DirectedGraph in project gephi by gephi.
the class GraphDistanceNGTest method testDirectedPathGraphBetweenness.
@Test
public void testDirectedPathGraphBetweenness() {
GraphModel graphModel = GraphGenerator.generatePathDirectedGraph(4);
GraphDistance d = new GraphDistance();
d.initializeStartValues();
DirectedGraph directedGraph = graphModel.getDirectedGraph();
HashMap<Node, Integer> indicies = d.createIndiciesMap(graphModel.getGraph());
HashMap<String, double[]> metricsMap = (HashMap) d.calculateDistanceMetrics(graphModel.getGraph(), indicies, true, false);
double[] betweenness = metricsMap.get(GraphDistance.BETWEENNESS);
Node n2 = directedGraph.getNode("1");
int index2 = indicies.get(n2);
assertEquals(betweenness[index2], 2.0, TOLERANCE);
}
use of org.gephi.graph.api.DirectedGraph in project gephi by gephi.
the class GraphDensityNGTest method testDirectedPathGraphDensity.
@Test
public void testDirectedPathGraphDensity() {
GraphModel graphModel = GraphGenerator.generatePathDirectedGraph(2);
DirectedGraph graph = graphModel.getDirectedGraph();
GraphDensity d = new GraphDensity();
double density = d.calculateDensity(graph, true);
assertEquals(density, 0.5);
}
use of org.gephi.graph.api.DirectedGraph in project gephi by gephi.
the class GraphDensityNGTest method testDirectedCompleteGraphDensity.
@Test
public void testDirectedCompleteGraphDensity() {
GraphModel graphModel = GraphGenerator.generateCompleteDirectedGraph(5);
DirectedGraph graph = graphModel.getDirectedGraph();
GraphDensity d = new GraphDensity();
double density = d.calculateDensity(graph, true);
assertEquals(density, 1.0);
}
Aggregations