Skip to content

Commit da0856b

Browse files
author
Release Manager
committed
gh-40710: Allow calling is_perfect() on immutable graphs This is a simple fix to avoid an exception when calling `is_perfect()` on an immutable graph. The fix works by removing an unnecessary `remove_loops()` call added in 915a5e2. ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [x] I have created tests covering the changes. - [x] I have updated the documentation and checked the documentation preview. URL: #40710 Reported by: Lennard Hofmann Reviewer(s): David Coudert
2 parents fbe24d6 + 80235ff commit da0856b

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

src/sage/graphs/graph.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2670,7 +2670,7 @@ def is_perfect(self, certificate=False):
26702670
sage: Graph(':Ab').is_perfect() # needs sage.modules
26712671
Traceback (most recent call last):
26722672
...
2673-
ValueError: This method is only defined for simple graphs, and yours is not one of them !
2673+
ValueError: This method is not known to work on graphs with multiedges/loops...
26742674
sage: g = Graph()
26752675
sage: g.allow_loops(True)
26762676
sage: g.add_edge(0,0)
@@ -2679,18 +2679,21 @@ def is_perfect(self, certificate=False):
26792679
sage: g.is_perfect() # needs sage.modules
26802680
Traceback (most recent call last):
26812681
...
2682-
ValueError: This method is only defined for simple graphs, and yours is not one of them !
2682+
ValueError: This method is not known to work on graphs with loops. ...
2683+
2684+
TESTS:
2685+
2686+
Check that immutable graphs are supported::
2687+
2688+
sage: g = graphs.HouseGraph(immutable=True)
2689+
sage: g.is_perfect() # needs sage.modules
2690+
True
26832691
"""
2684-
if self.has_multiple_edges() or self.has_loops():
2685-
raise ValueError("This method is only defined for simple graphs,"
2686-
" and yours is not one of them !")
2692+
self_complement = self.complement(immutable=False)
2693+
26872694
if self.is_bipartite():
26882695
return True if not certificate else None
26892696

2690-
self_complement = self.complement()
2691-
self_complement.remove_loops()
2692-
self_complement.remove_multiple_edges()
2693-
26942697
if self_complement.is_bipartite():
26952698
return True if not certificate else None
26962699

0 commit comments

Comments
 (0)