In fact, I can use the following code (in conjunction with Edmonds' and Gallai's theorem) where the number of edges is less than or equal to 38.
num_vertices = 12
selected_graphs = []
for g in graphs.nauty_geng(f'{num_vertices} -c 11:38'):
if g.matching(value_only=True) == 2:
selected_graphs.append(g)
len(selected_graphs)
I'm wondering if it's possible to combine the structure of such graphs to improve efficiency. For example, Let G be a connected grpah with maximum matching size of 4. Let M=[u1u2,u3u4,u5u6,u7u8] be a matching. Let S=V(G)−(u1,u2…u8). Then:
- there is no edge in S.
- Any two vertices in S cannot be connected to the two endpoints of a matching in M, respectively.
Perhaps in this way, we can need to traverse the order of non-isomorphic graphs, only running some non-isomorphic graphs on 8 vertices. Or nauty can forbid matchings of fixed size, which could also achieve some purposes.
PS: Theorem (Erdős and Gallai, 1959) For all n≥2s and s≥1,
ex(n,Ms)=max that is, for any given graph G of order n, if |E(G)| > ex(n, M_s) , then ( G ) contains a matching of sizes.