spitespike
spitespike

Reputation: 179

Sage python bug in looped graph degree computation?

I'm working in Sage. Python appears to define degrees inconsistently for looped mutable/immutable graphs. This is screwing up my computations hard. What is going on here?

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]

Upvotes: 2

Views: 50

Answers (1)

kcrisman
kcrisman

Reputation: 4402

This is a nasty bug. Here is why.

sage: a._backend
<class 'sage.graphs.base.static_sparse_backend.StaticSparseBackend'>
sage: b._backend
<class 'sage.graphs.base.sparse_graph.SparseGraphBackend'>

In the usual backend, there is code like this for undirected graphs.

    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

In the static one, we just get

        else:
            return cg.out_degree(v)

Upvotes: 2

Related Questions