-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Added code to handle multi-graph in mst #7454
Changes from all commits
6c4aee8
4dca079
f91dbc7
9653605
74eb78d
1181136
f293e39
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1126,19 +1126,28 @@ def _write_partition(self, partition): | |
A Partition dataclass describing a partition on the edges of the | ||
graph. | ||
""" | ||
for u, v, d in self.G.edges(data=True): | ||
if (u, v) in partition.partition_dict: | ||
d[self.partition_key] = partition.partition_dict[(u, v)] | ||
else: | ||
d[self.partition_key] = EdgePartition.OPEN | ||
|
||
partition_dict = partition.partition_dict | ||
partition_key = self.partition_key | ||
G = self.G | ||
|
||
edges = ( | ||
G.edges(keys=True, data=True) if G.is_multigraph() else G.edges(data=True) | ||
) | ||
for *e, d in edges: | ||
d[partition_key] = partition_dict.get(tuple(e), EdgePartition.OPEN) | ||
|
||
def _clear_partition(self, G): | ||
""" | ||
Removes partition data from the graph | ||
""" | ||
for u, v, d in G.edges(data=True): | ||
if self.partition_key in d: | ||
del d[self.partition_key] | ||
partition_key = self.partition_key | ||
edges = ( | ||
G.edges(keys=True, data=True) if G.is_multigraph() else G.edges(data=True) | ||
) | ||
for *e, d in edges: | ||
Comment on lines
+1145
to
+1148
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like this pattern! What do you think about using it above when setting There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looked neat this way. |
||
if partition_key in d: | ||
del d[partition_key] | ||
|
||
|
||
@nx._dispatchable(edge_attrs="weight") | ||
|
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.
While we're here, I think this looks cleaner. Feel free to disregard.