# 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
|
|
326 | 326 | - ``sparse`` -- (default: ``True``) ignored if implementation is not |
327 | 327 | ``'c_graph'``. |
328 | 328 | |
| 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 | |
329 | 338 | EXAMPLES: |
330 | 339 | |
331 | 340 | Print graphs on 3 or less vertices:: |
… |
… |
|
482 | 491 | sage: print 10, len([g for g in graphs(10,degree_sequence=[3]*10) if g.is_connected()]) # not tested |
483 | 492 | 10 19 |
484 | 493 | |
| 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 | |
485 | 505 | REFERENCE: |
486 | 506 | |
487 | 507 | - Brendan D. McKay, Isomorph-Free Exhaustive generation. *Journal |
… |
… |
|
6413 | 6433 | |
6414 | 6434 | def __call__(self, vertices=None, property=lambda x: True, augment='edges', |
6415 | 6435 | size=None, deg_seq=None, degree_sequence=None, loops=False, implementation='c_graph', |
6416 | | sparse=True): |
| 6436 | sparse=True, copy = True): |
6417 | 6437 | """ |
6418 | 6438 | Accesses the generator of isomorphism class representatives. |
6419 | 6439 | Iterates over distinct, exhaustive representatives. See the docstring |
… |
… |
|
6460 | 6480 | """ |
6461 | 6481 | from sage.graphs.all import Graph |
6462 | 6482 | from sage.misc.misc import deprecation |
| 6483 | from copy import copy as copyfun |
| 6484 | |
6463 | 6485 | if deg_seq is not None: |
6464 | 6486 | deprecation("The argument name deg_seq is deprecated. It will be " |
6465 | 6487 | "removed in a future release of Sage. So, please use " |
… |
… |
|
6488 | 6510 | g = Graph(loops=loops, implementation=implementation, sparse=sparse) |
6489 | 6511 | for gg in canaug_traverse_vert(g, [], vertices, property, loops=loops, implementation=implementation, sparse=sparse): |
6490 | 6512 | if extra_property(gg): |
6491 | | yield gg |
| 6513 | yield copyfun(gg) if copy else gg |
6492 | 6514 | elif augment == 'edges': |
6493 | 6515 | if vertices is None: |
6494 | 6516 | from sage.rings.all import Integer |
6495 | 6517 | vertices = Integer(0) |
6496 | 6518 | while True: |
6497 | 6519 | for g in self(vertices, loops=loops, implementation=implementation, sparse=sparse): |
6498 | | yield g |
| 6520 | yield copyfun(g) if copy else g |
6499 | 6521 | vertices += 1 |
6500 | 6522 | g = Graph(vertices, loops=loops, implementation=implementation, sparse=sparse) |
6501 | 6523 | gens = [] |
… |
… |
|
6506 | 6528 | gens.append(gen) |
6507 | 6529 | for gg in canaug_traverse_edge(g, gens, property, loops=loops, implementation=implementation, sparse=sparse): |
6508 | 6530 | if extra_property(gg): |
6509 | | yield gg |
| 6531 | yield copyfun(gg) if copy else gg |
6510 | 6532 | else: |
6511 | 6533 | raise NotImplementedError |
6512 | 6534 | |