Search in sources :

Example 51 with Edge

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

the class GeneralChooseColumnsAndRowUI method refreshRows.

private void refreshRows() {
    rows = columnsAndRowChooser.getRows();
    Object sourceRow = columnsAndRowChooser.getRow();
    Node node;
    Edge edge;
    // Prepare combo box with nodes/edges data:
    for (int i = 0; i < rows.length; i++) {
        if (rows[i] instanceof Node) {
            node = (Node) rows[i];
            rowComboBox.addItem(node.getId() + " - " + node.getLabel());
        } else {
            edge = (Edge) rows[i];
            rowComboBox.addItem(edge.getId() + " - " + edge.getLabel());
        }
        if (rows[i] == sourceRow) {
            rowComboBox.setSelectedIndex(i);
        }
    }
}
Also used : Node(org.gephi.graph.api.Node) Edge(org.gephi.graph.api.Edge)

Example 52 with Edge

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

the class StatisticsControllerImpl method executeDynamic.

private void executeDynamic(DynamicStatistics statistics, DynamicLongTask dynamicLongTask) {
    GraphController graphController = Lookup.getDefault().lookup(GraphController.class);
    GraphModel graphModel = graphController.getGraphModel();
    double window = statistics.getWindow();
    double tick = statistics.getTick();
    GraphView currentView = graphModel.getVisibleView();
    Interval bounds = statistics.getBounds();
    if (bounds == null) {
        if (currentView.isMainView()) {
            bounds = graphModel.getTimeBounds();
        } else {
            bounds = currentView.getTimeInterval();
        }
        statistics.setBounds(bounds);
    }
    if (dynamicLongTask != null) {
        // Count
        int c = (int) ((bounds.getHigh() - window - bounds.getLow()) / tick);
        dynamicLongTask.start(c);
    }
    // Init
    statistics.execute(graphModel);
    // Loop
    for (double low = bounds.getLow(); low <= bounds.getHigh() - window; low += tick) {
        double high = low + window;
        Graph graph = graphModel.getGraphVisible();
        graph.writeLock();
        try {
            GraphView view = graphModel.createView();
            Subgraph g = graphModel.getGraph(view);
            TimeIndex<Node> nodeIndex = graphModel.getNodeTimeIndex(currentView);
            if (Double.isInfinite(nodeIndex.getMinTimestamp()) && Double.isInfinite(nodeIndex.getMaxTimestamp())) {
                for (Node node : graph.getNodes()) {
                    g.addNode(node);
                }
            } else {
                for (Node node : nodeIndex.get(new Interval(low, high))) {
                    g.addNode(node);
                }
            }
            TimeIndex<Edge> edgeIndex = graphModel.getEdgeTimeIndex(currentView);
            if (Double.isInfinite(edgeIndex.getMinTimestamp()) && Double.isInfinite(edgeIndex.getMaxTimestamp())) {
                for (Edge edge : graph.getEdges()) {
                    if (g.contains(edge.getSource()) && g.contains(edge.getTarget())) {
                        g.addEdge(edge);
                    }
                }
            } else {
                for (Edge edge : edgeIndex.get(new Interval(low, high))) {
                    if (g.contains(edge.getSource()) && g.contains(edge.getTarget())) {
                        g.addEdge(edge);
                    }
                }
            }
            statistics.loop(g.getView(), new Interval(low, high));
        } finally {
            graph.writeUnlock();
            graph.readUnlockAll();
        }
        // Cancelled?
        if (dynamicLongTask != null && dynamicLongTask.isCancelled()) {
            return;
        } else if (dynamicLongTask != null) {
            dynamicLongTask.progress();
        }
    }
    statistics.end();
    model.addReport(statistics);
}
Also used : Graph(org.gephi.graph.api.Graph) GraphModel(org.gephi.graph.api.GraphModel) Node(org.gephi.graph.api.Node) Subgraph(org.gephi.graph.api.Subgraph) GraphView(org.gephi.graph.api.GraphView) Edge(org.gephi.graph.api.Edge) GraphController(org.gephi.graph.api.GraphController) Interval(org.gephi.graph.api.Interval)

Example 53 with Edge

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

the class Modularity method finalQ.

private double finalQ(int[] struct, double[] degrees, Graph graph, CommunityStructure theStructure, double totalWeight, double usedResolution, boolean weighted) {
    double res = 0;
    double[] internal = new double[degrees.length];
    for (Node n : graph.getNodes()) {
        int n_index = theStructure.map.get(n);
        for (Edge edge : graph.getEdges(n)) {
            Node neighbor = graph.getOpposite(n, edge);
            if (n == neighbor) {
                continue;
            }
            int neigh_index = theStructure.map.get(neighbor);
            if (struct[neigh_index] == struct[n_index]) {
                if (weighted) {
                    internal[struct[neigh_index]] += edge.getWeight(graph.getView());
                } else {
                    internal[struct[neigh_index]]++;
                }
            }
        }
    }
    for (int i = 0; i < degrees.length; i++) {
        internal[i] /= 2.0;
        // HERE
        res += usedResolution * (internal[i] / totalWeight) - Math.pow(degrees[i] / (2 * totalWeight), 2);
    }
    return res;
}
Also used : Node(org.gephi.graph.api.Node) Edge(org.gephi.graph.api.Edge)

Example 54 with Edge

