use of org.gephi.graph.api.GraphModel in project gephi by gephi.
the class GraphDistanceNGTest method testTwoConnectedNodesAvPathLength.
@Test
public void testTwoConnectedNodesAvPathLength() {
GraphModel graphModel = GraphGenerator.generatePathUndirectedGraph(2);
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();
assertEquals(averageDegree, 1.0, TOLERANCE);
}
use of org.gephi.graph.api.GraphModel 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.GraphModel 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.GraphModel 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.GraphModel 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);
}
Aggregations