iVis-at-Bilkent / cytoscape.js-fcose

fCoSE: a fast Compound Spring Embedder
MIT License
134 stars 25 forks source link

RangeError thrown with low number of iterations #41

Closed jhubble closed 3 years ago

jhubble commented 3 years ago

When running a layout with a non-trivial amount of nodes and edges, a RangeError is thrown when using a small number of iterations. If the iteration count is increased, the range error does not appear.

See example on code sandbox. Error is thrown with numIter=20, it works fine with numIter=2000

https://codesandbox.io/s/cytoscape-layout-error-6heez?file=/App.js

Partial stack trace: RangeError: Invalid array length at CoSELayout.FDLayout.calcGrid (VM197 layout-base.js:3678) at CoSELayout.FDLayout.updateGrid (VM197 layout-base.js:3718) at CoSELayout.FDLayout.calcRepulsionForces (VM197 layout-base.js:3434) at CoSELayout.tick (VM196 cose-base.js:1543) at CoSELayout.runSpringEmbedder (VM196 cose-base.js:1580) at CoSELayout.classicLayout (VM196 cose-base.js:1459) at CoSELayout.layout (VM196 cose-base.js:1405) at CoSELayout.Layout.runLayout (VM197 layout-base.js:2659) at coseLayout (VM195 cytoscape-fcose.js:918) at Layout.run (VM195 cytoscape-fcose.js:445)

hasanbalci commented 3 years ago

@jhubble The problem was related to the cooling schedule of the algorithm. It is fixed now in the unstable branch and will be available with the next release (hopefully soon). Until then, you can use the unstable branch.

ugurdogrusoz commented 3 years ago

@jhubble Could you please check and confirm the fix for us?

jhubble commented 3 years ago

I can confirm that low values for numIter no longer produce an error when using the unstable branch.

However, with a large set, I notice execution time is fairly similar regardless of the number. Even with a numIter as 0, I see a fairly well-formed layout. Should I expect numIter=0 to be similar to a draft layout?

hasanbalci commented 3 years ago

@jhubble The algorithm consists of two parts: draft + iterative. If the quality is default or proof, the algorithm internally sets max number of iterations as max(numIter, 5*number of nodes) to be able to generate satisfying layouts even if numIter is given very low. But if you set the quality as "draft", then it doesn't apply iterative part but just generates a draft layout. I think you can adjust your parameters based on this info.

jhubble commented 3 years ago

@hasanbalci can the parameter documentation on the README be updated to reflect the override of numIter? I was under the impression that I could set numIter to a low number to get a fast layout at the expense of quality. However, it appears that numIter functions only as a higher ceiling, not as a lower floor.

ugurdogrusoz commented 3 years ago

good point. @hasanbalci please explain the fact that numIter is a suggested value and might be adjusted by the algorithm as required.

ivansglazunov commented 2 years ago

Still error. Please reopen.

hasanbalci commented 2 years ago

@ivansglazunov Could you provide a JSFiddle or JSBin demo to reproduce the issue?