JGraphX ​​takes a long time to plot

I am building a graph with JGraphX. Using the following code, it takes too long to build compared to similar graph implementations such as JGraphT. Why should it be? Vertices are created quickly, but nested loops that create edges take a lot of time, especially when the dimensions of the array are 1000.

Vertex[] verts = new Vertex[1000]; // My own vertex class mxCell[] cells = new mxCell[1000]; // From com.mxGraph.model.mxCell // Create graph mxGraph mx = new mxGraph(); // from com.mxgraph.view.mxGraph // Create vertices for(int i = 0; i < verts.length; i++) { verts[i] = new Vertex(Integer.toString(i)); cells[i] = new mxCell(verts[i]); mx.getModel().beginUpdate(); mx.insertVertex(null, Integer.toString(i), cells[i], 1, 1, 1, 1); mx.getModel().endUpdate(); } System.out.println("Vertices created."); // Connect graph Random r = new Random(); for(int j = 0; j < verts.length; j++) { for(int k = 0; k < verts.length; k++) { if(k != j) { if(r.nextInt(5) == 0) // Random connections, fairly dense { mx.getModel().beginUpdate(); mx.insertEdge(null, Integer.toString(k) + " " + Integer.toString(j), "", cells[j], cells[k]); mx.getModel().endUpdate(); } } } } System.out.println("Finished graph."); 
+4
source share
1 answer

begin and end updates are designed to combine operations into one. Completion of the update causes a full schedule check. Here you wrap only every atomic operation, they do not affect.

Remove the start / end that you start after creating the graph and the end at the bottom of this section of code and try this.

+1
source

Source: https://habr.com/ru/post/1482627/


All Articles