use of org.gephi.graph.api.GraphModel 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.GraphModel 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.GraphModel 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.GraphModel in project gephi by gephi.
the class MergeColumnsUI method loadColumns.
private void loadColumns() {
availableColumnsModel.clear();
columnsToMergeModel.clear();
GraphModel am = Lookup.getDefault().lookup(GraphController.class).getGraphModel();
Column[] columns;
if (mode == Mode.NODES_TABLE) {
table = am.getNodeTable();
columns = table.toArray();
} else {
table = am.getEdgeTable();
columns = table.toArray();
}
for (Column column : columns) {
availableColumnsModel.addElement(new ColumnWrapper(column));
}
availableColumnsList.setModel(availableColumnsModel);
columnsToMergeList.setModel(columnsToMergeModel);
}
use of org.gephi.graph.api.GraphModel in project gephi by gephi.
the class InterEdgesBuilder method getBuilders.
@Override
public FilterBuilder[] getBuilders(Workspace workspace) {
List<FilterBuilder> builders = new ArrayList<>();
GraphModel gm = Lookup.getDefault().lookup(GraphController.class).getGraphModel(workspace);
Graph graph = gm.getGraph();
AppearanceModel am = Lookup.getDefault().lookup(AppearanceController.class).getModel(workspace);
//Force refresh
am.getNodeFunctions(graph);
for (Column nodeCol : gm.getNodeTable()) {
if (!nodeCol.isProperty()) {
if (am.getNodePartition(graph, nodeCol) != null) {
InterEdgesFilterBuilder builder = new InterEdgesFilterBuilder(nodeCol, am);
builders.add(builder);
}
}
}
return builders.toArray(new FilterBuilder[0]);
}
Aggregations