is_graphical

Contents

is_graphical#

graph_tool.generation.is_graphical(out_deg, in_deg=None, self_loops=False, parallel_edges=False)[git][source]#

Check whether a degree sequence can be realized by a graph.

Parameters:
out_degiterable of int

The degrees of the vertices if in_deg is None, or their out-degrees otherwise.

in_degiterable of int (optional, default: None)

The in-degrees of the vertices, for a directed graph. It must have the same length as out_deg.

self_loopsbool (optional, default: False)

If True, self-loops are allowed in the realization.

parallel_edgesbool (optional, default: False)

If True, parallel edges are allowed in the realization.

Returns:
graphicalbool

True if there is a graph with the given degrees and constraints.

See also

realize_degree_sequence

Graph with a given degree sequence

random_graph

Random graph with a given degree sequence

is_joint_degree_graphical

Test for joint degree matrices

Notes

A degree sequence is graphical if there is a graph with these degrees. For undirected graphs, the sum of the degrees must be even, and a self-loop contributes two to the degree of its vertex. The degrees \(d_1 \ge d_2 \ge \dots \ge d_N\), in non-increasing order, are graphical without self-loops or parallel edges if and only if

\[\sum_{i=1}^k d_i \le k(k-1) + \sum_{i=k+1}^N \min(d_i, k)\]

for \(k=1,\dots,N\), which is the Erdős–Gallai theorem [erdos-graphs-1960]. If each vertex may have a self-loop, \(k(k-1)\) is replaced by \(k(k+1)\) [cairns-symmetric-2013]. If parallel edges are allowed but self-loops are not, the sequence is graphical if and only if \(d_1 \le \sum_{i>1} d_i\) [hakimi-realizability-1962], and if both are allowed, an even sum suffices.

For directed graphs, the out-degrees \(a_i\) and the in-degrees \(b_i\) must have the same sum. Without self-loops or parallel edges, with the vertices ordered by non-increasing \(a_i\) (and \(b_i\) for ties), they are graphical if and only if

\[\sum_{i=1}^k a_i \le \sum_{i=1}^k \min(b_i, k-1) + \sum_{i=k+1}^N \min(b_i, k)\]

for \(k=1,\dots,N\), which is the Fulkerson–Chen–Anstee theorem [fulkerson-zero-one-1960] [chen-realization-1966]. If each vertex may have a self-loop, the condition becomes \(\sum_{i=1}^k a_i \le \sum_{i=1}^N \min(b_i, k)\), which is the condition of the Gale–Ryser theorem for bipartite graphs [gale-theorem-1957] [ryser-combinatorial-1957]. If parallel edges are allowed but self-loops are not, the condition is \(a_i + b_i \le \sum_j a_j\) for every vertex, and if both are allowed, equal sums suffice.

The inequalities are evaluated for all \(k\) in a single pass, in time \(O(N\log N)\), dominated by the sorting of the degrees.

References

[erdos-graphs-1960]

Paul Erdős and Tibor Gallai, “Gráfok előírt fokú pontokkal” (Graphs with prescribed degrees of vertices), Matematikai Lapok 11, 264-274 (1960).

[cairns-symmetric-2013]

Grant Cairns and Stacey Mendan, “Symmetric bipartite graphs and graphs with loops”, arXiv: 1303.2145

[hakimi-realizability-1962]

S. L. Hakimi, “On realizability of a set of integers as degrees of the vertices of a linear graph. I”, Journal of the Society for Industrial and Applied Mathematics 10, 496-506 (1962), DOI: 10.1137/0110037 [sci-hub, @tor]

[fulkerson-zero-one-1960]

D. R. Fulkerson, “Zero-one matrices with zero trace”, Pacific Journal of Mathematics 10, 831-836 (1960), DOI: 10.2140/pjm.1960.10.831 [sci-hub, @tor]

[chen-realization-1966]

Wai-Kai Chen, “On the realization of a (p,s)-digraph with prescribed degrees”, Journal of the Franklin Institute 281, 406-422 (1966), DOI: 10.1016/0016-0032(66)90301-2 [sci-hub, @tor]

[gale-theorem-1957]

David Gale, “A theorem on flows in networks”, Pacific Journal of Mathematics 7, 1073-1082 (1957), DOI: 10.2140/pjm.1957.7.1073 [sci-hub, @tor]

[ryser-combinatorial-1957]

H. J. Ryser, “Combinatorial properties of matrices of zeros and ones”, Canadian Journal of Mathematics 9, 371-377 (1957), DOI: 10.4153/CJM-1957-044-3 [sci-hub, @tor]

Examples

>>> gt.is_graphical([3, 3, 3, 3])
True
>>> gt.is_graphical([3, 3, 1, 1])
False
>>> gt.is_graphical([3, 3, 1, 1], parallel_edges=True)
True
>>> gt.is_graphical([1, 1, 0], in_deg=[0, 1, 1])
True

The degrees of an existing graph are always graphical:

>>> g = gt.collection.data["polblogs"]
>>> gt.is_graphical(g.get_out_degrees(g.get_vertices()),
...                 in_deg=g.get_in_degrees(g.get_vertices()),
...                 self_loops=True, parallel_edges=True)
True