Search in sources :

Example 26 with DirectedGraph

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

the class GraphGenerator method generateSelfLoopDirectedGraph.

public static GraphModel generateSelfLoopDirectedGraph(int n) {
    GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getGraphModel();
    DirectedGraph directedGraph = graphModel.getDirectedGraph();
    for (int i = 0; i < n; i++) {
        Node currentNode = graphModel.factory().newNode(((Integer) i).toString());
        directedGraph.addNode(currentNode);
        Edge currentEdge = graphModel.factory().newEdge(currentNode, currentNode);
        directedGraph.addEdge(currentEdge);
    }
    return graphModel;
}
Also used : DirectedGraph(org.gephi.graph.api.DirectedGraph) GraphModel(org.gephi.graph.api.GraphModel) Node(org.gephi.graph.api.Node) Edge(org.gephi.graph.api.Edge) GraphController(org.gephi.graph.api.GraphController)

Example 27 with DirectedGraph

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

the class GraphGenerator method generateCompleteDirectedGraph.

public static GraphModel generateCompleteDirectedGraph(int n) {
    GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getGraphModel();
    DirectedGraph directedGraph = graphModel.getDirectedGraph();
    Node[] nodes = new Node[n];
    for (int i = 0; i < n; i++) {
        Node currentNode = graphModel.factory().newNode(((Integer) i).toString());
        nodes[i] = currentNode;
        directedGraph.addNode(currentNode);
    }
    for (int i = 0; i < n - 1; i++) {
        for (int j = i + 1; j < n; j++) {
            Edge currentEdge = graphModel.factory().newEdge(nodes[i], nodes[j]);
            directedGraph.addEdge(currentEdge);
            currentEdge = graphModel.factory().newEdge(nodes[j], nodes[i]);
            directedGraph.addEdge(currentEdge);
        }
    }
    return graphModel;
}
Also used : DirectedGraph(org.gephi.graph.api.DirectedGraph) GraphModel(org.gephi.graph.api.GraphModel) Node(org.gephi.graph.api.Node) Edge(org.gephi.graph.api.Edge) GraphController(org.gephi.graph.api.GraphController)

Example 28 with DirectedGraph

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

the class HitsNGTest method testExampleDirectedGraph.

@Test
public void testExampleDirectedGraph() {
    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");
    directedGraph.addNode(node1);
    directedGraph.addNode(node2);
    directedGraph.addNode(node3);
    directedGraph.addNode(node4);
    Edge edge12 = graphModel.factory().newEdge(node1, node2);
    Edge edge13 = graphModel.factory().newEdge(node1, node3);
    Edge edge14 = graphModel.factory().newEdge(node1, node4);
    Edge edge23 = graphModel.factory().newEdge(node2, node3);
    Edge edge24 = graphModel.factory().newEdge(node2, node4);
    Edge edge32 = graphModel.factory().newEdge(node3, node2);
    directedGraph.addEdge(edge12);
    directedGraph.addEdge(edge13);
    directedGraph.addEdge(edge14);
    directedGraph.addEdge(edge23);
    directedGraph.addEdge(edge24);
    directedGraph.addEdge(edge32);
    DirectedGraph graph = graphModel.getDirectedGraph();
    Hits hit = new Hits();
    double[] authority = new double[4];
    double[] hubs = new double[4];
    HashMap<Node, Integer> indices = hit.createIndicesMap(graph);
    hit.calculateHits(graph, hubs, authority, indices, true, EPSILON);
    int index1 = indices.get(node1);
    int index2 = indices.get(node2);
    int index3 = indices.get(node3);
    int index4 = indices.get(node4);
    assertEquals(hubs[index1], 0.7887);
    assertEquals(hubs[index2], 0.5774);
    assertEquals(hubs[index3], 0.2113);
    assertEquals(hubs[index4], 0);
    assertEquals(authority[index1], 0);
    assertEquals(authority[index2], 0.4597);
    assertEquals(authority[index3], 0.6280);
    assertEquals(authority[index4], 0.6280);
}
Also used : DirectedGraph(org.gephi.graph.api.DirectedGraph) GraphModel(org.gephi.graph.api.GraphModel) Node(org.gephi.graph.api.Node) Edge(org.gephi.graph.api.Edge) GraphController(org.gephi.graph.api.GraphController) Test(org.testng.annotations.Test)

Example 29 with DirectedGraph

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

the class HitsNGTest method testDirectedSpecial1GraphHits.

