use of org.gephi.graph.api.UndirectedGraph in project gephi by gephi.
the class GraphDistanceNGTest method testCyclic5GraphHarmonicCloseness.
@Test
public void testCyclic5GraphHarmonicCloseness() {
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[] harmonic = metricsMap.get(GraphDistance.HARMONIC_CLOSENESS);
Node n3 = undirectedGraph.getNode("2");
int index3 = indicies.get(n3);
assertEquals(harmonic[index3], (1.0 + 1.0 + 1.0 / 2.0 + 1.0 / 2.0) / 4.0, TOLERANCE);
}
use of org.gephi.graph.api.UndirectedGraph in project gephi by gephi.
the class GraphDistanceNGTest method testTwoConnectedNodesCloseness.
@Test
public void testTwoConnectedNodesCloseness() {
GraphModel graphModel = GraphGenerator.generatePathUndirectedGraph(2);
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[] closeness = metricsMap.get(GraphDistance.CLOSENESS);
Node n1 = undirectedGraph.getNode("0");
int index1 = indicies.get(n1);
assertEquals(closeness[index1], 1.0, TOLERANCE);
}
use of org.gephi.graph.api.UndirectedGraph in project gephi by gephi.
the class EigenvectorCentralityNGTest method testSpecial2UndirectedGraphEigenvectorCentrlity.
@Test
public void testSpecial2UndirectedGraphEigenvectorCentrlity() {
GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getGraphModel();
UndirectedGraph undirectedGraph = graphModel.getUndirectedGraph();
Node node1 = graphModel.factory().newNode("0");
Node node2 = graphModel.factory().newNode("1");
Node node3 = graphModel.factory().newNode("2");
Node node4 = graphModel.factory().newNode("3");
Node node5 = graphModel.factory().newNode("4");
undirectedGraph.addNode(node1);
undirectedGraph.addNode(node2);
undirectedGraph.addNode(node3);
undirectedGraph.addNode(node4);
undirectedGraph.addNode(node5);
Edge edge13 = graphModel.factory().newEdge(node1, node3, false);
Edge edge23 = graphModel.factory().newEdge(node2, node3, false);
Edge edge34 = graphModel.factory().newEdge(node3, node4, false);
Edge edge45 = graphModel.factory().newEdge(node4, node5, false);
undirectedGraph.addEdge(edge13);
undirectedGraph.addEdge(edge23);
undirectedGraph.addEdge(edge34);
undirectedGraph.addEdge(edge45);
UndirectedGraph graph = graphModel.getUndirectedGraph();
EigenvectorCentrality ec = new EigenvectorCentrality();
double[] centralities = new double[5];
HashMap<Integer, Node> indicies = new HashMap();
HashMap<Node, Integer> invIndicies = new HashMap();
ec.fillIndiciesMaps(graph, centralities, indicies, invIndicies);
ec.calculateEigenvectorCentrality(graph, centralities, indicies, invIndicies, false, 100);
int index2 = invIndicies.get(node2);
int index3 = invIndicies.get(node3);
int index4 = invIndicies.get(node4);
double ec2 = centralities[index2];
double ec3 = centralities[index3];
double ec4 = centralities[index4];
double res = 0.765;
double diff = 0.01;
assertTrue(ec2 < ec3);
assertTrue(Math.abs(ec4 - res) < diff);
}
use of org.gephi.graph.api.UndirectedGraph in project gephi by gephi.
the class GraphDistanceNGTest method testOneNodeDiameter.
@Test
public void testOneNodeDiameter() {
GraphModel graphModel = GraphGenerator.generateNullUndirectedGraph(1);
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 diameter = d.getDiameter();
assertEquals(diameter, 0.0, TOLERANCE);
}
use of org.gephi.graph.api.UndirectedGraph in project gephi by gephi.
the class GraphDistanceNGTest method testTwoConnectedNodesHarmonicCloseness.
@Test
public void testTwoConnectedNodesHarmonicCloseness() {
GraphModel graphModel = GraphGenerator.generatePathUndirectedGraph(2);
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[] harmonic = metricsMap.get(GraphDistance.HARMONIC_CLOSENESS);
Node n1 = undirectedGraph.getNode("0");
int index1 = indicies.get(n1);
assertEquals(harmonic[index1], 1.0, TOLERANCE);
}
Aggregations