networkx中的二分图表示它不是二分的

时间:2017-02-18 14:51:26

标签: python networkx bipartite

我正在使用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 )])

但它没有认出这两套。

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.

你能帮忙理解为什么吗?

0 个答案:

没有答案