Skip to content

Commit d125720

Browse files
williamfisetclaude
andcommitted
Update MWPM file description to clarify problem definition
Co-Authored-By: Claude Opus 4.6 <[email protected]>
1 parent bd904b5 commit d125720

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

src/main/java/com/williamfiset/algorithms/dp/MinimumWeightPerfectMatching.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,19 @@
99
/**
1010
* Minimum Weight Perfect Matching (MWPM)
1111
*
12-
* Given n nodes and a symmetric distance matrix, pairs up all nodes to minimize
13-
* total matching cost. Uses bitmask DP where each state represents a subset of
14-
* matched nodes. Two solvers are provided:
12+
* Given n nodes and a symmetric n x n cost matrix, the goal is to find a
13+
* perfect matching — a set of n/2 pairs that covers every node exactly once —
14+
* such that the sum of the edge costs of the chosen pairs is minimized.
1515
*
16-
* - Top-down (recursive with memoization): naturally skips unreachable states
17-
* - Bottom-up (iterative): builds solutions from pairs upward
16+
* For example, given 4 nodes with cost matrix:
17+
* cost = {{0,2,1,2}, {2,0,2,1}, {1,2,0,2}, {2,1,2,0}}
18+
* the optimal matching is (0,2) and (1,3) with total cost 1 + 1 = 2.
19+
*
20+
* Uses bitmask DP where each bit in the state represents whether a node has
21+
* been matched. Two solvers are provided:
22+
*
23+
* - solveRecursive(): top-down with memoization, skips unreachable states
24+
* - solveIterative(): bottom-up, builds matchings from pairs upward
1825
*
1926
* Requires n to be even (otherwise no perfect matching exists) and n <= 32
2027
* (bitmask representation limit).

0 commit comments

Comments
 (0)