Search in sources :

Example 41 with DirectedGraph

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

the class GraphGenerator method generateNullDirectedGraph.

public static GraphModel generateNullDirectedGraph(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);
    }
    return graphModel;
}
Also used : DirectedGraph(org.gephi.graph.api.DirectedGraph) GraphModel(org.gephi.graph.api.GraphModel) Node(org.gephi.graph.api.Node) GraphController(org.gephi.graph.api.GraphController)

Example 42 with DirectedGraph

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

the class GraphGenerator method generatePathDirectedGraph.

public static GraphModel generatePathDirectedGraph(int n) {
    GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getGraphModel();
    DirectedGraph directedGraph = graphModel.getDirectedGraph();
    if (n <= 0) {
        return graphModel;
    }
    Node firstNode = graphModel.factory().newNode("0");
    directedGraph.addNode(firstNode);
    Node prevNode = firstNode;
    for (int i = 1; i < n; i++) {
        Node currentNode = graphModel.factory().newNode(((Integer) i).toString());
        directedGraph.addNode(currentNode);
        Edge currentEdge = graphModel.factory().newEdge(prevNode, currentNode);
        directedGraph.addEdge(currentEdge);
        prevNode = currentNode;
    }
    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 43 with DirectedGraph

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

the class HitsNGTest method testDirectedSpecial2GraphHits.

@Test
public void testDirectedSpecial2GraphHits() {
    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");
    Node node6 = graphModel.factory().newNode("5");
    directedGraph.addNode(node1);
    directedGraph.addNode(node2);
    directedGraph.addNode(node3);
    directedGraph.addNode(node4);
    directedGraph.addNode(node5);
    directedGraph.addNode(node6);
    Edge edge21 = graphModel.factory().newEdge(node2, node1);
    Edge edge31 = graphModel.factory().newEdge(node3, node1);
    Edge edge41 = graphModel.factory().newEdge(node4, node1);
    Edge edge51 = graphModel.factory().newEdge(node5, node1);
    Edge edge36 = graphModel.factory().newEdge(node3, node6);
    Edge edge46 = graphModel.factory().newEdge(node4, node6);
    Edge edge56 = graphModel.factory().newEdge(node5, node6);
    directedGraph.addEdge(edge21);
    directedGraph.addEdge(edge31);
    directedGraph.addEdge(edge41);
    directedGraph.addEdge(edge51);
    directedGraph.addEdge(edge36);
    directedGraph.addEdge(edge46);
    directedGraph.addEdge(edge56);
    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);
    int index1 = indices.get(node1);
    int index2 = indices.get(node2);
    int index3 = indices.get(node3);
    int index5 = indices.get(node5);
    int index6 = indices.get(node6);
    double hub2 = hubs[index2];
    double hub3 = hubs[index3];
    double hub5 = hubs[index5];
    double hub6 = hubs[index6];
    double auth1 = authority[index1];
    double auth3 = authority[index3];
    double auth6 = authority[index6];
    assertEquals(hub3, hub5);
    assertTrue(hub3 > hub2);
    assertTrue(auth1 > auth6);
    assertEquals(hub6, 0.0);
    assertEquals(auth3, 0.0);
}
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 44 with DirectedGraph

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

the class HitsNGTest method testDirectedSpecial3GraphHits.

@Test
public void testDirectedSpecial3GraphHits() {
    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");
    Node node6 = graphModel.factory().newNode("5");
    directedGraph.addNode(node1);
    directedGraph.addNode(node2);
    directedGraph.addNode(node3);
    directedGraph.addNode(node4);
    directedGraph.addNode(node5);
    directedGraph.addNode(node6);
    Edge edge15 = graphModel.factory().newEdge(node1, node5);
    Edge edge25 = graphModel.factory().newEdge(node2, node5);
    Edge edge35 = graphModel.factory().newEdge(node3, node5);
    Edge edge45 = graphModel.factory().newEdge(node4, node5);
    Edge edge56 = graphModel.factory().newEdge(node5, node6);
    directedGraph.addEdge(edge15);
    directedGraph.addEdge(edge25);
    directedGraph.addEdge(edge35);
    directedGraph.addEdge(edge45);
    directedGraph.addEdge(edge56);
    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);
    int index1 = indices.get(node1);
    int index3 = indices.get(node3);
    int index5 = indices.get(node5);
    int index6 = indices.get(node6);
    double hub1 = hubs[index1];
    double hub3 = hubs[index3];
    double hub5 = hubs[index5];
    double auth5 = authority[index5];
    double auth6 = authority[index6];
    assertEquals(hub1, hub3);
    assertTrue(hub1 > hub5);
    assertTrue(auth5 > auth6);
}
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 45 with DirectedGraph

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

the class PageRankNGTest method testCyclicDirectedGraphPageRank.

@Test
public void testCyclicDirectedGraphPageRank() {
    pc.newProject();
    GraphModel graphModel = GraphGenerator.generateCyclicDirectedGraph(5);
    DirectedGraph graph = graphModel.getDirectedGraph();
    PageRank pr = new PageRank();
    double[] pageRank;
    HashMap<Node, Integer> indicies = pr.createIndiciesMap(graph);
    pageRank = pr.calculatePagerank(graph, indicies, true, false, 0.001, 0.85);
    Node n3 = graph.getNode("2");
    int index3 = indicies.get(n3);
    double pr3 = pageRank[index3];
    double res = 0.2d;
    double diff3 = Math.abs(pr3 - res);
    assertTrue(diff3 < 0.01);
}
Also used : DirectedGraph(org.gephi.graph.api.DirectedGraph) GraphModel(org.gephi.graph.api.GraphModel) Node(org.gephi.graph.api.Node) 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