Search in sources :

Example 61 with GraphModel

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

the class WeightedDegreeNGTest 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");
    WeightedDegree d = new WeightedDegree();
    d.execute(graph);
    double degree1 = (Double) n1.getAttribute(WeightedDegree.WDEGREE);
    double degree2 = (Double) n2.getAttribute(WeightedDegree.WDEGREE);
    double avDegree = d.getAverageDegree();
    double expectedAvDegree = 1.6667;
    double diff = Math.abs(avDegree - expectedAvDegree);
    assertEquals(degree1, 5.0);
    assertEquals(degree2, 1.0);
    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 62 with GraphModel

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

the class WeightedDegreeNGTest method testDirectedStarOutGraphDegree.

@Test
public void testDirectedStarOutGraphDegree() {
    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);
    }
    DirectedGraph graph = graphModel.getDirectedGraph();
    Node n1 = graph.getNode("0");
    Node n3 = graph.getNode("2");
    WeightedDegree d = new WeightedDegree();
    d.execute(graph);
    double inDegree1 = (Double) n1.getAttribute(WeightedDegree.WINDEGREE);
    double outDegree1 = (Double) n1.getAttribute(WeightedDegree.WOUTDEGREE);
    double degree3 = (Double) n3.getAttribute(WeightedDegree.WDEGREE);
    assertEquals(inDegree1, 0.0);
    assertEquals(outDegree1, 5.0);
    assertEquals(degree3, 1.0);
}
Also used : DirectedGraph(org.gephi.graph.api.DirectedGraph) GraphModel(org.gephi.graph.api.GraphModel) Node(org.gephi.graph.api.Node) Edge(org.gephi.graph.api.Edge) GraphController(org.gephi.graph.api.GraphController) Test(org.testng.annotations.Test)

Example 63 with GraphModel

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

the class WeightedDegreeNGTest method testOneNodeDegree.

@Test
public void testOneNodeDegree() {
    GraphModel graphModel = GraphGenerator.generateNullUndirectedGraph(1);
    Graph graph = graphModel.getGraph();
    Node n = graph.getNode("0");
    WeightedDegree d = new WeightedDegree();
    d.execute(graph);
    assertEquals(n.getAttribute(WeightedDegree.WDEGREE), 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 64 with GraphModel

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

the class WeightedDegreeNGTest method testSelfLoopGraphDegree.

@Test
public void testSelfLoopGraphDegree() {
    GraphModel graphModel = GraphGenerator.generateSelfLoopUndirectedGraph(1);
    Graph graph = graphModel.getGraph();
    Node n = graph.getNode("0");
    WeightedDegree d = new WeightedDegree();
    d.execute(graph);
    assertEquals(n.getAttribute(WeightedDegree.WDEGREE), 2.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 65 with GraphModel

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

the class WeightedDegreeNGTest method testSelfLoopDirectedGraphDegree.

@Test
public void testSelfLoopDirectedGraphDegree() {
    GraphModel graphModel = GraphGenerator.generateSelfLoopDirectedGraph(1);
    DirectedGraph graph = graphModel.getDirectedGraph();
    Node n = graph.getNode("0");
    WeightedDegree d = new WeightedDegree();
    d.execute(graph);
    assertEquals(n.getAttribute(WeightedDegree.WDEGREE), 2.0);
    assertEquals(n.getAttribute(WeightedDegree.WINDEGREE), 1.0);
    assertEquals(n.getAttribute(WeightedDegree.WOUTDEGREE), 1.0);
}
Also used : DirectedGraph(org.gephi.graph.api.DirectedGraph) GraphModel(org.gephi.graph.api.GraphModel) Node(org.gephi.graph.api.Node) 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