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

Create two shortest path options in own module #174

Merged
merged 2 commits into from
May 28, 2024

Conversation

barneydobson
Copy link
Collaborator

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.

@barneydobson barneydobson requested review from dalonsoa and cheginit May 23, 2024 11:51
@barneydobson barneydobson mentioned this pull request May 23, 2024
5 tasks
Copy link
Collaborator

@dalonsoa dalonsoa left a 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:
Copy link
Collaborator

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.

Comment on lines +75 to +76
# Check if all vertices are reachable from the root
if len(parent) != n - 1:
Copy link
Collaborator

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:
Copy link
Collaborator

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:
Copy link
Collaborator

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?

@barneydobson barneydobson merged commit 560870d into main May 28, 2024
4 checks passed
@barneydobson barneydobson deleted the refactor_shortest_path branch May 28, 2024 13:47
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

Successfully merging this pull request may close these issues.

2 participants