Search in sources :

Example 71 with GraphModel

use of org.gephi.graph.api.GraphModel 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 72 with GraphModel

use of org.gephi.graph.api.GraphModel 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 73 with GraphModel

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

the class PageRankNGTest method testTwoConnectedNodesPageRank.

@Test
public void testTwoConnectedNodesPageRank() {
    pc.newProject();
    GraphModel graphModel = GraphGenerator.generatePathUndirectedGraph(2);
    UndirectedGraph graph = graphModel.getUndirectedGraph();
    PageRank pr = new PageRank();
    double[] pageRank;
    HashMap<Node, Integer> indicies = pr.createIndiciesMap(graph);
    pageRank = pr.calculatePagerank(graph, indicies, false, false, 0.001, 0.85);
    Node n2 = graph.getNode("1");
    int index = indicies.get(n2);
    double pr2 = pageRank[index];
    assertEquals(pr2, 0.5);
}
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 74 with GraphModel

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

the class GraphGenerator method generateCyclicUndirectedGraph.

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

Example 75 with GraphModel

use of org.gephi.graph.api.GraphModel 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

GraphModel (org.gephi.graph.api.GraphModel)235 Node (org.gephi.graph.api.Node)169 Test (org.testng.annotations.Test)168 UndirectedGraph (org.gephi.graph.api.UndirectedGraph)115 GraphController (org.gephi.graph.api.GraphController)105 DirectedGraph (org.gephi.graph.api.DirectedGraph)92 Edge (org.gephi.graph.api.Edge)80 Graph (org.gephi.graph.api.Graph)57 HashMap (java.util.HashMap)52 Column (org.gephi.graph.api.Column)16 LinkedList (java.util.LinkedList)12 ArrayList (java.util.ArrayList)11 FilterBuilder (org.gephi.filters.spi.FilterBuilder)6 GraphView (org.gephi.graph.api.GraphView)6 XMLStreamException (javax.xml.stream.XMLStreamException)5 IOException (java.io.IOException)4 AppearanceController (org.gephi.appearance.api.AppearanceController)4 AppearanceModel (org.gephi.appearance.api.AppearanceModel)4 TimeFormat (org.gephi.graph.api.TimeFormat)4 Element (org.gephi.graph.api.Element)3