# HG changeset patch
# User Nathann Cohen
# Date 1315671402 7200
# Node ID aac33495b7996b323254b9ed7b2530ddd0ef2303
# Parent 3aac65df60e82beef87f7e81cd7c135c5dcc6007
trac 11735  Fixes a bug in is_chordal
diff r 3aac65df60e8 r aac33495b799 sage/graphs/generic_graph.py
 a/sage/graphs/generic_graph.py Sat Sep 10 18:05:46 2011 +0200
+++ b/sage/graphs/generic_graph.py Sat Sep 10 18:16:42 2011 +0200
@@ 9453,6 +9453,16 @@
Incidence matrices and interval graphs
Pacific J. Math 1965
Vol. 15, number 3, pages 835855
+
+ TESTS:
+
+ Trac Ticket #11735::
+
+ sage: g = Graph({3:[2,1,4],2:[1],4:[1],5:[2,1,4]})
+ sage: _, g1 = g.is_chordal(certificate=True); g1.is_chordal()
+ False
+ sage: g1.is_isomorphic(graphs.CycleGraph(g1.order()))
+ True
"""
# If the graph is not connected, we are computing the result on each component
@@ 9492,20 +9502,34 @@
if not frozenset(g.neighbors(v)).issubset(S):
+ # Do we need to return a hole ?
if certificate:
# In this case, let us take two nonadjacent neighbors of v
+ # In this case, let us take two nonadjacent neighbors of
+ # v. In order to do so, we pick a vertex y which is a
+ # neighbor of v but is not adjacent to x, which we know
+ # exists by the test written two lines above.
for y in g.neighbors(v):
if y not in S:
break
+ g.delete_vertices([vv for vv in g.neighbors(v) if vv != y and vv != x])
g.delete_vertex(v)
 # Our hole is v + (a shortest path between x and y
 # not containing v)

 return (False, self.subgraph([v] + g.shortest_path(x,y)))
+ # Our hole is v + (a shortest path between x and y not
+ # containing v or any of its neighbors).
+
+ hole = self.subgraph([v] + g.shortest_path(x,y))
+
+ # There was a bug there once, so it's better to check the
+ # answer is valid, especally when it is so cheap ;)
+
+ if hole.order() <= 3 or not hole.is_regular(k=2):
+ raise Exception("The graph is not chordal, and something went wrong in the computation of the certificate. Please report this bug, providing the graph if possible !")
+
+ return (False, hole)
else:
return False