Skip to content

Commit 872adfb

Browse files
author
Release Manager
committed
gh-40836: Fix BipartiteGraph.vertex_cover(value_only=True) for disconnected graphs For a graph G, `len(G.vertex_cover())` should always equal `G.vertex_cover(value_only=True)`, but this was not the case when G is a disconnected `BipartiteGraph`. The fix is shockingly simple. URL: #40836 Reported by: Lennard Hofmann Reviewer(s): David Coudert
2 parents 7271bd0 + ecaab20 commit 872adfb

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/sage/graphs/bipartite_graph.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2345,6 +2345,8 @@ def vertex_cover(self, algorithm='Konig', value_only=False,
23452345
sage: B = BipartiteGraph(graphs.CycleGraph(4) * 2)
23462346
sage: len(B.vertex_cover()) # needs networkx
23472347
4
2348+
sage: B.vertex_cover(value_only=True) # needs networkx
2349+
4
23482350
23492351
Empty bipartite graph and bipartite graphs without edges::
23502352
@@ -2376,7 +2378,7 @@ def vertex_cover(self, algorithm='Konig', value_only=False,
23762378
if b.size():
23772379
VC.extend(b.vertex_cover(algorithm='Konig'))
23782380
if value_only:
2379-
return sum(VC)
2381+
return len(VC)
23802382
return VC
23812383

23822384
M = Graph(self.matching())

0 commit comments

Comments
 (0)