Search in sources :

Example 1 with NodeIterable

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

the class ConnectedComponents method computeWeeklyConnectedComponents.

public LinkedList<LinkedList<Node>> computeWeeklyConnectedComponents(Graph graph, HashMap<Node, Integer> indicies) {
    int N = graph.getNodeCount();
    //Keep track of which nodes have been seen
    int[] color = new int[N];
    Progress.start(progress, N);
    int seenCount = 0;
    LinkedList<LinkedList<Node>> components = new LinkedList<>();
    while (seenCount < N) {
        //The search Q
        LinkedList<Node> Q = new LinkedList<>();
        //The component-list
        LinkedList<Node> component = new LinkedList<>();
        //Seed the seach Q
        NodeIterable iter = graph.getNodes();
        for (Node first : iter) {
            if (color[indicies.get(first)] == 0) {
                Q.add(first);
                iter.doBreak();
                break;
            }
        }
        //While there are more nodes to search
        while (!Q.isEmpty()) {
            if (isCanceled) {
                return new LinkedList<>();
            }
            //Get the next Node and add it to the component list
            Node u = Q.removeFirst();
            component.add(u);
            //Iterate over all of u's neighbors
            EdgeIterable edgeIter = graph.getEdges(u);
            //For each neighbor
            for (Edge edge : edgeIter) {
                Node reachable = graph.getOpposite(u, edge);
                int id = indicies.get(reachable);
                //If this neighbor is unvisited
                if (color[id] == 0) {
                    color[id] = 1;
                    //Add it to the search Q
                    Q.addLast(reachable);
                    //Mark it as used 
                    Progress.progress(progress, seenCount);
                }
            }
            color[indicies.get(u)] = 2;
            seenCount++;
        }
        components.add(component);
    }
    return components;
}
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) LinkedList(java.util.LinkedList)

Example 2 with NodeIterable

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

the class ExporterPajek method exportData.

private void exportData(Graph graph) throws Exception {
    int max = graph.getNodeCount(), i = 1;
    HashMap<String, Integer> idx = new HashMap<>(3 * max / 2 + 1);
    Progress.start(progressTicket, max);
    writer.append("*Vertices " + max + "\n");
    NodeIterable nodeIterable = graph.getNodes();
    for (Node node : nodeIterable) {
        writer.append(Integer.toString(i));
        writer.append(" \"" + node.getLabel() + "\"");
        if (exportPosition) {
            writer.append(" " + node.x() + " " + node.y() + " " + node.z());
        }
        writer.append("\n");
        // assigns Ids from the interval [1..max]
        idx.put(node.getId().toString(), i++);
        if (cancel) {
            nodeIterable.doBreak();
            return;
        }
    }
    if (graph.isUndirected()) {
        writer.append("*Edges\n");
    } else {
        writer.append("*Arcs\n");
    }
    EdgeIterable edgeIterable = graph.getEdges();
    for (Edge edge : edgeIterable) {
        if (cancel) {
            edgeIterable.doBreak();
            return;
        }
        writer.append(Integer.toString(idx.get(edge.getSource().getId().toString())) + " ");
        writer.append(Integer.toString(idx.get(edge.getTarget().getId().toString())));
        if (exportEdgeWeight) {
            writer.append(" " + edge.getWeight());
        }
        writer.append("\n");
        Progress.progress(progressTicket);
    }
    Progress.finish(progressTicket);
}
Also used : NodeIterable(org.gephi.graph.api.NodeIterable) HashMap(java.util.HashMap) EdgeIterable(org.gephi.graph.api.EdgeIterable) Node(org.gephi.graph.api.Node) Edge(org.gephi.graph.api.Edge)

Example 3 with NodeIterable

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

the class ExporterVNA method calculateMinMaxForNormalization.

private void calculateMinMaxForNormalization(Graph graph) {
    minX = Double.POSITIVE_INFINITY;
    maxX = Double.NEGATIVE_INFINITY;
    minY = Double.POSITIVE_INFINITY;
    maxY = Double.NEGATIVE_INFINITY;
    minSize = Double.POSITIVE_INFINITY;
    maxSize = Double.NEGATIVE_INFINITY;
    NodeIterable nodeIterable = graph.getNodes();
    for (Node node : nodeIterable) {
        if (cancel) {
            nodeIterable.doBreak();
            break;
        }
        minX = Math.min(minX, node.x());
        maxX = Math.max(maxX, node.x());
        minY = Math.min(minY, node.y());
        maxY = Math.max(maxY, node.y());
        minSize = Math.min(minSize, node.r());
        maxSize = Math.max(maxSize, node.r());
    }
}
Also used : NodeIterable(org.gephi.graph.api.NodeIterable) Node(org.gephi.graph.api.Node)

Example 4 with NodeIterable

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

the class ExporterGML method computeNormalizeValues.

private void computeNormalizeValues(Graph graph) {
    minX = Double.MAX_VALUE;
    minY = Double.MAX_VALUE;
    minZ = Double.MAX_VALUE;
    maxX = Double.MIN_VALUE;
    maxY = Double.MIN_VALUE;
    maxZ = Double.MIN_VALUE;
    minSize = Double.MAX_VALUE;
    maxSize = Double.MIN_VALUE;
    NodeIterable nodeIterable = graph.getNodes();
    for (Node node : nodeIterable) {
        if (cancel) {
            nodeIterable.doBreak();
            break;
        }
        minX = Math.min(minX, node.x());
        minY = Math.min(minY, node.y());
        minZ = Math.min(minZ, node.z());
        maxX = Math.max(maxX, node.x());
        maxY = Math.max(maxY, node.y());
        maxZ = Math.max(maxZ, node.z());
        minSize = Math.min(minSize, node.size());
        maxSize = Math.max(maxSize, node.size());
    }
}
Also used : NodeIterable(org.gephi.graph.api.NodeIterable) Node(org.gephi.graph.api.Node)

Example 5 with NodeIterable

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

the class ClusteringCoefficient method computeNodeClusteringCoefficient.

private float computeNodeClusteringCoefficient(Graph graph, Node node, boolean directed) {
    float nodeCC = 0;
    int neighborhood = 0;
    NodeIterable neighbors1 = graph.getNeighbors(node);
    for (Node neighbor1 : neighbors1) {
        neighborhood++;
        NodeIterable neighbors2 = graph.getNeighbors(node);
        for (Node neighbor2 : neighbors2) {
            nodeCC = increaseCCifNesessary(graph, neighbor1, neighbor2, directed, nodeCC);
        }
    }
    nodeCC /= 2.0;
    if (neighborhood > 1) {
        float cc = nodeCC / (.5f * neighborhood * (neighborhood - 1));
        if (directed) {
            cc = nodeCC / (neighborhood * (neighborhood - 1));
        }
        return cc;
    } else {
        return -1.f;
    }
}
Also used : NodeIterable(org.gephi.graph.api.NodeIterable) 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