-
Notifications
You must be signed in to change notification settings - Fork 113
Deterministic graph layout? #84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thank you for the report. With which layout algorithm(s) does this occur for you? It seems to be a layout-specific problem. For example, multiple runs of the |
Here's my code: ogdf::Graph G;
ogdf::GraphAttributes GA(G,
ogdf::GraphAttributes::nodeGraphics
| ogdf::GraphAttributes::edgeGraphics
| ogdf::GraphAttributes::nodeLabel
| ogdf::GraphAttributes::edgeStyle
| ogdf::GraphAttributes::nodeStyle
| ogdf::GraphAttributes::nodeTemplate);
// Add node and edges here
ogdf::SugiyamaLayout layout;
layout.setRanking(new ogdf::OptimalRanking);
layout.setCrossMin(new ogdf::MedianHeuristic);
ogdf::OptimalHierarchyLayout* ohl = new ogdf::OptimalHierarchyLayout;
ohl->layerDistance(30.0);
ohl->nodeDistance(25.0);
ohl->weightBalancing(0.8);
layout.setLayout(ohl);
layout.call(GA); I can't debug right now but I remember placing a breakpoint on |
Hmmm, I've been using the same code as you (including Here's the exact code I used:#include <ogdf/basic/graph_generators.h>
#include <ogdf/fileformats/GraphIO.h>
#include <ogdf/layered/MedianHeuristic.h>
#include <ogdf/layered/OptimalHierarchyLayout.h>
#include <ogdf/layered/OptimalRanking.h>
#include <ogdf/layered/SugiyamaLayout.h>
using namespace ogdf;
int main(int argc, char *argv[])
{
Graph G;
GraphAttributes GA(G, GraphAttributes::all);
randomGraph(G, 50, 100);
for (int i {0}; i < 15; ++i) {
ogdf::setSeed(42);
std::cout << "Round " << i << std::endl;
SugiyamaLayout SL;
SL.setRanking(new OptimalRanking);
SL.setCrossMin(new MedianHeuristic);
OptimalHierarchyLayout *ohl = new OptimalHierarchyLayout;
ohl->layerDistance(30.0);
ohl->nodeDistance(25.0);
ohl->weightBalancing(0.8);
SL.setLayout(ohl);
SL.call(GA);
GraphIO::write(GA, "issue-84-" + std::to_string(i) + ".svg", GraphIO::drawSVG);
}
return 0;
} |
Thanks for taking the time to look into this, appreciate it. I added back my call to I think I might be going insane |
No problem, I know that feeling all too well. I'll keep this issue open for now as a reminder that there are other non-deterministic layouts that probably should be deterministic (with a set seed). |
Note that the Sugiyam 9B6F a Docs mention that you need to set runs=1 if you want to get deterministic behaviour. I vaguely recall that I had a similar issue when writing tests for ogdf-python and this might have fixed it. |
Dear Sir, I am trying to use the FMMMLayout to generate the positions of nodes. However, I noticed that even after setting the random seed with ogdf::setSeed(1), I am unable to obtain the same results consistently. I would like to use OGDF (Open Graph Drawing Framework) in the Rust language, but I am not very familiar with OGDF and C++ . Could you please provide me with some advice? Thank you for your time and assistance. Best regards,
|
Uh oh!
There was an error while loading. Please reload this page.
I have noticed that the positions of nodes change randomly between runs on the same graph, even if I use
ogdf::setSeed(42);
.This looks like a data race problem. Even if you set the seed on the global PRNG, the layout algorithms have worker threads, so the points at which random numbers are obtained is... well, random.
The text was updated successfully, but these errors were encountered: