我正在使用图形工具在网络上工作。你知道吗
在所有顶点的集合中,有一些特定的顶点组,它们具有良好定义的顺序,我希望跟踪它们。到目前为止,我一直在维护一个外部数据结构,以正确的顺序引用顶点。但是,删除某个顶点时,索引大于已删除索引的所有顶点都将重新建立索引,这会破坏我在外部数据结构中保留的引用。你知道吗
什么是保持顶点有序子集的正确方法,以便在(例如)从图中删除第0个顶点时不会中断?你知道吗
from graph_tool.all import *
graph = Graph(directed=False)
graph.add_vertex(5)
""" fifth_vertex is a reference to the vertex with an index of 5. """
fifth_vertex = graph.add_vertex()
assert graph.vertex_index[fifth_vertex] == 5
""" upon removal of a vertex at index i, all vertices of index > i are reindexed. fifth_vertex no longer references a vertex. """
graph.remove_vertex(graph.vertex(0))
""" assertion error """
assert fifth_vertex in graph.get_vertices()
在图形工具中,顶点索引总是在一个连续的范围内。你知道吗
要实现所需功能,需要使用属性映射:
相关问题 更多 >
编程相关推荐