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=[u_1u_2,u_3u_4,u_5u_6,u_7u_8]$ be a matching. Let $S=V(G)-(u_1,u_2\dots u_8)$. 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 \geq 2 s$ and $s \geq 1$,
$$ ex(n, M_s) = \max \large( ( \frac{s - 1}{2} ) + (s - 1)(n - s + 1), \left( \frac{2s - 1}{2} \right) \large) $$ that is, for any given graph $G$ of order $ n$, if $|E(G)| > ex(n, M_s) $, then ( G ) contains a matching of size$s$.