Search in sources :

Example 6 with UndirectedGraph

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

the class EigenvectorCentralityNGTest method testCompleteUndirectedGraphEigenvectorCentrality.

@Test
public void testCompleteUndirectedGraphEigenvectorCentrality() {
    GraphModel graphModel = GraphGenerator.generateCompleteUndirectedGraph(5);
    UndirectedGraph graph = graphModel.getUndirectedGraph();
    EigenvectorCentrality ec = new EigenvectorCentrality();
    ec.setDirected(false);
    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);
    Node n1 = graph.getNode("0");
    Node n3 = graph.getNode("2");
    int index1 = invIndicies.get(n1);
    int index3 = invIndicies.get(n3);
    double ec1 = centralities[index1];
    double ec3 = centralities[index3];
    assertEquals(ec1, 1.0);
    assertEquals(ec3, 1.0);
}
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 7 with UndirectedGraph

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

the class EigenvectorCentralityNGTest method testSpecial1UndirectedGraphEigenvectorCentrlity.

@Test
public void testSpecial1UndirectedGraphEigenvectorCentrlity() {
    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");
    undirectedGraph.addNode(node1);
    undirectedGraph.addNode(node2);
    undirectedGraph.addNode(node3);
    undirectedGraph.addNode(node4);
    Edge edge12 = graphModel.factory().newEdge(node1, node2, false);
    Edge edge23 = graphModel.factory().newEdge(node2, node3, false);
    Edge edge34 = graphModel.factory().newEdge(node3, node4, false);
    Edge edge13 = graphModel.factory().newEdge(node1, node3, false);
    Edge edge24 = graphModel.factory().newEdge(node2, node4, false);
    undirectedGraph.addEdge(edge12);
    undirectedGraph.addEdge(edge23);
    undirectedGraph.addEdge(edge34);
    undirectedGraph.addEdge(edge13);
    undirectedGraph.addEdge(edge24);
    UndirectedGraph graph = graphModel.getUndirectedGraph();
    EigenvectorCentrality ec = new EigenvectorCentrality();
    double[] centralities = new double[4];
    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 index1 = invIndicies.get(node1);
    int index2 = invIndicies.get(node2);
    int index3 = invIndicies.get(node3);
    double ec1 = centralities[index1];
    double ec2 = centralities[index2];
    double ec3 = centralities[index3];
    assertEquals(ec2, ec3);
    assertNotEquals(ec1, ec2);
    assertEquals(ec3, 1.0);
}
Also used : HashMap(java.util.HashMap) Node(org.gephi.graph.api.Node) GraphModel(org.gephi.graph.api.GraphModel) UndirectedGraph(org.gephi.graph.api.UndirectedGraph) Edge(org.gephi.graph.api.Edge) GraphController(org.gephi.graph.api.GraphController) Test(org.testng.annotations.Test)

Example 8 with UndirectedGraph

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

the class ConnectedComponents method execute.

@Override
public void execute(GraphModel graphModel) {
    isDirected = graphModel.isDirected();
    isCanceled = false;
    UndirectedGraph undirectedGraph = graphModel.getUndirectedGraphVisible();
    undirectedGraph.readLock();
    try {
        weaklyConnected(undirectedGraph);
        if (isDirected) {
            DirectedGraph directedGraph = graphModel.getDirectedGraphVisible();
            stronglyConnected(directedGraph, graphModel);
        }
    } finally {
        undirectedGraph.readUnlock();
    }
}
Also used : DirectedGraph(org.gephi.graph.api.DirectedGraph) UndirectedGraph(org.gephi.graph.api.UndirectedGraph)

Example 9 with UndirectedGraph

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

the class ConnectedComponentsNGTest method testSpecial1UndirectedGraphConnectedComponents.

@Test
public void testSpecial1UndirectedGraphConnectedComponents() {
    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 edge12 = graphModel.factory().newEdge(node1, node2, false);
    Edge edge14 = graphModel.factory().newEdge(node1, node4, false);
    Edge edge23 = graphModel.factory().newEdge(node2, node3, false);
    Edge edge25 = graphModel.factory().newEdge(node2, node5, false);
    Edge edge35 = graphModel.factory().newEdge(node3, node5, false);
    Edge edge43 = graphModel.factory().newEdge(node4, node3, false);
    Edge edge51 = graphModel.factory().newEdge(node5, node1, false);
    Edge edge54 = graphModel.factory().newEdge(node5, node4, false);
    undirectedGraph.addEdge(edge12);
    undirectedGraph.addEdge(edge14);
    undirectedGraph.addEdge(edge23);
    undirectedGraph.addEdge(edge25);
    undirectedGraph.addEdge(edge35);
    undirectedGraph.addEdge(edge43);
    undirectedGraph.addEdge(edge51);
    undirectedGraph.addEdge(edge54);
    UndirectedGraph graph = graphModel.getUndirectedGraph();
    ConnectedComponents c = new ConnectedComponents();
    HashMap<Node, Integer> indicies = c.createIndiciesMap(graph);
    LinkedList<LinkedList<Node>> components = c.computeWeeklyConnectedComponents(graph, indicies);
    assertEquals(components.size(), 1);
}
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) LinkedList(java.util.LinkedList) Test(org.testng.annotations.Test)

Example 10 with UndirectedGraph

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

the class ConnectedComponentsNGTest method testNullGraphWeeklyConnectedComponents.

@Test
public void testNullGraphWeeklyConnectedComponents() {
    GraphModel graphModel = GraphGenerator.generateNullUndirectedGraph(5);
    UndirectedGraph graph = graphModel.getUndirectedGraph();
    Node n0 = graph.getNode("0");
    Node n1 = graph.getNode("1");
    Node n2 = graph.getNode("2");
    Node n3 = graph.getNode("3");
    Node n4 = graph.getNode("4");
    ConnectedComponents c = new ConnectedComponents();
    HashMap<Node, Integer> indicies = new HashMap<>();
    indicies.put(n0, 0);
    indicies.put(n1, 1);
    indicies.put(n2, 2);
    indicies.put(n3, 3);
    indicies.put(n4, 4);
    LinkedList<LinkedList<Node>> components = c.computeWeeklyConnectedComponents(graph, indicies);
    assertEquals(components.size(), 5);
}
Also used : HashMap(java.util.HashMap) GraphModel(org.gephi.graph.api.GraphModel) UndirectedGraph(org.gephi.graph.api.UndirectedGraph) Node(org.gephi.graph.api.Node) LinkedList(java.util.LinkedList) 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