use of org.gephi.graph.api.Edge 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());
    NodeIterable nodesIterable = graph.getNodes();
    for (Node n : nodesIterable) {
        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) {
            nodesIterable.doBreak();
            break;
        }
        Progress.progress(progress);
    }
    averageWeightedDegree /= (isDirected ? 2.0 : 1.0) * graph.getNodeCount();
    return averageWeightedDegree;
}
Also used : DirectedGraph(org.gephi.graph.api.DirectedGraph) NodeIterable(org.gephi.graph.api.NodeIterable) Node(org.gephi.graph.api.Node) Edge(org.gephi.graph.api.Edge)

Example 55 with Edge

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

the class ShortestPath method getListeners.

@Override
public ToolEventListener[] getListeners() {
    listeners = new ToolEventListener[2];
    listeners[0] = new NodeClickEventListener() {

        @Override
        public void clickNodes(Node[] nodes) {
            Node n = nodes[0];
            if (sourceNode == null) {
                sourceNode = n;
                shortestPathPanel.setResult("");
                shortestPathPanel.setStatus(NbBundle.getMessage(ShortestPath.class, "ShortestPath.status2"));
            } else if (n != sourceNode) {
                color = shortestPathPanel.getColor();
                Node targetNode = n;
                GraphController gc = Lookup.getDefault().lookup(GraphController.class);
                GraphModel gm = gc.getGraphModel();
                AbstractShortestPathAlgorithm algorithm;
                if (gm.isDirected()) {
                    algorithm = new BellmanFordShortestPathAlgorithm(gm.getDirectedGraphVisible(), sourceNode);
                } else {
                    algorithm = new DijkstraShortestPathAlgorithm(gm.getGraphVisible(), sourceNode);
                }
                algorithm.compute();
                double distance;
                if ((distance = algorithm.getDistances().get(targetNode)) != Double.POSITIVE_INFINITY) {
                    targetNode.setColor(color);
                    VizController.getInstance().selectNode(targetNode);
                    Edge predecessorEdge = algorithm.getPredecessorIncoming(targetNode);
                    Node predecessor = algorithm.getPredecessor(targetNode);
                    while (predecessorEdge != null && predecessor != sourceNode) {
                        predecessorEdge.setColor(color);
                        VizController.getInstance().selectEdge(predecessorEdge);
                        predecessor.setColor(color);
                        VizController.getInstance().selectNode(predecessor);
                        predecessorEdge = algorithm.getPredecessorIncoming(predecessor);
                        predecessor = algorithm.getPredecessor(predecessor);
                    }
                    predecessorEdge.setColor(color);
                    VizController.getInstance().selectEdge(predecessorEdge);
                    sourceNode.setColor(color);
                    VizController.getInstance().selectNode(sourceNode);
                    shortestPathPanel.setResult(NbBundle.getMessage(ShortestPath.class, "ShortestPath.result", distance));
                } else {
                    // No path
                    shortestPathPanel.setResult(NbBundle.getMessage(ShortestPath.class, "ShortestPath.noresult"));
                }
                sourceNode = null;
                shortestPathPanel.setStatus(NbBundle.getMessage(ShortestPath.class, "ShortestPath.status1"));
            }
        }
    };
    listeners[1] = new MouseClickEventListener() {

        @Override
        public void mouseClick(int[] positionViewport, float[] position3d) {
            if (sourceNode != null) {
                // Cancel
                shortestPathPanel.setStatus(NbBundle.getMessage(ShortestPath.class, "ShortestPath.status1"));
                sourceNode = null;
            } else {
                VizController.getInstance().resetSelection();
            }
        }
    };
    return listeners;
}
Also used : MouseClickEventListener(org.gephi.tools.spi.MouseClickEventListener) Node(org.gephi.graph.api.Node) DijkstraShortestPathAlgorithm(org.gephi.algorithms.shortestpath.DijkstraShortestPathAlgorithm) AbstractShortestPathAlgorithm(org.gephi.algorithms.shortestpath.AbstractShortestPathAlgorithm) BellmanFordShortestPathAlgorithm(org.gephi.algorithms.shortestpath.BellmanFordShortestPathAlgorithm) GraphModel(org.gephi.graph.api.GraphModel) NodeClickEventListener(org.gephi.tools.spi.NodeClickEventListener) Edge(org.gephi.graph.api.Edge) GraphController(org.gephi.graph.api.GraphController)

Aggregations

Edge (org.gephi.graph.api.Edge)151 Node (org.gephi.graph.api.Node)122 GraphModel (org.gephi.graph.api.GraphModel)84 GraphController (org.gephi.graph.api.GraphController)79 Test (org.testng.annotations.Test)67 UndirectedGraph (org.gephi.graph.api.UndirectedGraph)46 DirectedGraph (org.gephi.graph.api.DirectedGraph)44 Graph (org.gephi.graph.api.Graph)31 HashMap (java.util.HashMap)26 EdgeIterable (org.gephi.graph.api.EdgeIterable)18 LinkedList (java.util.LinkedList)13 Column (org.gephi.graph.api.Column)11 NodeIterable (org.gephi.graph.api.NodeIterable)9 ArrayList (java.util.ArrayList)8 Table (org.gephi.graph.api.Table)6 GraphView (org.gephi.graph.api.GraphView)5 HashSet (java.util.HashSet)4 Interval (org.gephi.graph.api.Interval)4 TimeFormat (org.gephi.graph.api.TimeFormat)4 DateTimeZone (org.joda.time.DateTimeZone)4