Skip to content

Commit

Permalink
⬆️ bipartite conversion fix
Browse files Browse the repository at this point in the history
  • Loading branch information
GiulioRossetti committed May 13, 2024
1 parent 5ae2b89 commit d2c5341
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions cdlib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,16 @@ def __from_nx_to_igraph(g: object, directed: bool = None) -> ig.Graph:
gi = ig.Graph(directed=directed)

a_r = {}
skip_bipartite = False
if bipartite.is_bipartite(g):
A, B = bipartite.sets(g)
for a in A:
a_r[a] = 0
for b in B:
a_r[b] = 1
try:
A, B = bipartite.sets(g)
for a in A:
a_r[a] = 0
for b in B:
a_r[b] = 1
except nx.exception.AmbiguousSolution:
skip_bipartite = True

## Two problems to handle:
# 1)in igraph, names have to be str.
Expand All @@ -127,7 +131,7 @@ def __from_nx_to_igraph(g: object, directed: bool = None) -> ig.Graph:
gi.add_vertices(["\\" + str(n) for n in g.nodes()])
gi.add_edges([("\\" + str(u), "\\" + str(v)) for (u, v) in g.edges()])

if bipartite.is_bipartite(g):
if bipartite.is_bipartite(g) and not skip_bipartite:
gi.vs["type"] = [
a_r[name] if type(name) == int else a_r[int(name.replace("\\", ""))]
for name in gi.vs["name"]
Expand Down

0 comments on commit d2c5341

Please sign in to comment.