realize_bipartite_degree_sequence#
- graph_tool.generation.realize_bipartite_degree_sequence(a_deg, b_deg, method='smallest', parallel_edges=False)[git][source]#
Return a bipartite graph with the given degrees.
- Parameters:
- a_degiterable of
int Degrees of the vertices of the first part.
- b_degiterable of
int Degrees of the vertices of the second part.
- method
str(optional, default:"smallest") Order in which the vertices are connected:
"smallest","largest","index","havel_hakimi","reverse_havel_hakimi", or"alternating_havel_hakimi"(see below).- parallel_edges
bool(optional, default:False) If
True, parallel edges are allowed.
- a_degiterable of
- Returns:
- g
Graph The undirected bipartite graph, where the vertices of the first part are \(0,\dots,N_a-1\), followed by those of the second part.
- g
See also
realize_degree_sequenceRealization of degree sequences
generate_bipartite_configurationRandom bipartite configuration model
Notes
The graph is built by a Havel-Hakimi-type procedure, where a source vertex is chosen and connected to distinct vertices of the other part. With
method="smallest"or"largest", the source is the vertex (from either part) with the smallest or largest remaining degree, and with"index"the sources are taken in index order; the targets are the vertices of the other part with the largest remaining degrees. The method"smallest"yields a connected graph, if one exists, and all three yield a simple graph whenever one exists (by the Gale-Ryser theorem [gale-theorem-1957] [ryser-combinatorial-1957]). The methods"havel_hakimi","reverse_havel_hakimi", and"alternating_havel_hakimi"take only the vertices of the first part as sources, in decreasing order of degree, and connect each to the vertices of the second part with the largest remaining degrees, with the smallest ones, or with half of each (the last two may fail for realizable sequences). Withparallel_edges=True, every stub is connected to the vertex of the other part with the largest remaining degree. AValueErroris raised if the sequences cannot be realized in this way. The algorithm runs in time \(O(N + E\log N)\).References
[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
>>> g = gt.realize_bipartite_degree_sequence([3, 2, 1], [2, 2, 2]) >>> print(sorted(tuple(sorted(e)) for e in g.get_edges().tolist())) [(0, 3), (0, 4), (0, 5), (1, 3), (1, 4), (2, 5)]
The graph is drawn as follows, with the two parts in different colors:
>>> b = g.new_vp("int", vals=[0] * 3 + [1] * 3) >>> cmap = matplotlib.colors.ListedColormap( ... ["#9bbedc", "#f28c8e"]) >>> gt.graph_draw(g, pos=gt.sfdp_layout(g), vertex_fill_color=b, vcmap=cmap, ... output="realize_bipartite_degree_sequence-example.pdf") <...>
Realization of the bipartite degree sequences \((3, 2, 1)\) (blue) and \((2, 2, 2)\) (red).#