Skip to content

Commit

Permalink
Merge pull request #22 from WestHealth/19-bidirectional-dependencies
Browse files Browse the repository at this point in the history
added check for bidirectional edge adding
  • Loading branch information
boludo00 committed Dec 6, 2018
2 parents 9aba20a + 7e87fdc commit b45de26
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions pyvis/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,15 +323,17 @@ def add_edge(self, source, to, **options):
assert to in self.get_nodes(), \
"non existent node '" + str(to) + "'"

for e in self.edges:
frm = e['from']
dest = e['to']
if (
(source == dest and to == frm) or
(source == frm and to == dest)
):
# edge already exists
edge_exists = True
# we only check existing edge for undirected graphs
if not self.directed:
for e in self.edges:
frm = e['from']
dest = e['to']
if (
(source == dest and to == frm) or
(source == frm and to == dest)
):
# edge already exists
edge_exists = True

if not edge_exists:
e = Edge(source, to, self.directed, **options)
Expand Down

0 comments on commit b45de26

Please sign in to comment.