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

fix algorithm NNedgesNetworkGenerator #61

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,18 @@ def generate_network(self, edges: list[tuple[int, int]],
w_edges.append((e[0], e[1], w))
nodes.extend(e)

final_edges = []
node_con = {n: 0 for n in nodes} # early termination crit
for edge in sorted(w_edges, key=lambda x: x[2]):
# Build initial MST:
self.g = nx.Graph()
self.g.add_weighted_edges_from(ebunch_to_add=w_edges)
min_edges = nx.minimum_spanning_edges(self.g, weight='weight')
mse = [(e1, e2, edge_data['weight']) for i, (e1, e2, edge_data) in
enumerate(min_edges)]

# Select Additional Edges
final_edges = mse
rest_edges = list(filter(lambda e: e not in mse, mse))
node_con = {n: 1 for n in nodes} # early termination crit
for edge in sorted(rest_edges, key=lambda x: x[2]):
e1 = edge[0]
e2 = edge[1]
if (node_con[e1] < self.target_node_connectivity):
Expand Down
Loading