# HG changeset patch
# User Lukas Lansky <lansky@kam.mff.cuni.cz>
# Date 1325631840 0
# Node ID a72a3005d4ed13c33b82c15a7befacb7759a24ed
# Parent 05c9f113ccede59fbca9ae26587fa2c4578871c5
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 | - ``independent`` -- (default: ``True``) the graph generator can use parts |
| 329 | of already generated graphs to create new ones. That is fast, but any change |
| 330 | of an generated graph, like edge removal or label update, randomly propagates |
| 331 | to the others. Moreover, the generator can crash or produce incorrect results |
| 332 | if the changes to the resulted graphs are made before the end of generation. |
| 333 | Whenever ``independent`` is set to ``True``, the generator make sure that |
| 334 | resulting graphs are separated both from each other and from the inner state |
| 335 | of the generator. |
| 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, independent=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 |
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 copy(gg) if independent 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 copy(g) if independent 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 copy(gg) if independent else gg |
6474 | 6495 | else: |
6475 | 6496 | raise NotImplementedError |
6476 | 6497 | |