public void testUndirectedAdjacencyList() { UndirectedGraph<Integer, DefaultEdge> g = new Pseudograph<>(DefaultEdge.class); g.addVertex(1); g.addVertex(2); g.addVertex(3); g.addVertex(4); g.addVertex(5); g.addEdge(1, 2); g.addEdge(1, 3); g.addEdge(3, 1); g.addEdge(3, 4); g.addEdge(4, 5); g.addEdge(5, 1); g.addEdge(5, 2); g.addEdge(5, 3); g.addEdge(5, 4); g.addEdge(5, 5); g.addEdge(5, 5); CSVExporter<Integer, DefaultEdge> exporter = new CSVExporter<>(nameProvider, CSVFormat.ADJACENCY_LIST, ';'); StringWriter w = new StringWriter(); exporter.exportGraph(g, w); assertEquals(UNDIRECTED_ADJACENCY_LIST, w.toString()); }
public void testUndirected() { UndirectedGraph<String, DefaultEdge> g = new SimpleGraph<String, DefaultEdge>(DefaultEdge.class); g.addVertex(V1); g.addVertex(V2); g.addEdge(V1, V2); g.addVertex(V3); g.addEdge(V3, V1); StringWriter w = new StringWriter(); exporter.export(w, g); assertEquals(UNDIRECTED, w.toString()); }
public void testAdjacencyUndirected() { UndirectedGraph<String, DefaultEdge> g = new Pseudograph<String, DefaultEdge>(DefaultEdge.class); g.addVertex(V1); g.addVertex(V2); g.addEdge(V1, V2); g.addVertex(V3); g.addEdge(V3, V1); g.addEdge(V1, V1); StringWriter w = new StringWriter(); exporter.exportAdjacencyMatrix(w, g); assertEquals(UNDIRECTED_ADJACENCY, w.toString()); }
public void testLaplacian() { UndirectedGraph<String, DefaultEdge> g = new SimpleGraph<String, DefaultEdge>(DefaultEdge.class); g.addVertex(V1); g.addVertex(V2); g.addEdge(V1, V2); g.addVertex(V3); g.addEdge(V3, V1); StringWriter w = new StringWriter(); exporter.exportLaplacianMatrix(w, g); assertEquals(LAPLACIAN, w.toString()); w = new StringWriter(); exporter.exportNormalizedLaplacianMatrix(w, g); assertEquals(NORMALIZED_LAPLACIAN, w.toString()); }
private void doPoetGraph(String path, String poet) { System.out.println(poet); ProjectController pc = Lookup.getDefault().lookup(ProjectController.class); pc.newProject(); Workspace workspace = pc.getCurrentWorkspace(); GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getModel(); UndirectedGraph directedGraph = graphModel.getUndirectedGraph(); ExportController ec = Lookup.getDefault().lookup(ExportController.class); ArrayList<String> queue = new ArrayList<String>(); ArrayList<Integer> depthqueue = new ArrayList<Integer>(); queue.add(poet); depthqueue.add(0); int depth = 0; int nodecount = 0; while (queue.size() != 0 && depth < 3 && nodecount < 20) { String name = queue.remove(0); depth = depthqueue.remove(0); Node n = directedGraph.getNode(name); if (n == null) { n = graphModel.factory().newNode(name); n.getNodeData().setLabel(name); directedGraph.addNode(n); nodecount++; } Iterator<String> it = edges.get(poet).keySet().iterator(); while (it.hasNext()) { String to = it.next(); Node slave = directedGraph.getNode(to); if (slave == null) { slave = graphModel.factory().newNode(to); slave.getNodeData().setLabel(to); directedGraph.addNode(slave); } Edge e = graphModel.factory().newEdge(n, slave, edges.get(poet).get(to) * 15, false); directedGraph.addEdge(e); queue.add(to); depthqueue.add(depth + 1); } } // Preview PreviewModel previewModel = Lookup.getDefault().lookup(PreviewController.class).getModel(); previewModel.getProperties().putValue(PreviewProperty.SHOW_NODE_LABELS, Boolean.TRUE); previewModel.getProperties().putValue(PreviewProperty.EDGE_COLOR, new EdgeColor(Color.BLUE)); previewModel.getProperties().putValue(PreviewProperty.EDGE_THICKNESS, new Float(0.005f)); previewModel .getProperties() .putValue(PreviewProperty.NODE_LABEL_COLOR, new DependantOriginalColor(Color.RED)); previewModel .getProperties() .putValue( PreviewProperty.NODE_LABEL_FONT, previewModel .getProperties() .getFontValue(PreviewProperty.NODE_LABEL_FONT) .deriveFont(12)); YifanHuLayout layout = new YifanHuLayout(null, new StepDisplacement(1f)); layout.setGraphModel(graphModel); layout.resetPropertiesValues(); layout.setOptimalDistance(120f); layout.initAlgo(); for (int i = 0; i < 100 && layout.canAlgo(); i++) { layout.goAlgo(); } try { ec.exportFile(new File(path + poet + ".svg")); } catch (IOException ex) { ex.printStackTrace(); return; } }