Repository navigation
Example fix for issue 7633 - #7634
Conversation
rossbar
left a comment
There was a problem hiding this comment.
Thanks @WoojinJung-04 , +1 for fixing the visualization. I have a minor suggestion (see above) for how to more reliably improve the layout independent of the seed!
| print(f"Maximum independent set of G: {I}") | ||
|
|
||
| pos = nx.spring_layout(G, seed=39299899) | ||
| pos = nx.spring_layout(G, seed=251134665) |
There was a problem hiding this comment.
In principle, we'd want a solution that doesn't depend on the seed. One thing to try that should robustly give better results is to increase the number of iterations to prevent premature termination of the layout method:
| pos = nx.spring_layout(G, seed=251134665) | |
| pos = nx.spring_layout(G, iterations=100, seed=251134665) |
There was a problem hiding this comment.
@rossbar
Thank you for the comment! It's really exciting to me as I'm just starting on my journey to the world of open source projects! I'm planning to get a career heavily related to Data Analysis so I' m hunting for issues from libraries like networkx or mathplotlib I can work on to gradually increase my skill!😊
I really appreciate your feedback!
/
I've looked into the code of 'nx.spring_layout' and tried multiple times increasing the iterations variable in this case.
While the frequency of graphs such as this where vertices overlap

decreased,
the frequency of graphs such as this where vertices cross each other
I have confirmed by multiple different seeds that iterations > 400 consistently avoids the overlapping of vertices in our example from #7633
\
In the function '_fruchterman_reingold' inside nx.spring_layout, the equation to calculate the attracting forces between vertices is
A * distance / k
while 'A' is an adjacency matrix and k the optimal distance between vertices
This means that there aren't any forces simulated between vertices that aren't connected.
Perhaps modifying the function could also be an solution.
The simplest solution(to avoid any interesting phenomena) I could think of is to add a weak force between unconnected vertices. I haven't tried it yet but it could possibly solve the issue in a aesthetically pleasing way, but it might diverge from the original algorithm.
Do you mean edges crossing each other (instead of vertices)? Generally edge crossings are completely fine! The main issue here is when the nodes 1, 6, and 7 are colinear, which causes the edge masking. The success criterion is that all three edges (1, 6), (6, 7) and (1, 7) are visible, regardless whether they cross one another.
This could be interesting to consider but is certainly out-of-scope for this PR. Please feel free to investigate the FR algorithm (I'd recommend starting with the paper), but I'd advocate opening separate issues/PRs for that so we don't block this fix. For this PR, IMO the best way forward is to pick a combination of |
|
Oh, I understand. While the criterion is whether all of the edges are distinctly visible, we also want it to be a replicable solution! I have made the necessary changes and commited them! |
rossbar
left a comment
There was a problem hiding this comment.
Thanks @WoojinJung-04 , LGTM!
Here's the updated example for other reviewers - note that edge-masking in the node 1, 6, 7 cluster is fixed!
dschult
left a comment
There was a problem hiding this comment.
This looks good to me. Thanks very much @WoojinJung-04 .
And Thanks @rossbar for the nice review.

Modified plot_maximum_independent_set.py (changed seed to 251134665)
So that it shows a better example of the graph.
Document needs to be modified
Closes #7633