Search in sources :

Example 11 with DirectedGraph

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

the class Degree method calculateAverageDegree.

protected double calculateAverageDegree(Graph graph, boolean isDirected, boolean updateAttributes) {
    double averageDegree = 0;
    DirectedGraph directedGraph = null;
    if (isDirected) {
        directedGraph = (DirectedGraph) graph;
    }
    Progress.start(progress, graph.getNodeCount());
    for (Node n : graph.getNodes()) {
        int inDegree = 0;
        int outDegree = 0;
        int degree = 0;
        if (isDirected) {
            inDegree = calculateInDegree(directedGraph, n);
            outDegree = calculateOutDegree(directedGraph, n);
        }
        degree = calculateDegree(graph, n);
        if (updateAttributes) {
            n.setAttribute(DEGREE, degree);
            if (isDirected) {
                n.setAttribute(INDEGREE, inDegree);
                n.setAttribute(OUTDEGREE, outDegree);
                updateDegreeDists(inDegree, outDegree, degree);
            } else {
                updateDegreeDists(degree);
            }
        }
        averageDegree += degree;
        if (isCanceled) {
            break;
        }
        Progress.progress(progress);
    }
    averageDegree /= (isDirected ? 2.0 : 1.0) * graph.getNodeCount();
    return averageDegree;
}
Also used : DirectedGraph(org.gephi.graph.api.DirectedGraph) Node(org.gephi.graph.api.Node)

Example 12 with DirectedGraph

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

the class ClusteringCoefficientNGTest method testSpecial2DirectedGraphClusteringCoefficient.

@Test
public void testSpecial2DirectedGraphClusteringCoefficient() {
    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 edge21 = graphModel.factory().newEdge(node2, node1);
    Edge edge24 = graphModel.factory().newEdge(node2, node4);
    Edge edge31 = graphModel.factory().newEdge(node3, node1);
    Edge edge32 = graphModel.factory().newEdge(node3, node2);
    Edge edge43 = graphModel.factory().newEdge(node4, node3);
    directedGraph.addEdge(edge21);
    directedGraph.addEdge(edge24);
    directedGraph.addEdge(edge31);
    directedGraph.addEdge(edge32);
    directedGraph.addEdge(edge43);
    DirectedGraph graph = graphModel.getDirectedGraph();
    ClusteringCoefficient cc = new ClusteringCoefficient();
    ArrayWrapper[] network = new ArrayWrapper[4];
    int[] triangles = new int[4];
    double[] nodeClustering = new double[4];
    HashMap<String, Double> results = cc.computeClusteringCoefficient(graph, network, triangles, nodeClustering, true);
    double avClusteringCoefficient = results.get("clusteringCoefficient");
    double res = 0.4167;
    double diff = 0.01;
    assertTrue(Math.abs(avClusteringCoefficient - res) < diff);
}
Also used : Node(org.gephi.graph.api.Node) DirectedGraph(org.gephi.graph.api.DirectedGraph) GraphModel(org.gephi.graph.api.GraphModel) Edge(org.gephi.graph.api.Edge) GraphController(org.gephi.graph.api.GraphController) Test(org.testng.annotations.Test)

Example 13 with DirectedGraph

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

the class GraphDistanceNGTest method testDirectedPathGraphBetweenness.

@Test
public void testDirectedPathGraphBetweenness() {
    GraphModel graphModel = GraphGenerator.generatePathDirectedGraph(4);
    GraphDistance d = new GraphDistance();
    d.initializeStartValues();
    DirectedGraph directedGraph = graphModel.getDirectedGraph();
    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 n2 = directedGraph.getNode("1");
    int index2 = indicies.get(n2);
    assertEquals(betweenness[index2], 2.0, TOLERANCE);
}
Also used : DirectedGraph(org.gephi.graph.api.DirectedGraph) HashMap(java.util.HashMap) GraphModel(org.gephi.graph.api.GraphModel) Node(org.gephi.graph.api.Node) Test(org.testng.annotations.Test)

Example 14 with DirectedGraph

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

the class GraphDensityNGTest method testDirectedPathGraphDensity.

@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);
}
Also used : DirectedGraph(org.gephi.graph.api.DirectedGraph) GraphModel(org.gephi.graph.api.GraphModel) Test(org.testng.annotations.Test)

Example 15 with DirectedGraph

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

the class GraphDensityNGTest method testDirectedCompleteGraphDensity.

@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);
}
Also used : DirectedGraph(org.gephi.graph.api.DirectedGraph) GraphModel(org.gephi.graph.api.GraphModel) Test(org.testng.annotations.Test)

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