Package org.gephi.graph.api

Examples of org.gephi.graph.api.DirectedGraph


    @Test
    public void testDirectedStarOutEigenvectorCentrality() {
        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 hgraph = graphModel.getDirectedGraph();
        EigenvectorCentrality ec = new EigenvectorCentrality();

        double[] centralities = new double[6];

        HashMap<Integer, Node> indicies = new HashMap();
        HashMap<Node, Integer> invIndicies = new HashMap();

        ec.fillIndiciesMaps(hgraph, centralities, indicies, invIndicies);

        ec.calculateEigenvectorCentrality(hgraph, centralities, indicies, invIndicies, true, 100);

        Node n1 = hgraph.getNode("0");
        Node n2 = hgraph.getNode("1");
        int index1 = invIndicies.get(n1);
        int index2 = invIndicies.get(n2);
        double ec1 = centralities[index1];
        double ec2 = centralities[index2];
View Full Code Here


    }

    @Test
    public void testPathDirectedGraphEigenvectorCentrality() {
        GraphModel graphModel = GraphGenerator.generatePathDirectedGraph(4);
        DirectedGraph hgraph = graphModel.getDirectedGraph();

        EigenvectorCentrality ec = new EigenvectorCentrality();

        double[] centralities = new double[4];

        HashMap<Integer, Node> indicies = new HashMap();
        HashMap<Node, Integer> invIndicies = new HashMap();

        ec.fillIndiciesMaps(hgraph, centralities, indicies, invIndicies);

        ec.calculateEigenvectorCentrality(hgraph, centralities, indicies, invIndicies, true, 100);

        Node n1 = hgraph.getNode("0");
        Node n4 = hgraph.getNode("3");
        int index1 = invIndicies.get(n1);
        int index4 = invIndicies.get(n4);
        double ec1 = centralities[index1];
        double ec4 = centralities[index4];
View Full Code Here

    }

    @Test
    public void testDirectedPathGraphDensity() {
        GraphModel graphModel = GraphGenerator.generatePathDirectedGraph(2);
        DirectedGraph graph = graphModel.getDirectedGraph();
        GraphDensity d = new GraphDensity();
        double density = d.calculateDensity(graph, true);
        assertEquals(density, 0.5);
    }
View Full Code Here

    }

    @Test
    public void testDirectedCyclicGraphDensity() {
        GraphModel graphModel = GraphGenerator.generateCyclicDirectedGraph(5);
        DirectedGraph graph = graphModel.getDirectedGraph();
        GraphDensity d = new GraphDensity();
        double density = d.calculateDensity(graph, true);
        assertEquals(density, 0.25);
    }
View Full Code Here

    }

    @Test
    public void testDirectedCompleteGraphDensity() {
        GraphModel graphModel = GraphGenerator.generateCompleteDirectedGraph(5);
        DirectedGraph graph = graphModel.getDirectedGraph();
        GraphDensity d = new GraphDensity();
        double density = d.calculateDensity(graph, true);
        assertEquals(density, 1.0);
    }
View Full Code Here

    }

    @Test
    public void testDirectedCompleteGraphWithSelfLoopsDensity() {
        GraphModel graphModel = GraphGenerator.generateCompleteDirectedGraph(3);
        DirectedGraph directedGraph = graphModel.getDirectedGraph();
        Node n1 = directedGraph.getNode("0");
        Node n2 = directedGraph.getNode("1");
        Node n3 = directedGraph.getNode("2");
        Edge currentEdge = graphModel.factory().newEdge(n1, n1);
        directedGraph.addEdge(currentEdge);
        currentEdge = graphModel.factory().newEdge(n2, n2);
        directedGraph.addEdge(currentEdge);
        currentEdge = graphModel.factory().newEdge(n3, n3);
        directedGraph.addEdge(currentEdge);

        DirectedGraph graph = graphModel.getDirectedGraph();

        GraphDensity d = new GraphDensity();
        double density = d.calculateDensity(graph, true);
        assertEquals(density, 1.5);
    }
View Full Code Here

        return graphModel;
    }

    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;
    }
View Full Code Here

        return graphModel;
    }

    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;
    }
View Full Code Here

        return graphModel;
    }

    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;
    }
View Full Code Here

        return graphModel;
    }

    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;
    }
View Full Code Here

TOP

Related Classes of org.gephi.graph.api.DirectedGraph

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.