Search in sources :

Example 31 with Node

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

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

the class ConnectedComponents method createIndiciesMap.

public HashMap<Node, Integer> createIndiciesMap(Graph graph) {
    HashMap<Node, Integer> indicies = new HashMap<>();
    int index = 0;
    for (Node s : graph.getNodes()) {
        indicies.put(s, index);
        index++;
    }
    return indicies;
}
Also used : HashMap(java.util.HashMap) Node(org.gephi.graph.api.Node)

Example 33 with Node

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

the class EigenvectorCentrality method computeMaxValueAndTempValues.

private double computeMaxValueAndTempValues(Graph graph, HashMap<Integer, Node> indicies, HashMap<Node, Integer> invIndicies, double[] tempValues, double[] centralityValues, boolean directed) {
    double max = 0.;
    int N = graph.getNodeCount();
    for (int i = 0; i < N; i++) {
        Node u = indicies.get(i);
        EdgeIterable iter;
        if (directed) {
            iter = ((DirectedGraph) graph).getInEdges(u);
        } else {
            iter = graph.getEdges(u);
        }
        for (Edge e : iter) {
            Node v = graph.getOpposite(u, e);
            Integer id = invIndicies.get(v);
            tempValues[i] += centralityValues[id];
        }
        max = Math.max(max, tempValues[i]);
        if (isCanceled) {
            return max;
        }
    }
    return max;
}
Also used : EdgeIterable(org.gephi.graph.api.EdgeIterable) Node(org.gephi.graph.api.Node) Edge(org.gephi.graph.api.Edge)

Example 34 with Node

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

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

the class ConnectedComponentsNGTest method testNullGraphWeeklyConnectedComponents.

@Test
public void testNullGraphWeeklyConnectedComponents() {
    GraphModel graphModel = GraphGenerator.generateNullUndirectedGraph(5);
    UndirectedGraph graph = graphModel.getUndirectedGraph();
    Node n0 = graph.getNode("0");
    Node n1 = graph.getNode("1");
    Node n2 = graph.getNode("2");
    Node n3 = graph.getNode("3");
    Node n4 = graph.getNode("4");
    ConnectedComponents c = new ConnectedComponents();
    HashMap<Node, Integer> indicies = new HashMap<>();
    indicies.put(n0, 0);
    indicies.put(n1, 1);
    indicies.put(n2, 2);
    indicies.put(n3, 3);
    indicies.put(n4, 4);
    LinkedList<LinkedList<Node>> components = c.computeWeeklyConnectedComponents(graph, indicies);
    assertEquals(components.size(), 5);
}
Also used : HashMap(java.util.HashMap) GraphModel(org.gephi.graph.api.GraphModel) UndirectedGraph(org.gephi.graph.api.UndirectedGraph) Node(org.gephi.graph.api.Node) LinkedList(java.util.LinkedList) Test(org.testng.annotations.Test)

Aggregations

Node (org.gephi.graph.api.Node)314 GraphModel (org.gephi.graph.api.GraphModel)173 Test (org.testng.annotations.Test)156 Edge (org.gephi.graph.api.Edge)122 UndirectedGraph (org.gephi.graph.api.UndirectedGraph)106 DirectedGraph (org.gephi.graph.api.DirectedGraph)83 GraphController (org.gephi.graph.api.GraphController)83 HashMap (java.util.HashMap)66 Graph (org.gephi.graph.api.Graph)51 NodeIterable (org.gephi.graph.api.NodeIterable)23 LinkedList (java.util.LinkedList)22 Column (org.gephi.graph.api.Column)22 EdgeIterable (org.gephi.graph.api.EdgeIterable)16 Table (org.gephi.graph.api.Table)10 HashSet (java.util.HashSet)8 ArrayList (java.util.ArrayList)7 Color (java.awt.Color)6 GraphElementsController (org.gephi.datalab.api.GraphElementsController)6 DataTablesController (org.gephi.datalab.api.datatables.DataTablesController)5 Interval (org.gephi.graph.api.Interval)5