Ticket #11735: trac_11735.patch

File trac_11735.patch, 2.8 KB (added by ncohen, 8 years ago)
  • sage/graphs/generic_graph.py

    # 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  
    94539453          Incidence matrices and interval graphs
    94549454          Pacific J. Math 1965
    94559455          Vol. 15, number 3, pages 835--855
     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
    94569466        """
    94579467
    94589468        # If the graph is not connected, we are computing the result on each component
     
    94929502
    94939503                if not frozenset(g.neighbors(v)).issubset(S):
    94949504
     9505                    # Do we need to return a hole ?
    94959506                    if certificate:
    94969507
    94979508                        # 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.
    94989513
    94999514                        for y in g.neighbors(v):
    95009515                            if y not in S:
    95019516                                break
    95029517
     9518                        g.delete_vertices([vv for vv in g.neighbors(v) if vv != y and vv != x])
    95039519                        g.delete_vertex(v)
    95049520
    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)
    95099533                    else:
    95109534                        return False
    95119535