Search in sources :

Example 61 with UndirectedGraph

use of org.gephi.graph.api.UndirectedGraph in project gephi by gephi.

the class GraphDistanceNGTest method testCompleteGraphBetweenness.

@Test
public void testCompleteGraphBetweenness() {
    GraphModel graphModel = GraphGenerator.generateCompleteUndirectedGraph(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);
}
Also used : HashMap(java.util.HashMap) GraphModel(org.gephi.graph.api.GraphModel) UndirectedGraph(org.gephi.graph.api.UndirectedGraph) Node(org.gephi.graph.api.Node) Test(org.testng.annotations.Test)

Example 62 with UndirectedGraph

use of org.gephi.graph.api.UndirectedGraph in project gephi by gephi.

the class GraphDistanceNGTest method testDirectedSpecial1GraphAvPathLength.

@Test
public void testDirectedSpecial1GraphAvPathLength() {
    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");
    Node node5 = graphModel.factory().newNode("4");
    directedGraph.addNode(node1);
    directedGraph.addNode(node2);
    directedGraph.addNode(node3);
    directedGraph.addNode(node4);
    directedGraph.addNode(node5);
    Edge edge15 = graphModel.factory().newEdge(node1, node5);
    Edge edge52 = graphModel.factory().newEdge(node5, node2);
    Edge edge53 = graphModel.factory().newEdge(node5, node3);
    Edge edge45 = graphModel.factory().newEdge(node4, node5);
    directedGraph.addEdge(edge15);
    directedGraph.addEdge(edge52);
    directedGraph.addEdge(edge53);
    directedGraph.addEdge(edge45);
    GraphDistance d = new GraphDistance();
    d.initializeStartValues();
    UndirectedGraph undirectedGraph = graphModel.getUndirectedGraph();
    HashMap<Node, Integer> indicies = d.createIndiciesMap(undirectedGraph);
    d.calculateDistanceMetrics(graphModel.getGraph(), indicies, true, false);
    double averageDegree = d.getPathLength();
    assertEquals(averageDegree, 1.5, TOLERANCE);
}
Also used : DirectedGraph(org.gephi.graph.api.DirectedGraph) GraphModel(org.gephi.graph.api.GraphModel) Node(org.gephi.graph.api.Node) UndirectedGraph(org.gephi.graph.api.UndirectedGraph) Edge(org.gephi.graph.api.Edge) GraphController(org.gephi.graph.api.GraphController) Test(org.testng.annotations.Test)

Example 63 with UndirectedGraph

use of org.gephi.graph.api.UndirectedGraph in project gephi by gephi.

the class GraphDistanceNGTest method testStarGraphHarmonicCloseness.

@Test
public void testStarGraphHarmonicCloseness() {
    GraphModel graphModel = GraphGenerator.generateStarUndirectedGraph(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 n1 = undirectedGraph.getNode("0");
    Node n2 = undirectedGraph.getNode("1");
    int index1 = indicies.get(n1);
    int index2 = indicies.get(n2);
    assertEquals(harmonic[index1], 5.0 / 5.0, TOLERANCE);
    assertEquals(harmonic[index2], (1.0 + 4 * 0.5) / 5.0, TOLERANCE);
}
Also used : HashMap(java.util.HashMap) GraphModel(org.gephi.graph.api.GraphModel) UndirectedGraph(org.gephi.graph.api.UndirectedGraph) Node(org.gephi.graph.api.Node) Test(org.testng.annotations.Test)

Example 64 with UndirectedGraph

use of org.gephi.graph.api.UndirectedGraph in project gephi by gephi.

the class GraphDistanceNGTest method testDirectedStarOutGraphAvPathLength.

@Test
public void testDirectedStarOutGraphAvPathLength() {
    GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getGraphModel();
    DirectedGraph directedGraph = graphModel.getDirectedGraph();
    Node firstNode = graphModel.factory().newNode("0");
    directedGraph.addNode(firstNode);
    for (int i = 1; i <= 5; i++) {
        Node currentNode = graphModel.factory().newNode(((Integer) i).toString());
        directedGraph.addNode(currentNode);
        Edge currentEdge = graphModel.factory().newEdge(firstNode, currentNode);
        directedGraph.addEdge(currentEdge);
    }
    GraphDistance d = new GraphDistance();
    d.initializeStartValues();
    UndirectedGraph undirectedGraph = graphModel.getUndirectedGraph();
    HashMap<Node, Integer> indicies = d.createIndiciesMap(undirectedGraph);
    d.calculateDistanceMetrics(graphModel.getGraph(), indicies, true, false);
    double averageDegree = d.getPathLength();
    assertEquals(averageDegree, 1.0, TOLERANCE);
}
Also used : DirectedGraph(org.gephi.graph.api.DirectedGraph) GraphModel(org.gephi.graph.api.GraphModel) Node(org.gephi.graph.api.Node) UndirectedGraph(org.gephi.graph.api.UndirectedGraph) Edge(org.gephi.graph.api.Edge) GraphController(org.gephi.graph.api.GraphController) Test(org.testng.annotations.Test)

Example 65 with UndirectedGraph

use of org.gephi.graph.api.UndirectedGraph in project gephi by gephi.

the class GraphDistanceNGTest method testStarGraphCloseness.

@Test
public void testStarGraphCloseness() {
    GraphModel graphModel = GraphGenerator.generateStarUndirectedGraph(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[] closeness = metricsMap.get(GraphDistance.CLOSENESS);
    Node n1 = undirectedGraph.getNode("0");
    Node n2 = undirectedGraph.getNode("1");
    int index1 = indicies.get(n1);
    int index2 = indicies.get(n2);
    assertEquals(closeness[index1], 1.0, TOLERANCE);
    assertEquals(closeness[index2], 1.0 / 1.8, TOLERANCE);
}
Also used : HashMap(java.util.HashMap) GraphModel(org.gephi.graph.api.GraphModel) UndirectedGraph(org.gephi.graph.api.UndirectedGraph) Node(org.gephi.graph.api.Node) Test(org.testng.annotations.Test)

Aggregations

UndirectedGraph (org.gephi.graph.api.UndirectedGraph)100 GraphModel (org.gephi.graph.api.GraphModel)99 Node (org.gephi.graph.api.Node)97 Test (org.testng.annotations.Test)93 Edge (org.gephi.graph.api.Edge)44 GraphController (org.gephi.graph.api.GraphController)39 HashMap (java.util.HashMap)36 DirectedGraph (org.gephi.graph.api.DirectedGraph)13 Graph (org.gephi.graph.api.Graph)7 LinkedList (java.util.LinkedList)6