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 information loss in undirected graph #283

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

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