Sage graphs are actually NetworkX graphs, wrapped in a Sage class. In fact, any graph can produce its underlying NetworkX graph. For example,
sage: import networkx sage: G = graphs.PetersenGraph() sage: N = G.networkx_graph() sage: isinstance(N, networkx.graph.Graph) True
The NetworkX graph is essentially a dictionary of dictionaries:
sage: N.adj {0: {1: None, 4: None, 5: None}, 1: {0: None, 2: None, 6: None}, 2: {1: None, 3: None, 7: None}, 3: {8: None, 2: None, 4: None}, 4: {0: None, 9: None, 3: None}, 5: {0: None, 8: None, 7: None}, 6: {8: None, 1: None, 9: None}, 7: {9: None, 2: None, 5: None}, 8: {3: None, 5: None, 6: None}, 9: {4: None, 6: None, 7: None}}
Each dictionary key is a vertex label, and each key in the following
dictionary is a neighbor of that vertex. In undirected graphs, there
is redundancy: for example, the dictionary containing the entry
1: {2: None}
implies it must contain {2: {1: None}
.
The innermost entry of None is related to edge labeling
(see section
See About this document... for information on suggesting changes.