Skip to content

Commit

Permalink
Trac #25613: Graph.is_gallai_tree() method has an error in the code
Browse files Browse the repository at this point in the history
The Graph.is_gallai_tree() method checks for whether a block's vertices
induce a cycle tests if the number of edges is one more than the number
of vertices. These should be the same.

The third-to-last-line currently has the test: gg.size() == len(c)+1

It *should* have the test: gg.size() == len(c)

A graph which is a 5-cycle with an appended edge to an external vertex
is a gallai tree. But the existing method returns False. Call this graph
"gg":

{{{#!python
gg=graphs.CycleGraph(5)
gg.add_edge(0,5)
gg.is_gallai_tree()
}}}

should return: True.

URL: https://trac.sagemath.org/25613
Reported by: gh-math1um
Ticket author(s): Frédéric Chapoton
Reviewer(s): Travis Scrimshaw
  • Loading branch information
Release Manager authored and vbraun committed Jun 22, 2018
2 parents a4b485a + f8a9c73 commit 7687d8f
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/sage/graphs/generic_graph.py
Expand Up @@ -12671,7 +12671,7 @@ def is_interval(self, certificate=False):

def is_gallai_tree(self):
r"""
Returns whether the current graph is a Gallai tree.
Return whether the current graph is a Gallai tree.

A graph is a Gallai tree if and only if it is
connected and its `2`-connected components are all
Expand Down Expand Up @@ -12709,15 +12709,24 @@ def is_gallai_tree(self):
sage: g.add_edges([(-1,c[0]) for c in g.connected_components()])
sage: g.is_gallai_tree()
True

TESTS:

Check that :trac:`25613` is fixed::

sage: g = graphs.CycleGraph(5)
sage: g.add_edge(0,5)
sage: g.is_gallai_tree()
True
"""
self._scream_if_not_simple()
if not self.is_connected():
return False

for c in self.blocks_and_cut_vertices()[0]:
gg = self.subgraph(c)
# is it an odd cycle ? a complete graph ?
if not ( (len(c)%2 == 1 and gg.size() == len(c)+1) or gg.is_clique() ):
# is it an odd cycle ? a complete graph ?
if not ((len(c) % 2 and gg.size() == len(c)) or gg.is_clique()):
return False

return True
Expand Down

0 comments on commit 7687d8f

Please sign in to comment.