Search in sources :

Example 66 with Node

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

the class GraphDistanceNGTest method testDirectedStarOutGraphCloseness.

@Test
public void testDirectedStarOutGraphCloseness() {
    GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getGraphModel();
    DirectedGraph directedGraph = graphModel.getDirectedGraph();
    Node firstNode = graphModel.factory().newNode("0");
    directedGraph.addNode(firstNode);
    for (int i = 1; i <= 5; i++) {
        Node currentNode = graphModel.factory().newNode(((Integer) i).toString());
        directedGraph.addNode(currentNode);
        Edge currentEdge = graphModel.factory().newEdge(firstNode, currentNode);
        directedGraph.addEdge(currentEdge);
    }
    GraphDistance d = new GraphDistance();
    d.initializeStartValues();
    HashMap<Node, Integer> indicies = d.createIndiciesMap(graphModel.getGraph());
    HashMap<String, double[]> metricsMap = (HashMap) d.calculateDistanceMetrics(graphModel.getGraph(), indicies, true, false);
    double[] closeness = metricsMap.get(GraphDistance.CLOSENESS);
    Node n1 = directedGraph.getNode("0");
    Node n6 = directedGraph.getNode("5");
    int index1 = indicies.get(n1);
    int index6 = indicies.get(n6);
    assertEquals(closeness[index1], 1.0, TOLERANCE);
    assertEquals(closeness[index6], 0.0, TOLERANCE);
}
Also used : HashMap(java.util.HashMap) 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 67 with Node

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

the class GraphDistanceNGTest method testNullGraphRadius.

@Test
public void testNullGraphRadius() {
    GraphModel graphModel = GraphGenerator.generateNullUndirectedGraph(5);
    GraphDistance d = new GraphDistance();
    d.initializeStartValues();
    UndirectedGraph undirectedGraph = graphModel.getUndirectedGraph();
    HashMap<Node, Integer> indicies = d.createIndiciesMap(undirectedGraph);
    d.calculateDistanceMetrics(graphModel.getGraph(), indicies, false, false);
    double radius = d.getRadius();
    assertEquals(radius, 0.0, TOLERANCE);
}
Also used : GraphModel(org.gephi.graph.api.GraphModel) UndirectedGraph(org.gephi.graph.api.UndirectedGraph) Node(org.gephi.graph.api.Node) Test(org.testng.annotations.Test)

Example 68 with Node

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

the class EigenvectorCentrality method saveCalculatedValues.

private void saveCalculatedValues(Graph graph, Column attributeColumn, HashMap<Integer, Node> indicies, double[] eigCenrtalities) {
    int N = graph.getNodeCount();
    for (int i = 0; i < N; i++) {
        Node s = indicies.get(i);
        s.setAttribute(attributeColumn, eigCenrtalities[i]);
    }
}
Also used : Node(org.gephi.graph.api.Node)

Example 69 with Node

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

the class EigenvectorCentrality method fillIndiciesMaps.

public void fillIndiciesMaps(Graph graph, double[] eigCentralities, HashMap<Integer, Node> indicies, HashMap<Node, Integer> invIndicies) {
    if (indicies == null || invIndicies == null) {
        return;
    }
    int count = 0;
    for (Node u : graph.getNodes()) {
        indicies.put(count, u);
        invIndicies.put(u, count);
        eigCentralities[count] = 1;
        count++;
    }
}
Also used : Node(org.gephi.graph.api.Node)

Example 70 with Node

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

the class Hits method updateAutorithy.

void updateAutorithy(Graph graph, double[] newValues, double[] hubValues, boolean isDirected, Map<Node, Integer> indices) {
    double norm = 0;
    for (Node q : indices.keySet()) {
        double auth = 0;
        EdgeIterable edge_iter;
        if (isDirected) {
            edge_iter = ((DirectedGraph) graph).getInEdges(q);
        } else {
            edge_iter = graph.getEdges(q);
        }
        for (Edge edge : edge_iter) {
            if (!edge.isSelfLoop()) {
                Node p = graph.getOpposite(q, edge);
                auth += hubValues[indices.get(p)];
            }
        }
        newValues[indices.get(q)] = auth;
        norm += auth * auth;
        if (isCanceled) {
            return;
        }
    }
    norm = Math.sqrt(norm);
    if (norm > 0) {
        for (int i = 0; i < newValues.length; i++) {
            newValues[i] = newValues[i] / norm;
        }
    }
}
Also used : EdgeIterable(org.gephi.graph.api.EdgeIterable) Node(org.gephi.graph.api.Node) Edge(org.gephi.graph.api.Edge)

Aggregations

Node (org.gephi.graph.api.Node)301 GraphModel (org.gephi.graph.api.GraphModel)169 Test (org.testng.annotations.Test)152 Edge (org.gephi.graph.api.Edge)116 UndirectedGraph (org.gephi.graph.api.UndirectedGraph)102 DirectedGraph (org.gephi.graph.api.DirectedGraph)84 GraphController (org.gephi.graph.api.GraphController)82 HashMap (java.util.HashMap)62 Graph (org.gephi.graph.api.Graph)50 Column (org.gephi.graph.api.Column)22 LinkedList (java.util.LinkedList)17 NodeIterable (org.gephi.graph.api.NodeIterable)12 EdgeIterable (org.gephi.graph.api.EdgeIterable)10 Table (org.gephi.graph.api.Table)10 ArrayList (java.util.ArrayList)7 HashSet (java.util.HashSet)6 GraphElementsController (org.gephi.datalab.api.GraphElementsController)6 Color (java.awt.Color)5 DataTablesController (org.gephi.datalab.api.datatables.DataTablesController)5 MouseClickEventListener (org.gephi.tools.spi.MouseClickEventListener)4