feat: implement optimal assignment using Hungarian algorithm in matching process

- Added a new function for minimum-cost bipartite matching via the Hungarian algorithm to improve the efficiency of the matching process.
- Refactored existing matching logic to utilize the new algorithm, replacing the previous greedy assignment approach.
- Updated relevant documentation to reflect changes in the matching strategy.
- Enhanced performance in ambiguous group matching scenarios.
This commit is contained in:
Joe 2026-03-07 17:55:50 -06:00
parent 43ede3bc0e
commit d26f82b4f2
6 changed files with 414 additions and 151 deletions

View file

@ -235,7 +235,23 @@ pub fn syncback_dir_no_meta<'sync>(
})
.collect();
// Run the 3-pass matching algorithm to pair new ↔ old children.
// In debug builds, shuffle children to catch order-dependent matching bugs.
#[cfg(debug_assertions)]
let eligible_new = {
use rand::seq::SliceRandom;
let mut v = eligible_new;
v.shuffle(&mut rand::rng());
v
};
#[cfg(debug_assertions)]
let eligible_old = {
use rand::seq::SliceRandom;
let mut v = eligible_old;
v.shuffle(&mut rand::rng());
v
};
// Run the matching algorithm to pair new ↔ old children.
let matching_session = crate::syncback::matching::MatchingSession::new();
let match_result = match_children(
&eligible_new,