Skip to content
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

Floyd-Warshall algorithm #38

Open
citizenfish opened this issue Nov 6, 2024 · 0 comments
Open

Floyd-Warshall algorithm #38

citizenfish opened this issue Nov 6, 2024 · 0 comments

Comments

@citizenfish
Copy link

I was looking to see if I could speed things up a bit as a computation on my home town of Brixham was taking 3-4 minutes.

Looking at the function get_shortest_distance_for_odd_degrees I see you are computing shortest paths on all the odd degree nodes. But I note that networkx has floyd-warshall which finds them all over the graph so I tried substituting this as follows to see if it would be quick to compute them all then pick the odd-degree nodes:-

 all_pairs_shortest_path = dict(nx.floyd_warshall(graph, weight="length"))
 
# Extract only the odd-degree node pairs
 return {(v, u): all_pairs_shortest_path[v][u] for v, u in combinations(odd_degree_nodes, 2)}

This significantly improved performance from over 2 minutes to 24 seconds. Testing with Brixham it seems to work OK but I'm not a graph theory expert, my maths degree is a distant memory. I'm just adding as an issue for information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant