Search in sources :

Example 21 with UndirectedGraph

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

the class GraphDistanceNGTest method testCyclic5GraphBetweenness.

@Test
public void testCyclic5GraphBetweenness() {
    GraphModel graphModel = GraphGenerator.generateCyclicUndirectedGraph(5);
    GraphDistance d = new GraphDistance();
    d.initializeStartValues();
    UndirectedGraph undirectedGraph = graphModel.getUndirectedGraph();
    HashMap<Node, Integer> indicies = d.createIndiciesMap(undirectedGraph);
    HashMap<String, double[]> metricsMap = (HashMap) d.calculateDistanceMetrics(graphModel.getGraph(), indicies, false, false);
    double[] betweenness = metricsMap.get(GraphDistance.BETWEENNESS);
    Node n4 = undirectedGraph.getNode("3");
    int index4 = indicies.get(n4);
    assertEquals(betweenness[index4], 1.0, TOLERANCE);
}
Also used : HashMap(java.util.HashMap) GraphModel(org.gephi.graph.api.GraphModel) UndirectedGraph(org.gephi.graph.api.UndirectedGraph) Node(org.gephi.graph.api.Node) Test(org.testng.annotations.Test)

Example 22 with UndirectedGraph

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

the class GraphDistanceNGTest method testCompleteGraphRadius.

@Test
public void testCompleteGraphRadius() {
    GraphModel graphModel = GraphGenerator.generateCompleteUndirectedGraph(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, 1.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 23 with UndirectedGraph

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

the class GraphDistanceNGTest method testNullGraphBetweenness.

@Test
public void testNullGraphBetweenness() {
    GraphModel graphModel = GraphGenerator.generateNullUndirectedGraph(5);
    GraphDistance d = new GraphDistance();
    d.initializeStartValues();
    UndirectedGraph undirectedGraph = graphModel.getUndirectedGraph();
    HashMap<Node, Integer> indicies = d.createIndiciesMap(undirectedGraph);
    HashMap<String, double[]> metricsMap = (HashMap) d.calculateDistanceMetrics(graphModel.getGraph(), indicies, false, false);
    double[] betweenness = metricsMap.get(GraphDistance.BETWEENNESS);
    Node n1 = undirectedGraph.getNode("0");
    int index1 = indicies.get(n1);
    assertEquals(betweenness[index1], 0.0, TOLERANCE);
}
Also used : HashMap(java.util.HashMap) GraphModel(org.gephi.graph.api.GraphModel) UndirectedGraph(org.gephi.graph.api.UndirectedGraph) Node(org.gephi.graph.api.Node) Test(org.testng.annotations.Test)

Example 24 with UndirectedGraph

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

the class GraphDistanceNGTest method testStarGraphAvPathLength.

@Test
public void testStarGraphAvPathLength() {
    GraphModel graphModel = GraphGenerator.generateStarUndirectedGraph(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 averageDegree = d.getPathLength();
    double res = 1.6667;
    double diff = Math.abs(averageDegree - res);
    assertEquals(averageDegree, res, 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 25 with UndirectedGraph

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

the class GraphDensityNGTest method testSelfLoopNodeDensity.

@Test
public void testSelfLoopNodeDensity() {
    GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getGraphModel();
    UndirectedGraph undirectedGraph = graphModel.getUndirectedGraph();
    Node currentNode = graphModel.factory().newNode("0");
    undirectedGraph.addNode(currentNode);
    Edge currentEdge = graphModel.factory().newEdge(currentNode, currentNode, false);
    undirectedGraph.addEdge(currentEdge);
    Graph graph = graphModel.getGraph();
    GraphDensity d = new GraphDensity();
    double density = d.calculateDensity(graph, false);
    assertEquals(density, Double.POSITIVE_INFINITY);
}
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) UndirectedGraph(org.gephi.graph.api.UndirectedGraph) Node(org.gephi.graph.api.Node) Edge(org.gephi.graph.api.Edge) GraphController(org.gephi.graph.api.GraphController) Test(org.testng.annotations.Test)

Aggregations

UndirectedGraph (org.gephi.graph.api.UndirectedGraph)100 GraphModel (org.gephi.graph.api.GraphModel)99 Node (org.gephi.graph.api.Node)97 Test (org.testng.annotations.Test)93 Edge (org.gephi.graph.api.Edge)44 GraphController (org.gephi.graph.api.GraphController)39 HashMap (java.util.HashMap)36 DirectedGraph (org.gephi.graph.api.DirectedGraph)13 Graph (org.gephi.graph.api.Graph)7 LinkedList (java.util.LinkedList)6