# 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
|
|
325 | 325 | - ``sparse`` -- (default: ``True``) ignored if implementation is not |
326 | 326 | ``'c_graph'``. |
327 | 327 | |
| 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 | |
328 | 337 | EXAMPLES: |
329 | 338 | |
330 | 339 | Print graphs on 3 or less vertices:: |
… |
… |
|
481 | 490 | sage: print 10, len([g for g in graphs(10,deg_seq=[3]*10) if g.is_connected()]) # not tested |
482 | 491 | 10 19 |
483 | 492 | |
| 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 | |
484 | 504 | REFERENCE: |
485 | 505 | |
486 | 506 | - Brendan D. McKay, Isomorph-Free Exhaustive generation. *Journal |
… |
… |
|
6384 | 6404 | |
6385 | 6405 | def __call__(self, vertices=None, property=lambda x: True, augment='edges', |
6386 | 6406 | size=None, deg_seq=None, loops=False, implementation='c_graph', |
6387 | | sparse=True): |
| 6407 | sparse=True, copy=True): |
6388 | 6408 | """ |
6389 | 6409 | Accesses the generator of isomorphism class representatives. |
6390 | 6410 | Iterates over distinct, exhaustive representatives. See the docstring |
… |
… |
|
6430 | 6450 | pages 306-324. |
6431 | 6451 | """ |
6432 | 6452 | from sage.graphs.all import Graph |
| 6453 | from copy import copy as copyfun |
6433 | 6454 | if deg_seq is not None: |
6434 | 6455 | if vertices is None: |
6435 | 6456 | raise NotImplementedError |
… |
… |
|
6452 | 6473 | g = Graph(loops=loops, implementation=implementation, sparse=sparse) |
6453 | 6474 | for gg in canaug_traverse_vert(g, [], vertices, property, loops=loops, implementation=implementation, sparse=sparse): |
6454 | 6475 | if extra_property(gg): |
6455 | | yield gg |
| 6476 | yield copyfun(gg) if copy else gg |
6456 | 6477 | elif augment == 'edges': |
6457 | 6478 | if vertices is None: |
6458 | 6479 | from sage.rings.all import Integer |
6459 | 6480 | vertices = Integer(0) |
6460 | 6481 | while True: |
6461 | 6482 | for g in self(vertices, loops=loops, implementation=implementation, sparse=sparse): |
6462 | | yield g |
| 6483 | yield copyfun(g) if copy else g |
6463 | 6484 | vertices += 1 |
6464 | 6485 | g = Graph(vertices, loops=loops, implementation=implementation, sparse=sparse) |
6465 | 6486 | gens = [] |
… |
… |
|
6470 | 6491 | gens.append(gen) |
6471 | 6492 | for gg in canaug_traverse_edge(g, gens, property, loops=loops, implementation=implementation, sparse=sparse): |
6472 | 6493 | if extra_property(gg): |
6473 | | yield gg |
| 6494 | yield copyfun(gg) if copy else gg |
6474 | 6495 | else: |
6475 | 6496 | raise NotImplementedError |
6476 | 6497 | |