Ticket #8458: trac_8458.patch

File trac_8458.patch, 3.6 KB (added by ncohen, 10 years ago)
  • sage/graphs/graph_generators.py

    # HG changeset patch
    # User Lukas Lansky <lansky@kam.mff.cuni.cz>
    # Date 1325631840 0
    # Node ID 3d5687cd30a8efb0e974ffa2d23746401646b037
    # Parent  7ffa0fee7030d2f3b93cea7c311a8b94b7387673
    Trac 8458: generated graphs are independent
    
    diff --git a/sage/graphs/graph_generators.py b/sage/graphs/graph_generators.py
    a b  
    326326    - ``sparse`` -- (default: ``True``) ignored if implementation is not
    327327      ``'c_graph'``.
    328328
     329    - ``copy`` (boolean) -- If set to ``True`` (default)
     330      this method makes copies of the graphs before returning
     331      them. If set to ``False`` the method returns the graph it
     332      is working on. The second alternative is faster, but modifying
     333      any of the graph instances returned by the method may break
     334      the function's behaviour, as it is using these graphs to
     335      compute the next ones : only use ``copy_graph = False`` when
     336      you stick to *reading* the graphs returned.
     337
    329338    EXAMPLES:
    330339
    331340    Print graphs on 3 or less vertices::
     
    482491        sage: print 10, len([g for g in graphs(10,degree_sequence=[3]*10) if g.is_connected()]) # not tested
    483492        10 19
    484493
     494    Make sure that the graphs are really independent and the generator
     495    survives repeated vertex removal (trac 8458)::
     496
     497        sage: for G in graphs(3):
     498        ...       G.delete_vertex(0)
     499        ...       print(G.order())
     500        2
     501        2
     502        2
     503        2
     504
    485505    REFERENCE:
    486506
    487507    - Brendan D. McKay, Isomorph-Free Exhaustive generation.  *Journal
     
    64136433   
    64146434    def __call__(self, vertices=None, property=lambda x: True, augment='edges',
    64156435        size=None, deg_seq=None, degree_sequence=None, loops=False, implementation='c_graph',
    6416         sparse=True):
     6436        sparse=True, copy = True):
    64176437        """
    64186438        Accesses the generator of isomorphism class representatives.
    64196439        Iterates over distinct, exhaustive representatives. See the docstring
     
    64606480        """
    64616481        from sage.graphs.all import Graph
    64626482        from sage.misc.misc import deprecation
     6483        from copy import copy as copyfun
     6484
    64636485        if deg_seq is not None:
    64646486            deprecation("The argument name deg_seq is deprecated. It will be "
    64656487                        "removed in a future release of Sage. So, please use "
     
    64886510            g = Graph(loops=loops, implementation=implementation, sparse=sparse)
    64896511            for gg in canaug_traverse_vert(g, [], vertices, property, loops=loops, implementation=implementation, sparse=sparse):
    64906512                if extra_property(gg):
    6491                     yield gg
     6513                    yield copyfun(gg) if copy else gg
    64926514        elif augment == 'edges':
    64936515            if vertices is None:
    64946516                from sage.rings.all import Integer
    64956517                vertices = Integer(0)
    64966518                while True:
    64976519                    for g in self(vertices, loops=loops, implementation=implementation, sparse=sparse):
    6498                         yield g
     6520                        yield copyfun(g) if copy else g
    64996521                    vertices += 1
    65006522            g = Graph(vertices, loops=loops, implementation=implementation, sparse=sparse)
    65016523            gens = []
     
    65066528                gens.append(gen)
    65076529            for gg in canaug_traverse_edge(g, gens, property, loops=loops, implementation=implementation, sparse=sparse):
    65086530                if extra_property(gg):
    6509                     yield gg
     6531                    yield copyfun(gg) if copy else gg
    65106532        else:
    65116533            raise NotImplementedError
    65126534