tomnelson / jungrapht-visualization

visualization and sample code from Java Universal Network Graph ported to use JGraphT models and algorithms
Other
47 stars 7 forks source link

Is it possible to get a deterministic calculation of the locations when running e.g. Sugiyama layout algorithm #25

Closed kristofsmits closed 1 year ago

kristofsmits commented 1 year ago

Hi, Thumbs up for your library, it's a great piece of work! Something I notice is that everytime I run the Sugiyama algorithm on exactly the same graph, the layout is different (or can be different) on each run compared to the previous run. I assume it has to do something with the fact that the vertices in JGraphT are stored in a Set and not in a List, so retrieval of graph nodes is always in an undeterministic order. Is there a way or would it be possible to provide functionality to calculate the layout in a deterministic way, so that every run the location of each vertex is exactly the same? Best regards, Kristof

tomnelson commented 1 year ago

Thank you! I just made 2 demos and pushed them to the master branch: SugiyamaSixSameGraphExample EiglspergerSixSameGraphExample

They create the same graph 6 times and lay it out six times in the same window. To me, they all look the same. I'm probably missing something about your test that makes them different each time. Could you give me more detail, or perhaps an example of how you configured the layout options?

tomnelson commented 1 year ago

If you get a chance, define a Comparator that will sort your graph edges in the same order. Pass that to the EiglspergerLayoutAlgorithm builder and use the EiglspergerLayoutAlgorithm. If you need to use the SugiyamaLayoutAlgorithm (its usually slower than the Eiglsperger), I'll need to update its code. Let me know if this works.