I have written a simple script which accepts a path to a graph file as a parameter, calculates modularity, colours the components based on this modularity, lays the graph out, and then writes back the file. Everything seems to work as expected.
My problem is that when I call the jar file from the command line, the script never returns me to the command prompt. This *only* happens when I attempt to use force atlas 2. The example documentation of Fruchterman-Reingold returns as expected, for example, and the script also returns when I don't do any layout at all. One strange observation is that if I open the gexf file, the layout seems to have completed as expected when using force atlas 2.
Here is the code I am using:
- Code: Select all
//Do layout
ForceAtlas2 f2 = new ForceAtlas2Builder().buildLayout();
f2.setGraphModel(graphModel);
f2.setScalingRatio(2.0);
f2.setGravity(7.0);
//f2.setThreadsCount(12);
f2.setLinLogMode(true);
f2.setAdjustSizes(true);
f2.initAlgo();
for (int i = 0; i < 1 && f2.canAlgo(); i++) {
f2.goAlgo();
}
I have tried varying the number of iterations in the loop, but it has no effect.
------------------------------------------------------------------------------
SOLUTION:
In this case the solution was to make sure that endAlgo() is called after the for loop. The complete code therefore looks like this:
- Code: Select all
//Do layout
ForceAtlas2 f2 = new ForceAtlas2Builder().buildLayout();
f2.setGraphModel(graphModel);
f2.setScalingRatio(2.0);
f2.setGravity(7.0);
f2.setThreadsCount(12);
f2.setLinLogMode(true);
f2.setAdjustSizes(true);
f2.initAlgo();
for (int i = 0; i < 1000 && f2.canAlgo(); i++) {
f2.goAlgo();
}
f2.endAlgo();
Because ForceAtlas2 is a continuous layout algorithm, it must somehow "stay alive" even after the iterations have been completed. This was not documented anywhere, so I think a note on the wiki (perhaps on this page: http://wiki.gephi.org/index.php/Toolkit_-_Layout_graph) about this specific algorithm would be a good idea.
