-
Notifications
You must be signed in to change notification settings - Fork 1
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
Create two shortest path options in own module #174
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've made a couple of minor comments, but it looks good to me. I've to admit, I don't completely understand what these trees are...
while in_edge_pq: | ||
weight, u, v = heapq.heappop(in_edge_pq) | ||
|
||
if u not in parent: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To avoid too much indentation, you can check the opposite and then continue:
if u in parent:
continue
# If v is not in the MST yet, add the edge (u, v) to the MST
parent[u] = v
...
Visually, it reduces complexity.
# Check if all vertices are reachable from the root | ||
if len(parent) != n - 1: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't follow this. Why checking the length checks that all vertices are reachable from the root? I mean, why such a length should be equal to n-1, when n is the total number of nodes? Probably is because I do not fully understand what these trees are, so don't worry if it's obvious it should this like this.
mst_edges = [] | ||
mst_weight = 0 | ||
outlets: dict = {} | ||
while in_edge_pq: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add a top level explanation of what this loop is doing and how ti finds the MST.
for path in paths.values(): | ||
# Assign outlet | ||
outlet = path[0] | ||
for node in path: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this exclude path[0]
or that one should have as outlet itself?
Description
A lot of changes in #144 so I am splitting out what I can to be reviewed separately.
In this PR I have written and tested two shortest path functions for deriving network topology.
These are currently standalone and will be incorporated into
graph_utilities.py\derive_topology
in a separate PR.