Search in sources :

Example 26 with Graph

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

the class DegreeNGTest method testNullGraphDegree.

@Test
public void testNullGraphDegree() {
    GraphModel graphModel = GraphGenerator.generateNullUndirectedGraph(5);
    Graph graph = graphModel.getGraph();
    Node n = graph.getNode("1");
    Degree d = new Degree();
    int degree = d.calculateDegree(graph, n);
    double avDegree = d.calculateAverageDegree(graph, false, false);
    assertEquals(degree, 0);
    assertEquals(avDegree, 0.0);
}
Also used : Graph(org.gephi.graph.api.Graph) DirectedGraph(org.gephi.graph.api.DirectedGraph) GraphModel(org.gephi.graph.api.GraphModel) Node(org.gephi.graph.api.Node) Test(org.testng.annotations.Test)

Example 27 with Graph

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

the class DegreeNGTest method testStarGraphDegree.

@Test
public void testStarGraphDegree() {
    GraphModel graphModel = GraphGenerator.generateStarUndirectedGraph(5);
    Graph graph = graphModel.getGraph();
    Node n1 = graph.getNode("0");
    Node n2 = graph.getNode("1");
    Degree d = new Degree();
    int degree1 = d.calculateDegree(graph, n1);
    int degree2 = d.calculateDegree(graph, n2);
    double avDegree = d.calculateAverageDegree(graph, false, false);
    double expectedAvDegree = 1.6667;
    double diff = Math.abs(avDegree - expectedAvDegree);
    assertEquals(degree1, 5);
    assertEquals(degree2, 1);
    assertTrue(diff < 0.001);
}
Also used : Graph(org.gephi.graph.api.Graph) DirectedGraph(org.gephi.graph.api.DirectedGraph) GraphModel(org.gephi.graph.api.GraphModel) Node(org.gephi.graph.api.Node) Test(org.testng.annotations.Test)

Example 28 with Graph

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

the class EigenvectorCentrality method execute.

/**
     *
     * @param graphModel
     */
@Override
public void execute(GraphModel graphModel) {
    isDirected = graphModel.isDirected();
    isCanceled = false;
    Graph graph;
    if (isDirected) {
        graph = graphModel.getDirectedGraphVisible();
    } else {
        graph = graphModel.getUndirectedGraphVisible();
    }
    execute(graph);
}
Also used : Graph(org.gephi.graph.api.Graph) DirectedGraph(org.gephi.graph.api.DirectedGraph)

Example 29 with Graph

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

the class ClusteringCoefficientNGTest method testStarGraphClusteringCoefficient.

@Test
public void testStarGraphClusteringCoefficient() {
    GraphModel graphModel = GraphGenerator.generateStarUndirectedGraph(5);
    Graph graph = graphModel.getGraph();
    ClusteringCoefficient cc = new ClusteringCoefficient();
    cc.setDirected(false);
    ArrayWrapper[] network = new ArrayWrapper[6];
    int[] triangles = new int[6];
    double[] nodeClustering = new double[6];
    HashMap<String, Double> results = cc.computeClusteringCoefficient(graph, network, triangles, nodeClustering, false);
    double avClusteringCoefficient = results.get("clusteringCoefficient");
    assertEquals(avClusteringCoefficient, 0.0);
}
Also used : Graph(org.gephi.graph.api.Graph) UndirectedGraph(org.gephi.graph.api.UndirectedGraph) DirectedGraph(org.gephi.graph.api.DirectedGraph) GraphModel(org.gephi.graph.api.GraphModel) Test(org.testng.annotations.Test)

Example 30 with Graph

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

the class DegreeNGTest method testOneNodeDegree.

@Test
public void testOneNodeDegree() {
    GraphModel graphModel = GraphGenerator.generateNullUndirectedGraph(1);
    Graph graph = graphModel.getGraph();
    Node n = graph.getNode("0");
    Degree d = new Degree();
    int degree = d.calculateDegree(graph, n);
    assertEquals(degree, 0);
}
Also used : Graph(org.gephi.graph.api.Graph) DirectedGraph(org.gephi.graph.api.DirectedGraph) GraphModel(org.gephi.graph.api.GraphModel) Node(org.gephi.graph.api.Node) Test(org.testng.annotations.Test)

Aggregations

Graph (org.gephi.graph.api.Graph)104 GraphModel (org.gephi.graph.api.GraphModel)57 Node (org.gephi.graph.api.Node)50 DirectedGraph (org.gephi.graph.api.DirectedGraph)43 Test (org.testng.annotations.Test)36 GraphController (org.gephi.graph.api.GraphController)27 UndirectedGraph (org.gephi.graph.api.UndirectedGraph)24 Edge (org.gephi.graph.api.Edge)21 Column (org.gephi.graph.api.Column)9 ArrayList (java.util.ArrayList)8 Function (org.gephi.appearance.api.Function)6 GraphView (org.gephi.graph.api.GraphView)6 AttributeFunction (org.gephi.appearance.api.AttributeFunction)5 AppearanceController (org.gephi.appearance.api.AppearanceController)4 AppearanceModel (org.gephi.appearance.api.AppearanceModel)4 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 TransformerUI (org.gephi.appearance.spi.TransformerUI)3 GraphElementsController (org.gephi.datalab.api.GraphElementsController)3 DataTablesController (org.gephi.datalab.api.datatables.DataTablesController)3