我在Windows 7下的Python 3.4中运行igraph 0.7.1,以下代码崩溃:
import igraph
class Person:
def __init__(self, name):
self.name = name
alice = Person('Alice')
bob = Person('Bob')
g = igraph.Graph()
g.add_vertex(alice)
g.add_vertex(bob)
print(g.vs[0]['name'] == alice)
print(g.vs[1]['name'] == bob)
g.add_edge(alice, bob)
输出如下:
True
True
File "C:\Python34\lib\site-packages\igraph\__init__.py", line 237, in add_edge
return self.add_edges([(source, target)])
File "C:\Python34\lib\site-packages\igraph\__init__.py", line 255, in add_edges
return GraphBase.add_edges(self, es)
TypeError: only numbers, vertex names or igraph.Vertex objects can be converted to vertex IDs
似乎这段代码应该可以工作,因为alice和bob在这种情况下是顶点名称,实际上存储在顶点的'name'属性中。有趣的是,以下内容不会崩溃:
g = igraph.Graph()
g.add_vertex('Alice')
g.add_vertex('Bob')
g.add_edge('Alice', 'Bob')