k_factor#
- k_factor(G, k, matching_weight='weight')[source]#
Compute a
k
-factor of a graph.A
k
-factor of a graph is a spanningk
-regular subgraph. A spanningk
-regular subgraph ofG
is a subgraph that contains each node ofG
and a subset of the edges ofG
such that each node has degreek
.- Parameters:
- GNetworkX graph
An undirected graph.
- kint
The degree of the
k
-factor.- matching_weight: string, optional (default=”weight”)
Edge attribute name corresponding to the edge weight. If not present, the edge is assumed to have weight 1. Used for finding the max-weighted perfect matching.
- Returns:
- NetworkX graph
A
k
-factor ofG
.
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)]) >>> KF = nx.k_factor(G, k=1) >>> KF.edges() EdgeView([(1, 2), (3, 4)])