Search in sources :

Example 1 with DirectedGraph

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

the class ClusteringCoefficient method createNeighbourTable.

private HashMap<Node, EdgeWrapper> createNeighbourTable(Graph graph, Node node, HashMap<Node, Integer> indicies, ArrayWrapper[] networks, boolean directed) {
    HashMap<Node, EdgeWrapper> neighborTable = new HashMap<>();
    if (!directed) {
        for (Edge edge : graph.getEdges(node)) {
            Node neighbor = graph.getOpposite(node, edge);
            neighborTable.put(neighbor, new EdgeWrapper(1, networks[indicies.get(neighbor)]));
        }
    } else {
        for (Node neighbor : ((DirectedGraph) graph).getPredecessors(node)) {
            neighborTable.put(neighbor, new EdgeWrapper(1, networks[indicies.get(neighbor)]));
        }
        for (Edge out : ((DirectedGraph) graph).getOutEdges(node)) {
            Node neighbor = out.getTarget();
            EdgeWrapper ew = neighborTable.get(neighbor);
            if (ew == null) {
                neighborTable.put(neighbor, new EdgeWrapper(1, network[indicies.get(neighbor)]));
            } else {
                ew.count++;
            }
        }
    }
    return neighborTable;
}
Also used : DirectedGraph(org.gephi.graph.api.DirectedGraph) HashMap(java.util.HashMap) Node(org.gephi.graph.api.Node) Edge(org.gephi.graph.api.Edge)

Example 2 with DirectedGraph

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

the class PageRank method calculateR.

private double calculateR(Graph graph, double[] pagerankValues, HashMap<Node, Integer> indicies, boolean directed, double prob) {
    int N = graph.getNodeCount();
    double r = 0;
    for (Node s : graph.getNodes()) {
        int s_index = indicies.get(s);
        boolean out;
        if (directed) {
            out = ((DirectedGraph) graph).getOutDegree(s) > 0;
        } else {
            out = graph.getDegree(s) > 0;
        }
        if (out) {
            r += (1.0 - prob) * (pagerankValues[s_index] / N);
        } else {
            r += (pagerankValues[s_index] / N);
        }
        if (isCanceled) {
            return r;
        }
    }
    return r;
}
Also used : DirectedGraph(org.gephi.graph.api.DirectedGraph) Node(org.gephi.graph.api.Node)

Example 3 with DirectedGraph

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

the class WeightedDegree method calculateAverageWeightedDegree.

public double calculateAverageWeightedDegree(Graph graph, boolean isDirected, boolean updateAttributes) {
    double averageWeightedDegree = 0;
    DirectedGraph directedGraph = null;
    if (isDirected) {
        directedGraph = (DirectedGraph) graph;
    }
    Progress.start(progress, graph.getNodeCount());
    for (Node n : graph.getNodes()) {
        double totalWeight = 0;
        if (isDirected) {
            double totalInWeight = 0;
            double totalOutWeight = 0;
            for (Edge e : directedGraph.getEdges(n)) {
                if (e.getSource().equals(n)) {
                    totalOutWeight += e.getWeight();
                }
                if (e.getTarget().equals(n)) {
                    totalInWeight += e.getWeight();
                }
            }
            totalWeight = totalInWeight + totalOutWeight;
            n.setAttribute(WINDEGREE, totalInWeight);
            n.setAttribute(WOUTDEGREE, totalOutWeight);
            n.setAttribute(WDEGREE, totalWeight);
            updateDegreeDists(totalInWeight, totalOutWeight, totalWeight);
        } else {
            for (Edge e : graph.getEdges(n)) {
                totalWeight += (e.isSelfLoop() ? 2 : 1) * e.getWeight();
            }
            n.setAttribute(WDEGREE, totalWeight);
            updateDegreeDists(totalWeight);
        }
        averageWeightedDegree += totalWeight;
        if (isCanceled) {
            break;
        }
        Progress.progress(progress);
    }
    averageWeightedDegree /= (isDirected ? 2.0 : 1.0) * graph.getNodeCount();
    return averageWeightedDegree;
}
Also used : DirectedGraph(org.gephi.graph.api.DirectedGraph) Node(org.gephi.graph.api.Node) Edge(org.gephi.graph.api.Edge)

