我在 Sage 工作。 Python 似乎对循环可变/不可变图定义的度数不一致。这严重搞乱了我的计算。这是怎么回事?
q=graphs.CompleteGraph(2)
q.allow_loops(True)
q.allow_multiple_edges(True)
q.add_edge([1,1])
a=q.copy(immutable=True)
b=q.copy(immutable=False)
sage: a==b
True
sage: a.degree()
[1, 2]
sage: b.degree()
[1, 3]
最佳答案
这是一个令人讨厌的错误。这就是原因。
sage: a._backend
<class 'sage.graphs.base.static_sparse_backend.StaticSparseBackend'>
sage: b._backend
<class 'sage.graphs.base.sparse_graph.SparseGraphBackend'>
在通常的后端中,有这样的无向图代码。
if self._loops and self.has_edge(v, v, None):
if self._multiple_edges:
d += len(self.get_edge_label(v, v))
else:
d += 1
在静态中,我们只是得到
else:
return cg.out_degree(v)
关于python - 循环图度计算中的 Sage python bug?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26566823/