2015-11-09 4 views
0

Я понятия не имею, что вызывает эту ошибку. Что я делаю, добавляя много вершины в мой график в начале:Получение «ValueError: неверный дескриптор вершин» при удалении вершин

for i in range(len(repositories_key_list)): 
    repo_vertices[repositories_key_list[i]] = g3.add_vertex() 

Затем идет некоторую обработка, которая соединяет эти вершины и для того, чтобы сократить время, необходимое, чтобы сделать график я удалить все вершины, что есть в и степени, равной нулю:

for repository_name in repo_vertices: 

    vert = repo_vertices[repository_name] 
    print vert 

    if vert.out_degree() == 0 and vert.in_degree() == 0: 
     g3.remove_vertex(vert) 

Однако, что-то я, кажется, проблема, потому что я получаю эту ошибку:

Traceback (most recent call last): 
    File "/media/sfalk/win-data/Stefan/Uni/Master/WS/Network Science/projects/project1/github/graph_tools_github.py", line 276, in <module> 
    print vert 
ValueError: invalid vertex descriptor: 22947 

Интересно, что print vert прослеживается как проблема здесь. Если я комментирую эту строку из Я получаю:

Traceback (most recent call last): 
    File "/media/sfalk/win-data/Stefan/Uni/Master/WS/Network Science/projects/project1/github/graph_tools_github.py", line 278, in <module> 
    if vert.out_degree() == 0 and vert.in_degree() == 0: 
    File "/usr/lib/python2.7/dist-packages/graph_tool/__init__.py", line 2933, in _out_degree 
    return self.__out_degree() 
ValueError: invalid vertex descriptor: 23038 

Так все, что здесь происходит, я понятия не имею, как решить эту проблему ..

ответ

0

Это подробно описано в документации Graph.remove_vertex() на https://graph-tool.skewed.de/static/doc/graph_tool.html#graph_tool.Graph.remove_vertex. В частности, в нем говорится:

This operation may invalidate vertex descriptors. Vertices are always indexed contiguously in the range [0,N−1], hence vertex descriptors with an index higher than vertex will be invalidated after removal (if fast == False, otherwise only descriptors pointing to vertices with the largest index will be invalidated).

Because of this, the only safe way to remove more than one vertex at once is to sort them in decreasing index order:

# 'del_list' is a list of vertex descriptors 
for v in reversed(sorted(del_list)): 
    g.remove_vertex(v) 

Alternatively (and preferably), a list (or iterable) may be passed directly as the vertex parameter, and the above is performed internally (in C++).

+1

Я до сих пор неясно, на этом: есть ли способ, чтобы удалить произвольную вершину без недействительности, по крайней мере одну другой вершины? – gerowam