Search in sources :

Example 11 with NodeIterable

use of org.gephi.graph.api.NodeIterable 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 12 with NodeIterable

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

the class ExporterGML method exportData.

private void exportData(Graph graph) throws IOException {
    printOpen("graph");
    printTag("Creator \"Gephi\"");
    if (graph.isDirected() || graph.isMixed()) {
        printTag("directed 1");
    } else if (graph.isUndirected()) {
        printTag("directed 0");
    }
    NodeIterable nodeIterable = graph.getNodes();
    for (Node node : nodeIterable) {
        if (cancel) {
            nodeIterable.doBreak();
            return;
        }
        printNode(node, graph);
    }
    EdgeIterable edgeIterable = graph.getEdges();
    for (Edge edge : edgeIterable) {
        if (cancel) {
            edgeIterable.doBreak();
            return;
        }
        printEdge(edge, graph);
    }
    printClose();
}
Also used : NodeIterable(org.gephi.graph.api.NodeIterable) EdgeIterable(org.gephi.graph.api.EdgeIterable) Node(org.gephi.graph.api.Node) Edge(org.gephi.graph.api.Edge)

Example 13 with NodeIterable

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

the class ExporterGraphML method createNodes.

private void createNodes(Document document, Element parentE, Graph graph) throws Exception {
    NodeIterable nodeIterable = graph.getNodes();
    for (Node n : nodeIterable) {
        if (cancel) {
            nodeIterable.doBreak();
            break;
        }
        Element nodeE = createNode(document, graph, n);
        parentE.appendChild(nodeE);
    }
}
Also used : NodeIterable(org.gephi.graph.api.NodeIterable) Node(org.gephi.graph.api.Node) Element(org.w3c.dom.Element)

Example 14 with NodeIterable

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

the class AbstractLayout method ensureSafeLayoutNodePositions.

/**
 * See https://github.com/gephi/gephi/issues/603 Nodes position to NaN on applied layout
 *
 * @param graphModel
 */
public static void ensureSafeLayoutNodePositions(GraphModel graphModel) {
    Graph graph = graphModel.getGraph();
    NodeIterable nodesIterable = graph.getNodes();
    for (Node node : nodesIterable) {
        if (node.x() != 0 || node.y() != 0) {
            nodesIterable.doBreak();
            return;
        }
    }
    // All at 0.0, init some random positions
    nodesIterable = graph.getNodes();
    for (Node node : nodesIterable) {
        node.setX((float) ((0.01 + Math.random()) * 1000) - 500);
        node.setY((float) ((0.01 + Math.random()) * 1000) - 500);
    }
}
Also used : Graph(org.gephi.graph.api.Graph) NodeIterable(org.gephi.graph.api.NodeIterable) Node(org.gephi.graph.api.Node)

Example 15 with NodeIterable

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

the class ClusteringCoefficient method computeTriangles.

private HashMap<String, Double> computeTriangles(Graph graph, ArrayWrapper[] currentNetwork, int[] currentTriangles, double[] nodeClustering, boolean directed) {
    HashMap<String, Double> resultValues = new HashMap<>();
    int ProgressCount = 0;
    Progress.start(progress, 7 * graph.getNodeCount());
    graph.readLock();
    try {
        int n = graph.getNodeCount();
        /**
         * Create network for processing
         */
        /**
         */
        HashMap<Node, Integer> indicies = new HashMap<>();
        ProgressCount = createIndiciesMapAndInitNetwork(graph, indicies, currentNetwork, ProgressCount);
        int index = 0;
        NodeIterable nodesIterable = graph.getNodes();
        for (Node node : nodesIterable) {
            HashMap<Node, EdgeWrapper> neighborTable = createNeighbourTable(graph, node, indicies, currentNetwork, directed);
            EdgeWrapper[] edges = getEdges(neighborTable);
            currentNetwork[index].node = node;
            currentNetwork[index].setArray(edges);
            index++;
            Progress.progress(progress, ++ProgressCount);
            if (isCanceled) {
                nodesIterable.doBreak();
                return resultValues;
            }
        }
        ProgressCount = processNetwork(currentNetwork, ProgressCount);
        int k = (int) Math.sqrt(n);
        for (int v = 0; v < k && v < n; v++) {
            newVertex(currentNetwork, currentTriangles, v, n);
            Progress.progress(progress, ++ProgressCount);
        }
        /* remaining links */
        ProgressCount = computeRemainingTrianles(graph, currentNetwork, currentTriangles, ProgressCount);
        resultValues = computeResultValues(graph, currentNetwork, currentTriangles, nodeClustering, directed, ProgressCount);
    } finally {
        graph.readUnlock();
    }
    return resultValues;
}
Also used : NodeIterable(org.gephi.graph.api.NodeIterable) HashMap(java.util.HashMap) Node(org.gephi.graph.api.Node)

Aggregations

Node (org.gephi.graph.api.Node)23 NodeIterable (org.gephi.graph.api.NodeIterable)23 Edge (org.gephi.graph.api.Edge)9 EdgeIterable (org.gephi.graph.api.EdgeIterable)8 LinkedList (java.util.LinkedList)3 Column (org.gephi.graph.api.Column)3 Object2DoubleOpenHashMap (it.unimi.dsi.fastutil.objects.Object2DoubleOpenHashMap)2 Object2ObjectOpenHashMap (it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap)2 ObjectOpenHashSet (it.unimi.dsi.fastutil.objects.ObjectOpenHashSet)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 DirectedGraph (org.gephi.graph.api.DirectedGraph)2 ArrayList (java.util.ArrayList)1 Graph (org.gephi.graph.api.Graph)1 Element (org.w3c.dom.Element)1