diff --git a/cdlib/utils.py b/cdlib/utils.py index a61ff5b4..12f9a926 100644 --- a/cdlib/utils.py +++ b/cdlib/utils.py @@ -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. @@ -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"]