Search in sources :

Example 21 with DirectedGraph

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

the class WeightedDegreeNGTest method testDirectedStarOutGraphDegree.

@Test
public void testDirectedStarOutGraphDegree() {
    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();
    Node n1 = graph.getNode("0");
    Node n3 = graph.getNode("2");
    WeightedDegree d = new WeightedDegree();
    d.execute(graph);
    double inDegree1 = (Double) n1.getAttribute(WeightedDegree.WINDEGREE);
    double outDegree1 = (Double) n1.getAttribute(WeightedDegree.WOUTDEGREE);
    double degree3 = (Double) n3.getAttribute(WeightedDegree.WDEGREE);
    assertEquals(inDegree1, 0.0);
    assertEquals(outDegree1, 5.0);
    assertEquals(degree3, 1.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 22 with DirectedGraph

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

the class WeightedDegreeNGTest method testSelfLoopDirectedGraphDegree.

@Test
public void testSelfLoopDirectedGraphDegree() {
    GraphModel graphModel = GraphGenerator.generateSelfLoopDirectedGraph(1);
    DirectedGraph graph = graphModel.getDirectedGraph();
    Node n = graph.getNode("0");
    WeightedDegree d = new WeightedDegree();
    d.execute(graph);
    assertEquals(n.getAttribute(WeightedDegree.WDEGREE), 2.0);
    assertEquals(n.getAttribute(WeightedDegree.WINDEGREE), 1.0);
    assertEquals(n.getAttribute(WeightedDegree.WOUTDEGREE), 1.0);
}
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)

Example 23 with DirectedGraph

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

the class PageRankNGTest method testPathDirectedGraphPageRank.

@Test
public void testPathDirectedGraphPageRank() {
    pc.newProject();
    GraphModel graphModel = GraphGenerator.generatePathDirectedGraph(4);
    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 n1 = graph.getNode("0");
    Node n2 = graph.getNode("1");
    Node n3 = graph.getNode("2");
    Node n4 = graph.getNode("3");
    int index1 = indicies.get(n1);
    int index2 = indicies.get(n2);
    int index3 = indicies.get(n3);
    int index4 = indicies.get(n4);
    double pr1 = pageRank[index1];
    double pr2 = pageRank[index2];
    double pr3 = pageRank[index3];
    double pr4 = pageRank[index4];
    double res = 1.;
    double diff = 0.01;
    double sum = pr1 + pr2 + pr3 + pr4;
    assertTrue(pr1 < pr2);
    assertTrue(pr2 < pr4);
    assertTrue(Math.abs(sum - res) < diff);
}
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)

Example 24 with DirectedGraph

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

the class PageRankNGTest method testDirectedStarOutGraphPageRank.

@Test
public void testDirectedStarOutGraphPageRank() {
    pc.newProject();
    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();
    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 n1 = graph.getNode("0");
    Node n2 = graph.getNode("1");
    Node n3 = graph.getNode("2");
    Node n5 = graph.getNode("4");
    int index1 = indicies.get(n1);
    int index2 = indicies.get(n2);
    int index3 = indicies.get(n3);
    int index5 = indicies.get(n5);
    double pr1 = pageRank[index1];
    double pr2 = pageRank[index2];
    double pr3 = pageRank[index3];
    double pr5 = pageRank[index5];
    double res = 0.146;
    double diff = 0.01;
    assertTrue(pr1 < pr3);
    assertEquals(pr2, pr5);
    assertTrue(Math.abs(pr1 - res) < diff);
}
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 25 with DirectedGraph

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

the class GraphGenerator method generateCyclicDirectedGraph.

public static GraphModel generateCyclicDirectedGraph(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;
    }
    Edge currentEdge = graphModel.factory().newEdge(prevNode, firstNode);
    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)

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