Ticket #11182: trac_11182-review.patch
File trac_11182-review.patch, 4.6 KB (added by , 10 years ago) |
---|
-
sage/graphs/digraph.py
# HG changeset patch # User Nathann Cohen <nathann.cohen@gmail.com> # Date 1302788234 -7200 # Node ID 0ea746afe79e1bc496f3a7a054561e98a7d5e7ce # Parent 0fd28743cd399b25b0324ffd8a91088497a518fb trac 11182 -- replace NetworkX empty dictionaries as edge labels with Sage default None (reviewer's patch) diff -r 0fd28743cd39 -r 0ea746afe79e sage/graphs/digraph.py
a b 83 83 84 84 INPUT: 85 85 86 - ``data`` - can be any of the following :86 - ``data`` - can be any of the following (see the ``format`` keyword): 87 87 88 88 #. A dictionary of dictionaries 89 89 … … 93 93 94 94 #. A Sage adjacency matrix or incidence matrix 95 95 96 #. A pygraphviz agraph96 #. A pygraphviz graph 97 97 98 98 #. A SciPy sparse matrix 99 99 … … 133 133 - ``'weighted_adjacency_matrix'`` - a square Sage 134 134 matrix M, with M[i,j] equal to the weight of the single edge {i,j}. 135 135 Given this format, weighted is ignored (assumed True). 136 137 - ``NX`` - data must be a NetworkX DiGraph. 138 139 .. NOTE:: 140 141 As Sage's default edge labels is ``None`` while NetworkX uses 142 ``{}``, the ``{}`` labels of a NetworkX digraph are automatically 143 set to ``None`` when it is converted to a Sage graph. This 144 behaviour can be overruled by setting the keyword 145 ``convert_empty_dict_labels_to_None`` to ``False`` (it is 146 ``True`` by default). 136 147 137 148 - ``boundary`` - a list of boundary vertices, if none, 138 149 digraph is considered as a 'digraph without boundary' -
sage/graphs/graph.py
diff -r 0fd28743cd39 -r 0ea746afe79e sage/graphs/graph.py
a b 75 75 Graph Format 76 76 ------------ 77 77 78 The Sage Graph Class: NetworkX plus79 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~80 81 Sage graphs are actually NetworkX graphs, wrapped in a Sage class.82 In fact, any graph can produce its underlying NetworkX graph. For83 example,84 85 ::86 87 sage: import networkx88 sage: G = graphs.PetersenGraph()89 sage: N = G.networkx_graph()90 sage: isinstance(N, networkx.graph.Graph)91 True92 93 The NetworkX graph is essentially a dictionary of dictionaries of dictionaries::94 95 sage: N.adj96 {0: {1: {}, 4: {}, 5: {}}, 1: {0: {}, 2: {}, 6: {}}, 2: {1: {}, 3: {}, 7: {}}, 3: {8: {}, 2: {}, 4: {}}, 4: {0: {}, 9: {}, 3: {}}, 5: {0: {}, 8: {}, 7: {}}, 6: {8: {}, 1: {}, 9: {}}, 7: {9: {}, 2: {}, 5: {}}, 8: {3: {}, 5: {}, 6: {}}, 9: {4: {}, 6: {}, 7: {}}}97 98 Each dictionary key is a vertex label, and each key in the99 following dictionary is a neighbor of that vertex. In undirected100 graphs, there is redundancy: for example, the dictionary containing101 the entry ``1: {2: {}}`` implies it must contain102 ``{2: {1: {}}``. The innermost entry of ``{}`` is103 related to edge labeling (see section :ref:`Graph:labels`).104 105 78 Supported formats 106 79 ~~~~~~~~~~~~~~~~~ 107 80 … … 123 96 124 97 :: 125 98 99 sage: import networkx 126 100 sage: K = networkx.complete_bipartite_graph(12,7) 127 101 sage: G = Graph(K) 128 102 sage: G.degree() … … 460 434 461 435 INPUT: 462 436 463 - ``data`` -- can be any of the following :437 - ``data`` -- can be any of the following (see the ``format`` argument): 464 438 465 439 #. A dictionary of dictionaries 466 440 … … 470 444 471 445 #. A Sage adjacency matrix or incidence matrix 472 446 473 #. A pygraphviz agraph447 #. A pygraphviz graph 474 448 475 449 #. A SciPy sparse matrix 476 450 477 #. A NetworkX digraph451 #. A NetworkX graph 478 452 479 453 - ``pos`` - a positioning dictionary: for example, the 480 454 spring layout from NetworkX for the 5-cycle is:: … … 523 497 iterable container of elliptic curves, and the graph produced has 524 498 each curve as a vertex (it's Cremona label) and an edge E-F 525 499 labelled p if and only if E is congruent to F mod p 500 501 - ``NX`` - data must be a NetworkX Graph. 502 503 .. NOTE:: 504 505 As Sage's default edge labels is ``None`` while NetworkX uses 506 ``{}``, the ``{}`` labels of a NetworkX graph are automatically 507 set to ``None`` when it is converted to a Sage graph. This 508 behaviour can be overruled by setting the keyword 509 ``convert_empty_dict_labels_to_None`` to ``False`` (it is 510 ``True`` by default). 526 511 527 512 - ``boundary`` - a list of boundary vertices, if 528 513 empty, graph is considered as a 'graph without boundary'