Skip to content

Conversation

@Ankush-Chander
Copy link
Contributor

In an undirected graph, when we add duplicate edges, the associated weight is overwritten instead of accumulated.
As per networkx documentation:

Adding the same edge twice has no effect but any edge data will be updated when each duplicate edge is added.

For a hypothetical example:

weighted_edges = [
    ("play", "with", {'weight': 2.0}),
    ("with", "play", {'weight': 11.0}),
]

graph= nx.Graph()
graph.add_edges_from(weighted_edges)

current code leads to(overwriting):

("play", "with", 11.0)

Desired behaviour(accumulation):

("play", "with", 13.0)

Thanks to @yamika-g for pointing it out here:

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.

1 participant