Search in sources :

Example 41 with GraphModel

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

use of org.gephi.graph.api.GraphModel 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)

Example 43 with GraphModel

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

the class GraphDensityNGTest method testDirectedPathGraphDensity.

@Test
public void testDirectedPathGraphDensity() {
    GraphModel graphModel = GraphGenerator.generatePathDirectedGraph(2);
    DirectedGraph graph = graphModel.getDirectedGraph();
    GraphDensity d = new GraphDensity();
    double density = d.calculateDensity(graph, true);
    assertEquals(density, 0.5);
}
Also used : DirectedGraph(org.gephi.graph.api.DirectedGraph) GraphModel(org.gephi.graph.api.GraphModel) Test(org.testng.annotations.Test)

Example 44 with GraphModel

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

the class GraphDensityNGTest method testCyclicGraphDensity.

@Test
public void testCyclicGraphDensity() {
    GraphModel graphModel = GraphGenerator.generateCyclicUndirectedGraph(6);
    Graph graph = graphModel.getGraph();
    GraphDensity d = new GraphDensity();
    double density = d.calculateDensity(graph, false);
    assertEquals(density, 0.4);
}
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 45 with GraphModel

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

the class GraphDensityNGTest method testDirectedCompleteGraphDensity.

@Test
public void testDirectedCompleteGraphDensity() {
    GraphModel graphModel = GraphGenerator.generateCompleteDirectedGraph(5);
    DirectedGraph graph = graphModel.getDirectedGraph();
    GraphDensity d = new GraphDensity();
    double density = d.calculateDensity(graph, true);
    assertEquals(density, 1.0);
}
Also used : DirectedGraph(org.gephi.graph.api.DirectedGraph) GraphModel(org.gephi.graph.api.GraphModel) Test(org.testng.annotations.Test)

Aggregations

GraphModel (org.gephi.graph.api.GraphModel)235 Node (org.gephi.graph.api.Node)169 Test (org.testng.annotations.Test)168 UndirectedGraph (org.gephi.graph.api.UndirectedGraph)115 GraphController (org.gephi.graph.api.GraphController)105 DirectedGraph (org.gephi.graph.api.DirectedGraph)92 Edge (org.gephi.graph.api.Edge)80 Graph (org.gephi.graph.api.Graph)57 HashMap (java.util.HashMap)52 Column (org.gephi.graph.api.Column)16 LinkedList (java.util.LinkedList)12 ArrayList (java.util.ArrayList)11 FilterBuilder (org.gephi.filters.spi.FilterBuilder)6 GraphView (org.gephi.graph.api.GraphView)6 XMLStreamException (javax.xml.stream.XMLStreamException)5 IOException (java.io.IOException)4 AppearanceController (org.gephi.appearance.api.AppearanceController)4 AppearanceModel (org.gephi.appearance.api.AppearanceModel)4 TimeFormat (org.gephi.graph.api.TimeFormat)4 Element (org.gephi.graph.api.Element)3