k_factor#
- k_factor(G, k, matching_weight='weight')[source]#
Compute a k-factor of G
A k-factor of a graph is a spanning k-regular subgraph. A spanning k-regular subgraph of G is a subgraph that contains each vertex of G and a subset of the edges of G such that each vertex has degree k.
- Parameters:
- GNetworkX graph
Undirected graph
- matching_weight: string, optional (default=’weight’)
Edge data key corresponding to the edge weight. Used for finding the max-weighted perfect matching. If key not found, uses 1 as weight.
- Returns:
- G2NetworkX graph
A k-factor of G
References
[1]“An algorithm for computing simple k-factors.”, Meijer, Henk, Yurai Núñez-Rodríguez, and David Rappaport, Information processing letters, 2009.
Examples
>>> G = nx.Graph([(1, 2), (2, 3), (3, 4), (4, 1)]) >>> G2 = nx.k_factor(G, k=1) >>> G2.edges() EdgeView([(1, 2), (3, 4)])