Search in sources :

Example 76 with GraphModel

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

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

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

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

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

the class HitsNGTest method testOneNodeHits.

@Test
public void testOneNodeHits() {
    GraphModel graphModel = GraphGenerator.generateNullUndirectedGraph(1);
    Graph graph = graphModel.getUndirectedGraph();
    Hits hit = new Hits();
    double[] authority = new double[1];
    double[] hubs = new double[1];
    HashMap<Node, Integer> indices = hit.createIndicesMap(graph);
    hit.calculateHits(graph, hubs, authority, indices, false, EPSILON);
    Node n1 = graph.getNode("0");
    int index = indices.get(n1);
    double hub1 = hubs[index];
    double auth1 = authority[index];
    assertEquals(hub1, 0.0);
    assertEquals(auth1, 0.0);
}
Also used : Graph(org.gephi.graph.api.Graph) UndirectedGraph(org.gephi.graph.api.UndirectedGraph) DirectedGraph(org.gephi.graph.api.DirectedGraph) GraphModel(org.gephi.graph.api.GraphModel) Node(org.gephi.graph.api.Node) Test(org.testng.annotations.Test)

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