Example 4 with DirectedGraph

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

the class DynamicDegree method loop.

@Override
public void loop(GraphView window, Interval interval) {
    Graph graph = graphModel.getGraph(window);
    DirectedGraph directedGraph = null;
    if (isDirected) {
        directedGraph = graphModel.getDirectedGraph(window);
    }
    TimeRepresentation tr = graphModel.getConfiguration().getTimeRepresentation();
    long sum = 0;
    for (Node n : graph.getNodes().toArray()) {
        int degree = graph.getDegree(n);
        if (!averageOnly) {
            switch(tr) {
                case INTERVAL:
                    n.setAttribute(dynamicDegreeColumn, degree, new Interval(interval.getLow(), interval.getLow() + tick));
                    break;
                case TIMESTAMP:
                    n.setAttribute(dynamicDegreeColumn, degree, interval.getLow());
                    n.setAttribute(dynamicDegreeColumn, degree, interval.getHigh());
                    break;
            }
            if (isDirected) {
                int indegree = directedGraph.getInDegree(n);
                int outdegree = directedGraph.getOutDegree(n);
                switch(tr) {
                    case INTERVAL:
                        n.setAttribute(dynamicInDegreeColumn, indegree, new Interval(interval.getLow(), interval.getLow() + tick));
                        n.setAttribute(dynamicOutDegreeColumn, outdegree, new Interval(interval.getLow(), interval.getLow() + tick));
                        break;
                    case TIMESTAMP:
                        n.setAttribute(dynamicInDegreeColumn, indegree, interval.getLow());
                        n.setAttribute(dynamicInDegreeColumn, indegree, interval.getHigh());
                        n.setAttribute(dynamicOutDegreeColumn, outdegree, interval.getLow());
                        n.setAttribute(dynamicOutDegreeColumn, outdegree, interval.getHigh());
                        break;
                }
            }
        }
        sum += degree;
        if (cancel) {
            break;
        }
    }
    double avg = sum / (double) graph.getNodeCount();
    averages.put(interval.getLow(), avg);
    averages.put(interval.getHigh(), avg);
    graphModel.getGraphVisible().setAttribute(DYNAMIC_AVGDEGREE, avg, interval.getLow());
    graphModel.getGraphVisible().setAttribute(DYNAMIC_AVGDEGREE, avg, interval.getHigh());
}
Also used : DirectedGraph(org.gephi.graph.api.DirectedGraph) Graph(org.gephi.graph.api.Graph) DirectedGraph(org.gephi.graph.api.DirectedGraph) TimeRepresentation(org.gephi.graph.api.TimeRepresentation) Node(org.gephi.graph.api.Node) Interval(org.gephi.graph.api.Interval)

Example 5 with DirectedGraph

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

the class ClusteringCoefficientNGTest method testTriangleNonCompleteDirectedGraphClusteringCoefficient.

@Test
public void testTriangleNonCompleteDirectedGraphClusteringCoefficient() {
    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");
    directedGraph.addNode(node1);
    directedGraph.addNode(node2);
    directedGraph.addNode(node3);
    Edge edge12 = graphModel.factory().newEdge(node1, node2);
    Edge edge21 = graphModel.factory().newEdge(node2, node1);
    Edge edge23 = graphModel.factory().newEdge(node2, node3);
    Edge edge32 = graphModel.factory().newEdge(node3, node2);
    Edge edge13 = graphModel.factory().newEdge(node1, node3);
    directedGraph.addEdge(edge12);
    directedGraph.addEdge(edge21);
    directedGraph.addEdge(edge23);
    directedGraph.addEdge(edge32);
    directedGraph.addEdge(edge13);
    DirectedGraph graph = graphModel.getDirectedGraph();
    ClusteringCoefficient cc = new ClusteringCoefficient();
    ArrayWrapper[] network = new ArrayWrapper[3];
    int[] triangles = new int[3];
    double[] nodeClustering = new double[3];
    HashMap<String, Double> results = cc.computeClusteringCoefficient(graph, network, triangles, nodeClustering, true);
    double avClusteringCoefficient = results.get("clusteringCoefficient");
    double res = 0.833;
    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)

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