Ticket #8458: trac_8458_independent_graphs.2.patch

File trac_8458_independent_graphs.2.patch, 3.4 KB (added by brunellus, 10 years ago)
  • sage/graphs/graph_generators.py

    # HG changeset patch
    # User Lukas Lansky <lansky@kam.mff.cuni.cz>
    # Date 1325631840 0
    # Node ID e241ffc15f159ab980fc36e45480b200b9c20d36
    # Parent  9e29a3d84c48c399daaf3920bcb8b17273a0e876
    Trac 8458: generated graphs are independent
    
    diff --git a/sage/graphs/graph_generators.py b/sage/graphs/graph_generators.py
    a b  
    325325    - ``sparse`` -- (default: ``True``) ignored if implementation is not
    326326      ``'c_graph'``.
    327327
     328    - ``copy`` (boolean) -- If set to ``True`` (default)
     329      this method makes copies of the graphs before returning
     330      them. If set to ``False`` the method returns the graph it
     331      is working on. The second alternative is faster, but modifying
     332      any of the graph instances returned by the method may break
     333      the function's behaviour, as it is using these graphs to
     334      compute the next ones : only use ``copy_graph = False`` when
     335      you stick to *reading* the graphs returned.
     336
    328337    EXAMPLES:
    329338
    330339    Print graphs on 3 or less vertices::
     
    481490        sage: print 10, len([g for g in graphs(10,deg_seq=[3]*10) if g.is_connected()]) # not tested
    482491        10 19
    483492
     493    Make sure that the graphs are really independent and the generator
     494    survives repeated vertex removal (trac 8458)::
     495
     496        sage: for G in graphs(3):
     497        ...       G.delete_vertex(0)
     498        ...       print(G.order())
     499        2
     500        2
     501        2
     502        2
     503
    484504    REFERENCE:
    485505
    486506    - Brendan D. McKay, Isomorph-Free Exhaustive generation.  *Journal
     
    63846404   
    63856405    def __call__(self, vertices=None, property=lambda x: True, augment='edges',
    63866406        size=None, deg_seq=None, loops=False, implementation='c_graph',
    6387         sparse=True):
     6407        sparse=True, copy=True):
    63886408        """
    63896409        Accesses the generator of isomorphism class representatives.
    63906410        Iterates over distinct, exhaustive representatives. See the docstring
     
    64306450          pages 306-324.
    64316451        """
    64326452        from sage.graphs.all import Graph
     6453        from copy import copy as copyfun
    64336454        if deg_seq is not None:
    64346455            if vertices is None:
    64356456                raise NotImplementedError
     
    64526473            g = Graph(loops=loops, implementation=implementation, sparse=sparse)
    64536474            for gg in canaug_traverse_vert(g, [], vertices, property, loops=loops, implementation=implementation, sparse=sparse):
    64546475                if extra_property(gg):
    6455                     yield gg
     6476                    yield copyfun(gg) if copy else gg
    64566477        elif augment == 'edges':
    64576478            if vertices is None:
    64586479                from sage.rings.all import Integer
    64596480                vertices = Integer(0)
    64606481                while True:
    64616482                    for g in self(vertices, loops=loops, implementation=implementation, sparse=sparse):
    6462                         yield g
     6483                        yield copyfun(g) if copy else g
    64636484                    vertices += 1
    64646485            g = Graph(vertices, loops=loops, implementation=implementation, sparse=sparse)
    64656486            gens = []
     
    64706491                gens.append(gen)
    64716492            for gg in canaug_traverse_edge(g, gens, property, loops=loops, implementation=implementation, sparse=sparse):
    64726493                if extra_property(gg):
    6473                     yield gg
     6494                    yield copyfun(gg) if copy else gg
    64746495        else:
    64756496            raise NotImplementedError
    64766497