# HG changeset patch
# User Nathann Cohen <nathann.cohen@gmail.com>
# Date 1299736826 -28800
# Node ID 299c2995b46c8fb70a1785c46017e67227c67ea5
# Parent 361a4ad7d52c69b64ae2e658ffd0820af0d87e93
trac 10900 -- 100% doctest coverage for graphs
diff -r 361a4ad7d52c -r 299c2995b46c sage/graphs/base/c_graph.pyx
a
|
b
|
|
2885 | 2885 | - ``test_in`` -- boolean; whether we want to consider the in-neighbors of |
2886 | 2886 | the graph to be traversed. For undirected graphs, we consider both |
2887 | 2887 | the in- and out-neighbors. |
| 2888 | |
| 2889 | EXAMPLE:: |
| 2890 | |
| 2891 | sage: g = graphs.PetersenGraph() |
| 2892 | sage: list(g.breadth_first_search(0)) |
| 2893 | [0, 1, 4, 5, 2, 6, 3, 9, 7, 8] |
2888 | 2894 | """ |
2889 | 2895 | |
2890 | 2896 | cdef graph |
… |
… |
|
2925 | 2931 | - ``ignore_direction`` -- boolean (default: ``False``). This is only |
2926 | 2932 | relevant to digraphs. If ``graph`` is a digraph, ignore all |
2927 | 2933 | orientations and consider the graph as undirected. |
| 2934 | |
| 2935 | EXAMPLE:: |
| 2936 | |
| 2937 | sage: g = graphs.PetersenGraph() |
| 2938 | sage: list(g.breadth_first_search(0)) |
| 2939 | [0, 1, 4, 5, 2, 6, 3, 9, 7, 8] |
2928 | 2940 | """ |
2929 | 2941 | self.graph = graph |
2930 | 2942 | self.direction = direction |
… |
… |
|
2946 | 2958 | def __iter__(self): |
2947 | 2959 | r""" |
2948 | 2960 | Return an iterator object over a traversal of a graph. |
| 2961 | |
| 2962 | EXAMPLE:: |
| 2963 | |
| 2964 | sage: g = graphs.PetersenGraph() |
| 2965 | sage: g.breadth_first_search(0) |
| 2966 | <generator object breadth_first_search at ... |
2949 | 2967 | """ |
2950 | 2968 | return self |
2951 | 2969 | |
2952 | 2970 | def __next__(self): |
2953 | 2971 | r""" |
2954 | 2972 | Return the next vertex in a traversal of a graph. |
| 2973 | |
| 2974 | EXAMPLE:: |
| 2975 | |
| 2976 | sage: g = graphs.PetersenGraph() |
| 2977 | sage: g.breadth_first_search(0) |
| 2978 | <generator object breadth_first_search at ... |
| 2979 | sage: g.breadth_first_search(0).next() |
| 2980 | 0 |
2955 | 2981 | """ |
2956 | 2982 | cdef int v_int |
2957 | 2983 | cdef int w_int |
diff -r 361a4ad7d52c -r 299c2995b46c sage/graphs/base/dense_graph.pyx
a
|
b
|
|
156 | 156 | Memory usage is |
157 | 157 | |
158 | 158 | O( (nverts + extra_vertices)^2 ). |
159 | | |
| 159 | |
| 160 | EXAMPLE:: |
| 161 | |
| 162 | sage: from sage.graphs.base.dense_graph import DenseGraph |
| 163 | sage: D = DenseGraph(nverts = 10, extra_vertices = 10) |
160 | 164 | """ |
161 | 165 | if nverts == 0 and extra_vertices == 0: |
162 | 166 | raise RuntimeError('Dense graphs must allocate space for vertices!') |
diff -r 361a4ad7d52c -r 299c2995b46c sage/graphs/base/graph_backends.py
a
|
b
|
|
480 | 480 | def __init__(self): |
481 | 481 | """ |
482 | 482 | Issue deprecation warnings for the old networkx XGraph formats |
| 483 | |
| 484 | EXAMPLE:: |
| 485 | |
| 486 | sage: from sage.graphs.base.graph_backends import NetworkXGraphDeprecated |
| 487 | sage: NetworkXGraphDeprecated() |
| 488 | doctest:... |
| 489 | <class 'sage.graphs.base.graph_backends.NetworkXGraphDeprecated'> |
483 | 490 | """ |
484 | 491 | import warnings |
485 | 492 | from sage.misc.misc import deprecation |
… |
… |
|
532 | 539 | def __init__(self): |
533 | 540 | """ |
534 | 541 | Issue deprecation warnings for the old networkx XDiGraph formats |
| 542 | |
| 543 | EXAMPLE:: |
| 544 | |
| 545 | sage: from sage.graphs.base.graph_backends import NetworkXDiGraphDeprecated |
| 546 | sage: NetworkXDiGraphDeprecated() |
| 547 | doctest:... |
| 548 | <class 'sage.graphs.base.graph_backends.NetworkXDiGraphDeprecated'> |
535 | 549 | """ |
536 | 550 | import warnings |
537 | 551 | from sage.misc.misc import deprecation |
… |
… |
|
913 | 927 | """ |
914 | 928 | Iterate over the incoming edges incident to a sequence of vertices. |
915 | 929 | Special case, only for internal use. |
| 930 | |
| 931 | EXAMPLE:: |
| 932 | |
| 933 | sage: g = DiGraph(graphs.PetersenGraph(), implementation="networkx")._backend |
| 934 | sage: sorted(list(g.iterator_in_edges([0,1], True))) |
| 935 | [(0, 1, None), (1, 0, None), (2, 1, None), (4, 0, None), (5, 0, None), (6, 1, None)] |
916 | 936 | """ |
917 | 937 | try: |
918 | 938 | assert(not isinstance(self._nxg, (NetworkXGraphDeprecated, NetworkXDiGraphDeprecated))) |
… |
… |
|
955 | 975 | """ |
956 | 976 | Iterate over the outbound edges incident to a sequence of vertices. |
957 | 977 | Special case, only for internal use. |
| 978 | |
| 979 | EXAMPLE:: |
| 980 | |
| 981 | sage: g = DiGraph(graphs.PetersenGraph(), implementation="networkx")._backend |
| 982 | sage: sorted(list(g.iterator_out_edges([0,1], True))) |
| 983 | [(0, 1, None), (0, 4, None), (0, 5, None), (1, 0, None), (1, 2, None), (1, 6, None)] |
958 | 984 | """ |
959 | 985 | try: |
960 | 986 | assert(not isinstance(self._nxg, (NetworkXGraphDeprecated, NetworkXDiGraphDeprecated))) |
diff -r 361a4ad7d52c -r 299c2995b46c sage/graphs/base/sparse_graph.pyx
a
|
b
|
|
285 | 285 | Memory usage is roughly |
286 | 286 | |
287 | 287 | O( (nverts + extra_vertices)*expected_degree + num_arcs ). |
288 | | |
289 | | """ |
| 288 | |
| 289 | EXAMPLE:: |
| 290 | |
| 291 | sage: from sage.graphs.base.sparse_graph import SparseGraph |
| 292 | sage: S = SparseGraph(nverts = 10, expected_degree = 3, extra_vertices = 10) |
| 293 | |
| 294 | """ |
290 | 295 | cdef int i = 1 |
291 | 296 | if nverts == 0 and extra_vertices == 0: |
292 | 297 | raise RuntimeError('Sparse graphs must allocate space for vertices!') |
diff -r 361a4ad7d52c -r 299c2995b46c sage/graphs/generic_graph.py
a
|
b
|
|
13302 | 13302 | |
13303 | 13303 | def _keys_for_vertices(self): |
13304 | 13304 | """ |
13305 | | Returns a function mapping each vertex to a unique and hopefully readable string |
| 13305 | Returns a function mapping each vertex to a unique and hopefully |
| 13306 | readable string |
| 13307 | |
| 13308 | EXAMPLE:: |
| 13309 | |
| 13310 | sage: g = graphs.Grid2dGraph(5,5) |
| 13311 | sage: g._keys_for_vertices() |
| 13312 | <function key at ... |
13306 | 13313 | """ |
13307 | 13314 | from sage.graphs.dot2tex_utils import key, key_with_hash |
13308 | 13315 | if len(set(key(v) for v in self)) < len(self.vertices()): |
diff -r 361a4ad7d52c -r 299c2995b46c sage/graphs/generic_graph_pyx.pyx
a
|
b
|
|
483 | 483 | |
484 | 484 | This constructor only checks there is no inconsistency in the |
485 | 485 | input : `G` and `H` are both graphs or both digraphs. |
| 486 | |
| 487 | EXAMPLE:: |
| 488 | |
| 489 | sage: g = graphs.PetersenGraph() |
| 490 | sage: g.subgraph_search(graphs.CycleGraph(5)) |
| 491 | Subgraph of (Petersen graph): Graph on 5 vertices |
486 | 492 | """ |
487 | 493 | if sum([G.is_directed(), H.is_directed()]) == 1: |
488 | 494 | raise ValueError("One graph can not be directed while the other is not.") |
… |
… |
|
596 | 602 | Cython constructor |
597 | 603 | |
598 | 604 | This method initializes all the C values. |
| 605 | |
| 606 | EXAMPLE:: |
| 607 | |
| 608 | sage: g = graphs.PetersenGraph() |
| 609 | sage: g.subgraph_search(graphs.CycleGraph(5)) |
| 610 | Subgraph of (Petersen graph): Graph on 5 vertices |
599 | 611 | """ |
600 | 612 | |
601 | 613 | # Storing the number of vertices |