@Test
public void testDirectedSpecial1GraphHits() {
    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 edge14 = graphModel.factory().newEdge(node1, node4);
    Edge edge15 = graphModel.factory().newEdge(node1, node5);
    Edge edge24 = graphModel.factory().newEdge(node2, node4);
    Edge edge25 = graphModel.factory().newEdge(node2, node5);
    Edge edge34 = graphModel.factory().newEdge(node3, node4);
    Edge edge35 = graphModel.factory().newEdge(node3, node5);
    directedGraph.addEdge(edge14);
    directedGraph.addEdge(edge15);
    directedGraph.addEdge(edge24);
    directedGraph.addEdge(edge25);
    directedGraph.addEdge(edge34);
    directedGraph.addEdge(edge35);
    DirectedGraph graph = graphModel.getDirectedGraph();
    Hits hit = new Hits();
    double[] authority = new double[5];
    double[] hubs = new double[5];
    HashMap<Node, Integer> indices = hit.createIndicesMap(graph);
    hit.calculateHits(graph, hubs, authority, indices, true, EPSILON);
    Node n1 = graph.getNode("0");
    Node n2 = graph.getNode("1");
    Node n4 = graph.getNode("3");
    Node n5 = graph.getNode("4");
    int index1 = indices.get(n1);
    int index2 = indices.get(n2);
    int index4 = indices.get(n4);
    int index5 = indices.get(n5);
    double hub1 = hubs[index1];
    double hub4 = hubs[index4];
    double auth2 = authority[index2];
    double auth5 = authority[index5];
    assertEquals(hub1, 0.5773);
    assertEquals(hub4, 0.0);
    assertEquals(auth2, 0.0);
    assertEquals(auth5, 0.7071);
}
Also used : DirectedGraph(org.gephi.graph.api.DirectedGraph) GraphModel(org.gephi.graph.api.GraphModel) Node(org.gephi.graph.api.Node) Edge(org.gephi.graph.api.Edge) GraphController(org.gephi.graph.api.GraphController) Test(org.testng.annotations.Test)

Example 30 with DirectedGraph

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

the class HitsNGTest method testDirectedStarOutGraphHits.

@Test
public void testDirectedStarOutGraphHits() {
    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);
    }
    DirectedGraph graph = graphModel.getDirectedGraph();
    Hits hit = new Hits();
    double[] authority = new double[6];
    double[] hubs = new double[6];
    HashMap<Node, Integer> indices = hit.createIndicesMap(graph);
    hit.calculateHits(graph, hubs, authority, indices, true, EPSILON);
    Node n1 = graph.getNode("0");
    Node n3 = graph.getNode("2");
    int index1 = indices.get(n1);
    int index3 = indices.get(n3);
    double hub1 = hubs[index1];
    double hub3 = hubs[index3];
    double auth1 = authority[index1];
    double auth3 = authority[index3];
    assertEquals(hub1, 1.0);
    assertEquals(auth1, 0.0);
    assertEquals(hub3, 0.0);
    assertEquals(auth3, 0.4472);
}
Also used : DirectedGraph(org.gephi.graph.api.DirectedGraph) GraphModel(org.gephi.graph.api.GraphModel) Node(org.gephi.graph.api.Node) Edge(org.gephi.graph.api.Edge) GraphController(org.gephi.graph.api.GraphController) Test(org.testng.annotations.Test)

Aggregations

DirectedGraph (org.gephi.graph.api.DirectedGraph)64 Node (org.gephi.graph.api.Node)60 GraphModel (org.gephi.graph.api.GraphModel)57 Test (org.testng.annotations.Test)52 Edge (org.gephi.graph.api.Edge)37 GraphController (org.gephi.graph.api.GraphController)36 HashMap (java.util.HashMap)17 LinkedList (java.util.LinkedList)6 UndirectedGraph (org.gephi.graph.api.UndirectedGraph)6 Graph (org.gephi.graph.api.Graph)2 Color (java.awt.Color)1 DecimalFormat (java.text.DecimalFormat)1 Entry (java.util.Map.Entry)1 AbstractShortestPathAlgorithm (org.gephi.algorithms.shortestpath.AbstractShortestPathAlgorithm)1 BellmanFordShortestPathAlgorithm (org.gephi.algorithms.shortestpath.BellmanFordShortestPathAlgorithm)1 DijkstraShortestPathAlgorithm (org.gephi.algorithms.shortestpath.DijkstraShortestPathAlgorithm)1 Interval (org.gephi.graph.api.Interval)1 TimeRepresentation (org.gephi.graph.api.TimeRepresentation)1 NodeClickEventListener (org.gephi.tools.spi.NodeClickEventListener)1 LinearGradient (org.gephi.ui.utils.GradientUtils.LinearGradient)1