use of org.gephi.graph.api.UndirectedGraph in project gephi by gephi.
the class GraphDistanceNGTest method testCyclic5GraphBetweenness.
@Test
public void testCyclic5GraphBetweenness() {
GraphModel graphModel = GraphGenerator.generateCyclicUndirectedGraph(5);
GraphDistance d = new GraphDistance();
d.initializeStartValues();
UndirectedGraph undirectedGraph = graphModel.getUndirectedGraph();
HashMap<Node, Integer> indicies = d.createIndiciesMap(undirectedGraph);
HashMap<String, double[]> metricsMap = (HashMap) d.calculateDistanceMetrics(graphModel.getGraph(), indicies, false, false);
double[] betweenness = metricsMap.get(GraphDistance.BETWEENNESS);
Node n4 = undirectedGraph.getNode("3");
int index4 = indicies.get(n4);
assertEquals(betweenness[index4], 1.0, TOLERANCE);
}
use of org.gephi.graph.api.UndirectedGraph in project gephi by gephi.
the class GraphDistanceNGTest method testCompleteGraphRadius.
@Test
public void testCompleteGraphRadius() {
GraphModel graphModel = GraphGenerator.generateCompleteUndirectedGraph(5);
GraphDistance d = new GraphDistance();
d.initializeStartValues();
UndirectedGraph undirectedGraph = graphModel.getUndirectedGraph();
HashMap<Node, Integer> indicies = d.createIndiciesMap(undirectedGraph);
d.calculateDistanceMetrics(graphModel.getGraph(), indicies, false, false);
double radius = d.getRadius();
assertEquals(radius, 1.0, TOLERANCE);
}
use of org.gephi.graph.api.UndirectedGraph in project gephi by gephi.
the class GraphDistanceNGTest method testNullGraphBetweenness.
@Test
public void testNullGraphBetweenness() {
GraphModel graphModel = GraphGenerator.generateNullUndirectedGraph(5);
GraphDistance d = new GraphDistance();
d.initializeStartValues();
UndirectedGraph undirectedGraph = graphModel.getUndirectedGraph();
HashMap<Node, Integer> indicies = d.createIndiciesMap(undirectedGraph);
HashMap<String, double[]> metricsMap = (HashMap) d.calculateDistanceMetrics(graphModel.getGraph(), indicies, false, false);
double[] betweenness = metricsMap.get(GraphDistance.BETWEENNESS);
Node n1 = undirectedGraph.getNode("0");
int index1 = indicies.get(n1);
assertEquals(betweenness[index1], 0.0, TOLERANCE);
}
use of org.gephi.graph.api.UndirectedGraph in project gephi by gephi.
the class GraphDistanceNGTest method testStarGraphAvPathLength.
@Test
public void testStarGraphAvPathLength() {
GraphModel graphModel = GraphGenerator.generateStarUndirectedGraph(5);
GraphDistance d = new GraphDistance();
d.initializeStartValues();
UndirectedGraph undirectedGraph = graphModel.getUndirectedGraph();
HashMap<Node, Integer> indicies = d.createIndiciesMap(undirectedGraph);
d.calculateDistanceMetrics(graphModel.getGraph(), indicies, false, false);
double averageDegree = d.getPathLength();
double res = 1.6667;
double diff = Math.abs(averageDegree - res);
assertEquals(averageDegree, res, TOLERANCE);
}
use of org.gephi.graph.api.UndirectedGraph in project gephi by gephi.
the class GraphDensityNGTest method testSelfLoopNodeDensity.
@Test
public void testSelfLoopNodeDensity() {
GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getGraphModel();
UndirectedGraph undirectedGraph = graphModel.getUndirectedGraph();
Node currentNode = graphModel.factory().newNode("0");
undirectedGraph.addNode(currentNode);
Edge currentEdge = graphModel.factory().newEdge(currentNode, currentNode, false);
undirectedGraph.addEdge(currentEdge);
Graph graph = graphModel.getGraph();
GraphDensity d = new GraphDensity();
double density = d.calculateDensity(graph, false);
assertEquals(density, Double.POSITIVE_INFINITY);
}
Aggregations