Package org.gephi.graph.api

Examples of org.gephi.graph.api.DirectedGraph


    @Test
    public void testDirectedStarOutGraphBetweenness() {
        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);
        }

        GraphDistance d = new GraphDistance();
        d.initializeStartValues();

        HashMap<Node, Integer> indicies = d.createIndiciesMap(graphModel.getGraph());

        HashMap<String, double[]> metricsMap = (HashMap) d.calculateDistanceMetrics(graphModel.getGraph(), indicies, true, false);
        double[] betweenness = metricsMap.get(GraphDistance.BETWEENNESS);

        Node n1 = directedGraph.getNode("0");
        Node n5 = directedGraph.getNode("4");
        int index1 = indicies.get(n1);
        int index5 = indicies.get(n5);

        assertEquals(betweenness[index1], 0.0);
        assertEquals(betweenness[index5], 0.0);
View Full Code Here


    @Test
    public void testDirectedStarOutGraphCloseness() {
        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);
        }

        GraphDistance d = new GraphDistance();
        d.initializeStartValues();

        HashMap<Node, Integer> indicies = d.createIndiciesMap(graphModel.getGraph());

        HashMap<String, double[]> metricsMap = (HashMap) d.calculateDistanceMetrics(graphModel.getGraph(), indicies, true, false);
        double[] closeness = metricsMap.get(GraphDistance.CLOSENESS);

        Node n1 = directedGraph.getNode("0");
        Node n6 = directedGraph.getNode("5");
        int index1 = indicies.get(n1);
        int index6 = indicies.get(n6);

        assertEquals(closeness[index1], 1.0);
        assertEquals(closeness[index6], 0.0);
View Full Code Here

    }

    @Test
    public void testSpecial1DirectedGraphBetweenness() {
        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 edge13 = graphModel.factory().newEdge(node1, node3);
        Edge edge32 = graphModel.factory().newEdge(node3, node2);
        Edge edge21 = graphModel.factory().newEdge(node2, node1);
        Edge edge34 = graphModel.factory().newEdge(node3, node4);
        Edge edge45 = graphModel.factory().newEdge(node4, node5);
        Edge edge53 = graphModel.factory().newEdge(node5, node3);
        directedGraph.addEdge(edge13);
        directedGraph.addEdge(edge32);
        directedGraph.addEdge(edge21);
        directedGraph.addEdge(edge34);
        directedGraph.addEdge(edge45);
        directedGraph.addEdge(edge53);

        GraphDistance d = new GraphDistance();
        d.initializeStartValues();

        HashMap<Node, Integer> indicies = d.createIndiciesMap(graphModel.getGraph());
View Full Code Here

    }

    @Override
    public void loop(GraphView window, Interval interval) {
        Graph graph = graphModel.getGraph(window);
        DirectedGraph directedGraph = null;
        if (isDirected) {
            directedGraph = graphModel.getDirectedGraph(window);
        }

        long sum = 0;
        for (Node n : graph.getNodes().toArray()) {
            int degree = graph.getDegree(n);

            if (!averageOnly) {
                n.setAttribute(dynamicDegreeColumn, degree, interval.getLow());

                if (isDirected) {
                    int indegree = directedGraph.getInDegree(n);
                    n.setAttribute(dynamicInDegreeColumn, indegree, interval.getLow());

                    int outdegree = directedGraph.getOutDegree(n);
                    n.setAttribute(dynamicOutDegreeColumn, outdegree, interval.getLow());
                }
            }
            sum += degree;
            if (cancel) {
View Full Code Here

    }

    @Test
    public void testSpecial1DirectedGraphCloseness() {
        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 edge13 = graphModel.factory().newEdge(node1, node3);
        Edge edge32 = graphModel.factory().newEdge(node3, node2);
        Edge edge21 = graphModel.factory().newEdge(node2, node1);
        Edge edge34 = graphModel.factory().newEdge(node3, node4);
        Edge edge45 = graphModel.factory().newEdge(node4, node5);
        Edge edge53 = graphModel.factory().newEdge(node5, node3);
        directedGraph.addEdge(edge13);
        directedGraph.addEdge(edge32);
        directedGraph.addEdge(edge21);
        directedGraph.addEdge(edge34);
        directedGraph.addEdge(edge45);
        directedGraph.addEdge(edge53);

        GraphDistance d = new GraphDistance();
        d.initializeStartValues();

        HashMap<Node, Integer> indicies = d.createIndiciesMap(graphModel.getGraph());
View Full Code Here

    }

    @Test
    public void testDirectedPathGraphDegree() {
        GraphModel graphModel = GraphGenerator.generatePathDirectedGraph(2);
        DirectedGraph graph = graphModel.getDirectedGraph();
        Node n1 = graph.getNode("0");
        Node n2 = graph.getNode("1");
        Degree d = new Degree();
        int inDegree1 = d.calculateInDegree(graph, n1);
        int inDegree2 = d.calculateInDegree(graph, n2);
        int outDegree1 = d.calculateOutDegree(graph, n1);
        double avDegree = d.calculateAverageDegree(graph, true, false);
View Full Code Here

    }

    @Test
    public void testDirectedCyclicGraphDegree() {
        GraphModel graphModel = GraphGenerator.generateCyclicDirectedGraph(5);
        DirectedGraph graph = graphModel.getDirectedGraph();
        Node n1 = graph.getNode("0");
        Node n3 = graph.getNode("2");
        Node n5 = graph.getNode("4");
        Degree d = new Degree();
        int inDegree3 = d.calculateInDegree(graph, n3);
        int degree1 = d.calculateDegree(graph, n1);
        int outDegree5 = d.calculateOutDegree(graph, n5);
        double avDegree = d.calculateAverageDegree(graph, true, false);
View Full Code Here

    @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");
        Degree d = new Degree();
        int inDegree1 = d.calculateInDegree(graph, n1);
        int outDegree1 = d.calculateOutDegree(graph, n1);
        int degree3 = d.calculateDegree(graph, n3);
View Full Code Here

    }

    @Test
    public void testCyclicDirectedGraphEigenvectorCentrality() {
        GraphModel graphModel = GraphGenerator.generateCyclicDirectedGraph(3);
        DirectedGraph hgraph = graphModel.getDirectedGraph();

        EigenvectorCentrality ec = new EigenvectorCentrality();

        double[] centralities = new double[3];

        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");
        int index1 = invIndicies.get(n1);
        double ec1 = centralities[index1];

        assertEquals(ec1, 1.0);
    }
View Full Code Here

    @Test
    public void testSpecial1DirectedEigenvectorCentrality() {
        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 edge12 = graphModel.factory().newEdge(node1, node2);
        Edge edge23 = graphModel.factory().newEdge(node2, node3);
        Edge edge31 = graphModel.factory().newEdge(node3, node1);
        Edge edge42 = graphModel.factory().newEdge(node4, node2);
        Edge edge54 = graphModel.factory().newEdge(node5, node4);

        directedGraph.addEdge(edge12);
        directedGraph.addEdge(edge23);
        directedGraph.addEdge(edge31);
        directedGraph.addEdge(edge42);
        directedGraph.addEdge(edge54);

        DirectedGraph hgraph = graphModel.getDirectedGraph();
        EigenvectorCentrality ec = new EigenvectorCentrality();

        double[] centralities = new double[5];

        HashMap<Integer, Node> indicies = new HashMap();
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.