Search in sources :

Example 46 with UndirectedGraph

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

the class GraphDistanceNGTest method testSpecial2DirectedGraphDiameter.

@Test
public void testSpecial2DirectedGraphDiameter() {
    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 edge12 = graphModel.factory().newEdge(node1, node2);
    Edge edge14 = graphModel.factory().newEdge(node1, node4);
    Edge edge23 = graphModel.factory().newEdge(node2, node3);
    Edge edge25 = graphModel.factory().newEdge(node2, node5);
    Edge edge35 = graphModel.factory().newEdge(node3, node5);
    Edge edge43 = graphModel.factory().newEdge(node4, node3);
    Edge edge51 = graphModel.factory().newEdge(node5, node1);
    Edge edge54 = graphModel.factory().newEdge(node5, node4);
    directedGraph.addEdge(edge12);
    directedGraph.addEdge(edge14);
    directedGraph.addEdge(edge23);
    directedGraph.addEdge(edge25);
    directedGraph.addEdge(edge35);
    directedGraph.addEdge(edge43);
    directedGraph.addEdge(edge51);
    directedGraph.addEdge(edge54);
    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 diameter = d.getDiameter();
    assertEquals(diameter, 4.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 47 with UndirectedGraph

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

the class GraphDistanceNGTest method testSpecial2DirectedGraphRadius.

@Test
public void testSpecial2DirectedGraphRadius() {
    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 edge12 = graphModel.factory().newEdge(node1, node2);
    Edge edge14 = graphModel.factory().newEdge(node1, node4);
    Edge edge23 = graphModel.factory().newEdge(node2, node3);
    Edge edge25 = graphModel.factory().newEdge(node2, node5);
    Edge edge35 = graphModel.factory().newEdge(node3, node5);
    Edge edge43 = graphModel.factory().newEdge(node4, node3);
    Edge edge51 = graphModel.factory().newEdge(node5, node1);
    Edge edge54 = graphModel.factory().newEdge(node5, node4);
    directedGraph.addEdge(edge12);
    directedGraph.addEdge(edge14);
    directedGraph.addEdge(edge23);
    directedGraph.addEdge(edge25);
    directedGraph.addEdge(edge35);
    directedGraph.addEdge(edge43);
    directedGraph.addEdge(edge51);
    directedGraph.addEdge(edge54);
    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 radius = d.getRadius();
    assertEquals(radius, 2.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 48 with UndirectedGraph

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

the class GraphDistanceNGTest method testNullGraphDiameter.

@Test
public void testNullGraphDiameter() {
    GraphModel graphModel = GraphGenerator.generateNullUndirectedGraph(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 diameter = d.getDiameter();
    assertEquals(diameter, 0.0, TOLERANCE);
}
Also used : GraphModel(org.gephi.graph.api.GraphModel) UndirectedGraph(org.gephi.graph.api.UndirectedGraph) Node(org.gephi.graph.api.Node) Test(org.testng.annotations.Test)

Example 49 with UndirectedGraph

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

the class GraphDistanceNGTest method testCyclicGraphAvPathLength.

@Test
public void testCyclicGraphAvPathLength() {
    GraphModel graphModel = GraphGenerator.generateCyclicUndirectedGraph(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();
    assertEquals(averageDegree, 1.5, TOLERANCE);
}
Also used : GraphModel(org.gephi.graph.api.GraphModel) UndirectedGraph(org.gephi.graph.api.UndirectedGraph) Node(org.gephi.graph.api.Node) Test(org.testng.annotations.Test)

Example 50 with UndirectedGraph

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

the class GraphGenerator method generatePathUndirectedGraph.

public static GraphModel generatePathUndirectedGraph(int n) {
    GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getGraphModel();
    UndirectedGraph undirectedGraph = graphModel.getUndirectedGraph();
    if (n <= 0) {
        return graphModel;
    }
    Node firstNode = graphModel.factory().newNode("0");
    undirectedGraph.addNode(firstNode);
    Node prevNode = firstNode;
    for (int i = 1; i < n; i++) {
        Node currentNode = graphModel.factory().newNode(((Integer) i).toString());
        undirectedGraph.addNode(currentNode);
        Edge currentEdge = graphModel.factory().newEdge(prevNode, currentNode, false);
        undirectedGraph.addEdge(currentEdge);
        prevNode = currentNode;
    }
    return graphModel;
}
Also used : GraphModel(org.gephi.graph.api.GraphModel) UndirectedGraph(org.gephi.graph.api.UndirectedGraph) Node(org.gephi.graph.api.Node) Edge(org.gephi.graph.api.Edge) GraphController(org.gephi.graph.api.GraphController)

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