Search in sources :

Example 41 with UndirectedGraph

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

the class GraphDistanceNGTest method testStarGraphBetweenness.

@Test
public void testStarGraphBetweenness() {
    GraphModel graphModel = GraphGenerator.generateStarUndirectedGraph(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");
    Node n2 = undirectedGraph.getNode("1");
    int index1 = indicies.get(n1);
    int index2 = indicies.get(n2);
    assertEquals(betweenness[index1], 10.0, TOLERANCE);
    assertEquals(betweenness[index2], 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 42 with UndirectedGraph

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

the class GraphDistanceNGTest method testOneNodeRadius.

@Test
public void testOneNodeRadius() {
    GraphModel graphModel = GraphGenerator.generateNullUndirectedGraph(1);
    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 43 with UndirectedGraph

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

the class GraphDistanceNGTest method testPathGraphRadius.

@Test
public void testPathGraphRadius() {
    GraphModel graphModel = GraphGenerator.generatePathUndirectedGraph(6);
    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, 3.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 44 with UndirectedGraph

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

the class GraphDistanceNGTest method testStarGraphRadius.

@Test
public void testStarGraphRadius() {
    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 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 45 with UndirectedGraph

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

the class GraphDistanceNGTest method testDirectedCyclicRadius.

@Test
public void testDirectedCyclicRadius() {
    GraphModel graphModel = GraphGenerator.generateCyclicDirectedGraph(5);
    GraphDistance d = new GraphDistance();
    d.initializeStartValues();
    UndirectedGraph undirectedGraph = graphModel.getUndirectedGraph();
    HashMap<Node, Integer> indicies = d.createIndiciesMap(undirectedGraph);
    d.calculateDistanceMetrics(graphModel.getGraph(), indicies, true, false);
    double radius = d.getRadius();
    assertEquals(radius, 4.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)

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