Advanced maths

Maximum weight matching calculator for a general graph

General-graph matching selects pairwise disjoint edges even when the input contains odd cycles.

Your numbers

Vertices are indexed 0 through n−1.
Rows from,to,weight; absent weight means one. Leave empty for no edges.

Calculated on your device. Your inputs aren’t sent to us.

Your result

Ready when you are

Enter your inputs and select Calculate.

Report an issue

Behind the numbers

How this calculation works

General-graph matching selects pairwise disjoint edges even when the input contains odd cycles. This calculator uses exact bounded subset dynamic programming and lets you prioritize either total weight or cardinality followed by weight. The returned edge list can be checked directly against the disjoint-endpoint constraint.

THE FORMULAmax Σ_(e in M) w_e, subject to no two selected edges sharing a vertex.

A worked example

A triangle with edge weights two, five and three permits only one matched edge. The maximum-weight matching chooses the edge of weight five. A bipartite matching algorithm cannot be applied to the triangle without changing its graph, which is why this is a separate general-graph task.

Good to know

Simple undirected graphs up to 18 vertices, bounded finite weights. Negative weights are allowed; weight-only mode may choose the empty matching. Exact small-graph method, no large-graph blossom-performance claim. Zero-based endpoints and objective priorities are explicit.

Odd cycles require a general matching method

A matching uses each vertex at most once, regardless of how many edges connect near it. General graphs can contain odd cycles and do not necessarily split into two independent vertex classes. Forcing such a graph into a bipartite assignment table would discard or duplicate relationships and solve a different pairing problem.

The subset dynamic program selects the first remaining vertex, then compares leaving it unmatched with pairing it along each available incident edge. Every recursive alternative removes the consumed vertices. Memoization avoids solving the same remaining-vertex set repeatedly, while complete enumeration of those choices gives the bounded optimum.

A weighted triangle has a one-edge optimal matching012weight 253Choose edge 1–2Maximum weight = 5
A triangle with edge weights two, five and three permits only one matched edge. The maximum-weight matching chooses the edge of weight five. A bipartite matching algorithm cannot be applied to the triangle without changing its graph, which is why this is a separate general-graph task.

The Maximum bipartite matching calculator from an edge list covers the nearby task. General graphs permit odd cycles, so bipartite-only matching/assignment is insufficient.

Choose weight or cardinality deliberately

Weight-only mode maximizes the sum of selected weights. When every candidate edge has negative weight, the empty matching is optimal with value zero. This is not a failure to find pairs: adding a negative edge would worsen that particular objective, even when more vertices could be matched.

Cardinality-first mode instead maximizes the number of matched edges before comparing total weight among ties. The two modes can return different answers on the same graph. The selector keeps that priority explicit rather than treating a maximum-weight matching as if it automatically matched the greatest possible number of people or objects.

The selected edges provide a direct certificate

The result lists original edge indices and their endpoints, allowing disjointness and total weight to be checked directly. An unmatched vertex is permitted. The page does not infer a perfect matching requirement, force every vertex into a pair or make a fairness judgment from a purely weighted optimization.

Small random graphs can be checked by enumerating all edge subsets and rejecting conflicting endpoints. Independent general-matching references provide a second comparison. The vertex cap keeps the exact subset method suitable for a browser; it is not a claim to implement the scalable blossom algorithm used by larger graph packages.

Choose the objective before comparing matchings

A matching is a set of edges with no shared endpoints. Maximum weight maximizes the sum of selected edge weights, allowing vertices to remain unmatched. Maximum cardinality instead prioritizes the number of selected edges, using weight only to break ties between equally large matchings. A matching can be maximal, meaning no edge can be added, without being optimal under either objective.

This distinction matters when weights are negative or represent a benefit rather than a cost. Weight mode can choose the empty matching with total zero. Cardinality mode can accept a negative edge to match more vertices. If your inputs are costs to minimize under a required coverage constraint, this maximum-benefit form is not automatically that problem.

Construct a case where the selectors disagree

Use four vertices and edges 0,1,10;0,2,4;1,3,4. Weight mode chooses edge 0–1 alone for total 10. The two-edge matching {0–2,1–3} has total 8, so it loses on weight even though it matches all four vertices. Cardinality mode chooses those two edges because two edges outrank one before weights are compared.

The default triangle is another useful check: any two edges share an endpoint, so at most one can be chosen. Selecting its largest-weight edge is optimal there, but a greedy largest-edge rule fails on the four-vertex example under cardinality mode. Inspect the endpoint pairs in the returned certificate rather than assuming that a larger total always means more matched vertices.

Understand how subset search certifies a small optimum

For a set of available vertices, choose one vertex. It is either left unmatched or paired along an existing edge with another available vertex. Removing the chosen vertices reduces the problem to a smaller subset. The dynamic program compares all these possibilities, so odd cycles do not require the graph to be forced into two parts.

The exponential state count is why the form limits the graph to 18 vertices. A completed search establishes the optimum for the entered graph and stated objective. It is not an implementation of the large-graph blossom algorithm, and the small-graph limit should not be interpreted as a mathematical limit on matching itself. For larger networks, use a specialized graph solver.

Validate the graph model and tie interpretation

Vertices are labeled 0 through n−1. Each undirected edge should occur once; reversing its endpoints does not create a different relationship. Loops and parallel edges are outside the simple-graph input. A missing edge forbids a pair rather than assigning it zero benefit, while an explicitly entered zero-weight edge remains available for cardinality decisions.

Several matchings can have the same optimum. The table gives one witness, not a claim that its particular pairs are uniquely preferable. Check whether weights are measured on a common additive scale and whether a vertex really can participate in only one relationship. Capacities, required matches, directed pairing and fairness constraints would change the optimization model.

A few questions, answered

Can maximum-weight matching be empty?

Yes. With only negative edge benefits, weight-only mode prefers zero selected edges.

How does cardinality mode differ?

It prioritizes the greatest edge count, then maximizes weight among equally large matchings.

What is the difference between maximal and maximum?

Maximal means no additional edge can be added without conflict. Maximum means the chosen objective is globally optimized; a maximal matching can be worse.

Can maximum weight leave vertices unmatched?

Yes. Covering every vertex is not required. Negative or conflicting benefits can make a smaller matching optimal.

Find your calculator

Start typing to explore the library.