3

I am constructing a bipartite graph from a list of files with networkx:

https://networkx.github.io/documentation/networkx-1.10/reference/algorithms.bipartite.html?highlight=bipartite

for i, f in enumerate(glob.glob("*.json")):
    with open( f , 'r') as content:
        ...
        graph.add_nodes_from( _type_A , bipartite=0)
        for _type_B in properties:
            graph.add_nodes_from( _type_B , bipartite=1)
            graph.add_edges_from( [(_type_A, _type_B )])

But it failed to recognise the two sets.

x, y = nx.bipartite.sets(graph)

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/networkx/algorithms/bipartite/basic.py", line 170, in sets
    c = color(G)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/networkx/algorithms/bipartite/basic.py", line 78, in color
    raise nx.NetworkXError("Graph is not bipartite.")
networkx.exception.NetworkXError: Graph is not bipartite.

Can you help to understand why?

user305883
  • 1,635
  • 2
  • 24
  • 48

0 Answers0