我正在使用Metis for Python
Metis(图形分区软件)的 Python 包装器。我已经安装了所有东西,它似乎工作正常,但是我不明白如何构建一个图表来输入。
有一个在线示例: http: //metis.readthedocs.org/en/latest/#example
>>> import networkx as nx
>>> import metis
>>> G = metis.example_networkx()
>>> (edgecuts, parts) = metis.part_graph(G, 3)
>>> colors = ['red','blue','green']
>>> for i, p in enumerate(parts):
... G.node[i]['color'] = colors[p]
...
>>> nx.write_dot(G, 'example.dot') # Requires pydot or pygraphviz
我运行了这个例子,它工作正常。然而在这个例子中,他们从未指定如何构造图“example_networkx()”。我试图通过 networkx 构建图表:http: //metis.readthedocs.org/en/latest/#metis.networkx_to_metis
我的代码是:
>>> A=nx.Graph()
>>> A.add_edges_from([(3,1),(2,3),(1,2),(3,4),(4,5),(5,6),(5,7),(7,6),(4,10),(10,8),(10,9),(8,9)])
>>> G = metis.networkx_to_metis(A)
>>> (edgecuts, parts) = metis.part_graph(G, 3)
我在最后一行得到一个错误。错误追溯到 Metis 内置代码中的这些行:
in part_graph(graph, nparts, tpwgts, ubvec, recursive, **opts)
graph = adjlist_to_metis(graph, nodew, nodesz)
in adjlist_to_metis(adjlist, nodew, nodesz)
m2 = sum(map(len, adjlist))
TypeError: object of type 'c_long' has no len()
我还尝试通过邻接列表构建图形:http: //metis.readthedocs.org/en/latest/#metis.adjlist_to_metis 但这给出了与以前相同的错误。
我想知道是否有人遇到过这个问题,或者知道我做错了什么。
我在 Centos 6.5 上使用 python 2.7