# HG changeset patch
# User Nathann Cohen <nathann.cohen@gmail.com>
# 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

b


9453  9453  Incidence matrices and interval graphs 
9454  9454  Pacific J. Math 1965 
9455  9455  Vol. 15, number 3, pages 835855 
 9456  
 9457  TESTS: 
 9458  
 9459  Trac Ticket #11735:: 
 9460  
 9461  sage: g = Graph({3:[2,1,4],2:[1],4:[1],5:[2,1,4]}) 
 9462  sage: _, g1 = g.is_chordal(certificate=True); g1.is_chordal() 
 9463  False 
 9464  sage: g1.is_isomorphic(graphs.CycleGraph(g1.order())) 
 9465  True 
9456  9466  """ 
9457  9467  
9458  9468  # If the graph is not connected, we are computing the result on each component 
… 
… 

9492  9502  
9493  9503  if not frozenset(g.neighbors(v)).issubset(S): 
9494  9504  
 9505  # Do we need to return a hole ? 
9495  9506  if certificate: 
9496  9507  
9497  9508  # In this case, let us take two nonadjacent neighbors of v 
 9509  # In this case, let us take two nonadjacent neighbors of 
 9510  # v. In order to do so, we pick a vertex y which is a 
 9511  # neighbor of v but is not adjacent to x, which we know 
 9512  # exists by the test written two lines above. 
9498  9513  
9499  9514  for y in g.neighbors(v): 
9500  9515  if y not in S: 
9501  9516  break 
9502  9517  
 9518  g.delete_vertices([vv for vv in g.neighbors(v) if vv != y and vv != x]) 
9503  9519  g.delete_vertex(v) 
9504  9520  
9505   # Our hole is v + (a shortest path between x and y 
9506   # not containing v) 
9507   
9508   return (False, self.subgraph([v] + g.shortest_path(x,y))) 
 9521  # Our hole is v + (a shortest path between x and y not 
 9522  # containing v or any of its neighbors). 
 9523  
 9524  hole = self.subgraph([v] + g.shortest_path(x,y)) 
 9525  
 9526  # There was a bug there once, so it's better to check the 
 9527  # answer is valid, especally when it is so cheap ;) 
 9528  
 9529  if hole.order() <= 3 or not hole.is_regular(k=2): 
 9530  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 !") 
 9531  
 9532  return (False, hole) 
9509  9533  else: 
9510  9534  return False 
9511  9535  