Determines whether a graph is regular. A regular graph is a graph where all nodes have the same degree. A regular digraph is a graph where all nodes have the same indegree and all nodes have the same outdegree. Parameters ---------- G : NetworkX graph Returns -----
(G)
| 8 | |
| 9 | @nx._dispatchable |
| 10 | def is_regular(G): |
| 11 | """Determines whether a graph is regular. |
| 12 | |
| 13 | A regular graph is a graph where all nodes have the same degree. A regular |
| 14 | digraph is a graph where all nodes have the same indegree and all nodes |
| 15 | have the same outdegree. |
| 16 | |
| 17 | Parameters |
| 18 | ---------- |
| 19 | G : NetworkX graph |
| 20 | |
| 21 | Returns |
| 22 | ------- |
| 23 | bool |
| 24 | Whether the given graph or digraph is regular. |
| 25 | |
| 26 | Examples |
| 27 | -------- |
| 28 | >>> G = nx.DiGraph([(1, 2), (2, 3), (3, 4), (4, 1)]) |
| 29 | >>> nx.is_regular(G) |
| 30 | True |
| 31 | |
| 32 | """ |
| 33 | if len(G) == 0: |
| 34 | raise nx.NetworkXPointlessConcept("Graph has no nodes.") |
| 35 | n1 = nx.utils.arbitrary_element(G) |
| 36 | if not G.is_directed(): |
| 37 | d1 = G.degree(n1) |
| 38 | return all(d1 == d for _, d in G.degree) |
| 39 | else: |
| 40 | d_in = G.in_degree(n1) |
| 41 | in_regular = (d_in == d for _, d in G.in_degree) |
| 42 | d_out = G.out_degree(n1) |
| 43 | out_regular = (d_out == d for _, d in G.out_degree) |
| 44 | return all(in_regular) and all(out_regular) |
| 45 | |
| 46 | |
| 47 | @not_implemented_for("directed") |
nothing calls this directly
no test coverage detected
searching dependent graphs…