# Ticket #8458: trac_8458_independent_graphs.2.patch

File trac_8458_independent_graphs.2.patch, 3.4 KB (added by brunellus, 11 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 - ``sparse`` -- (default: ``True``) ignored if implementation is not ``'c_graph'``. - ``copy`` (boolean) -- If set to ``True`` (default) this method makes copies of the graphs before returning them. If set to ``False`` the method returns the graph it is working on. The second alternative is faster, but modifying any of the graph instances returned by the method may break the function's behaviour, as it is using these graphs to compute the next ones : only use ``copy_graph = False`` when you stick to *reading* the graphs returned. EXAMPLES: Print graphs on 3 or less vertices:: sage: print 10, len([g for g in graphs(10,deg_seq=[3]*10) if g.is_connected()]) # not tested 10 19 Make sure that the graphs are really independent and the generator survives repeated vertex removal (trac 8458):: sage: for G in graphs(3): ...       G.delete_vertex(0) ...       print(G.order()) 2 2 2 2 REFERENCE: - Brendan D. McKay, Isomorph-Free Exhaustive generation.  *Journal def __call__(self, vertices=None, property=lambda x: True, augment='edges', size=None, deg_seq=None, loops=False, implementation='c_graph', sparse=True): sparse=True, copy=True): """ Accesses the generator of isomorphism class representatives. Iterates over distinct, exhaustive representatives. See the docstring pages 306-324. """ from sage.graphs.all import Graph from copy import copy as copyfun if deg_seq is not None: if vertices is None: raise NotImplementedError g = Graph(loops=loops, implementation=implementation, sparse=sparse) for gg in canaug_traverse_vert(g, [], vertices, property, loops=loops, implementation=implementation, sparse=sparse): if extra_property(gg): yield gg yield copyfun(gg) if copy else gg elif augment == 'edges': if vertices is None: from sage.rings.all import Integer vertices = Integer(0) while True: for g in self(vertices, loops=loops, implementation=implementation, sparse=sparse): yield g yield copyfun(g) if copy else g vertices += 1 g = Graph(vertices, loops=loops, implementation=implementation, sparse=sparse) gens = [] gens.append(gen) for gg in canaug_traverse_edge(g, gens, property, loops=loops, implementation=implementation, sparse=sparse): if extra_property(gg): yield gg yield copyfun(gg) if copy else gg else: raise NotImplementedError