fix issue with maximum-bipartite-matching/stable

This commit is contained in:
xenia 2020-12-21 13:29:20 -05:00
parent 16a6abf9b5
commit 98db7e9dce
1 changed files with 3 additions and 1 deletions

View File

@ -44,7 +44,9 @@
(define num-first-lefts (define num-first-lefts
(for/sum ([m (in-list matching)] #:when (set-member? left (first m))) (for/sum ([m (in-list matching)] #:when (set-member? left (first m)))
1)) 1))
(if (> num-first-lefts (/ (set-count left) 2)) ;; if the first set contains more elements belonging to lefts than rights, then assume it's in
;; the right order. otherwise, swap
(if (> num-first-lefts (- (length matching) num-first-lefts))
matching matching
(map #{list (second %) (first %)} matching))) (map #{list (second %) (first %)} matching)))