use of org.gephi.graph.api.UndirectedGraph in project gephi by gephi.
the class GraphDistanceNGTest method testSpecial2DirectedGraphDiameter.
@Test
public void testSpecial2DirectedGraphDiameter() {
GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getGraphModel();
DirectedGraph directedGraph = graphModel.getDirectedGraph();
Node node1 = graphModel.factory().newNode("0");
Node node2 = graphModel.factory().newNode("1");
Node node3 = graphModel.factory().newNode("2");
Node node4 = graphModel.factory().newNode("3");
Node node5 = graphModel.factory().newNode("4");
directedGraph.addNode(node1);
directedGraph.addNode(node2);
directedGraph.addNode(node3);
directedGraph.addNode(node4);
directedGraph.addNode(node5);
Edge edge12 = graphModel.factory().newEdge(node1, node2);
Edge edge14 = graphModel.factory().newEdge(node1, node4);
Edge edge23 = graphModel.factory().newEdge(node2, node3);
Edge edge25 = graphModel.factory().newEdge(node2, node5);
Edge edge35 = graphModel.factory().newEdge(node3, node5);
Edge edge43 = graphModel.factory().newEdge(node4, node3);
Edge edge51 = graphModel.factory().newEdge(node5, node1);
Edge edge54 = graphModel.factory().newEdge(node5, node4);
directedGraph.addEdge(edge12);
directedGraph.addEdge(edge14);
directedGraph.addEdge(edge23);
directedGraph.addEdge(edge25);
directedGraph.addEdge(edge35);
directedGraph.addEdge(edge43);
directedGraph.addEdge(edge51);
directedGraph.addEdge(edge54);
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 diameter = d.getDiameter();
assertEquals(diameter, 4.0, TOLERANCE);
}
use of org.gephi.graph.api.UndirectedGraph in project gephi by gephi.
the class GraphDistanceNGTest method testSpecial2DirectedGraphRadius.
@Test
public void testSpecial2DirectedGraphRadius() {
GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getGraphModel();
DirectedGraph directedGraph = graphModel.getDirectedGraph();
Node node1 = graphModel.factory().newNode("0");
Node node2 = graphModel.factory().newNode("1");
Node node3 = graphModel.factory().newNode("2");
Node node4 = graphModel.factory().newNode("3");
Node node5 = graphModel.factory().newNode("4");
directedGraph.addNode(node1);
directedGraph.addNode(node2);
directedGraph.addNode(node3);
directedGraph.addNode(node4);
directedGraph.addNode(node5);
Edge edge12 = graphModel.factory().newEdge(node1, node2);
Edge edge14 = graphModel.factory().newEdge(node1, node4);
Edge edge23 = graphModel.factory().newEdge(node2, node3);
Edge edge25 = graphModel.factory().newEdge(node2, node5);
Edge edge35 = graphModel.factory().newEdge(node3, node5);
Edge edge43 = graphModel.factory().newEdge(node4, node3);
Edge edge51 = graphModel.factory().newEdge(node5, node1);
Edge edge54 = graphModel.factory().newEdge(node5, node4);
directedGraph.addEdge(edge12);
directedGraph.addEdge(edge14);
directedGraph.addEdge(edge23);
directedGraph.addEdge(edge25);
directedGraph.addEdge(edge35);
directedGraph.addEdge(edge43);
directedGraph.addEdge(edge51);
directedGraph.addEdge(edge54);
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, 2.0, TOLERANCE);
}
use of org.gephi.graph.api.UndirectedGraph in project gephi by gephi.
the class GraphDistanceNGTest method testNullGraphDiameter.
@Test
public void testNullGraphDiameter() {
GraphModel graphModel = GraphGenerator.generateNullUndirectedGraph(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 diameter = d.getDiameter();
assertEquals(diameter, 0.0, TOLERANCE);
}
use of org.gephi.graph.api.UndirectedGraph in project gephi by gephi.
the class GraphDistanceNGTest method testCyclicGraphAvPathLength.
@Test
public void testCyclicGraphAvPathLength() {
GraphModel graphModel = GraphGenerator.generateCyclicUndirectedGraph(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();
assertEquals(averageDegree, 1.5, TOLERANCE);
}
use of org.gephi.graph.api.UndirectedGraph in project gephi by gephi.
the class GraphGenerator method generatePathUndirectedGraph.
public static GraphModel generatePathUndirectedGraph(int n) {
GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getGraphModel();
UndirectedGraph undirectedGraph = graphModel.getUndirectedGraph();
if (n <= 0) {
return graphModel;
}
Node firstNode = graphModel.factory().newNode("0");
undirectedGraph.addNode(firstNode);
Node prevNode = firstNode;
for (int i = 1; i < n; i++) {
Node currentNode = graphModel.factory().newNode(((Integer) i).toString());
undirectedGraph.addNode(currentNode);
Edge currentEdge = graphModel.factory().newEdge(prevNode, currentNode, false);
undirectedGraph.addEdge(currentEdge);
prevNode = currentNode;
}
return graphModel;
}
Aggregations