mirror of
https://github.com/tgorordo/carousel.git
synced 2026-06-14 21:32:14 -07:00
format
This commit is contained in:
parent
8743b04809
commit
8d94b96b85
2 changed files with 72 additions and 17 deletions
|
|
@ -5,6 +5,7 @@ import polars.selectors as pls
|
|||
|
||||
import itertools as it
|
||||
|
||||
|
||||
def rank_to_pref(R):
|
||||
"""Converts a ranking to a preference."""
|
||||
id_col_name = R.select(pls.by_index(0)).to_series().name
|
||||
|
|
@ -66,53 +67,74 @@ def check_valid_rank(R):
|
|||
).get_column("ties")[0]
|
||||
return not ties
|
||||
|
||||
|
||||
def check_valid_match(match, applicants, reviewers):
|
||||
# TODO
|
||||
pass
|
||||
|
||||
|
||||
def check_valid_assgn(assgn, applicants, reviewers):
|
||||
# TODO
|
||||
pass
|
||||
|
||||
|
||||
def get_rank(ranking, ranker, rankee):
|
||||
idx = ranking.select(pl.arg_where(pl.col("") == rankee)).item()
|
||||
return ranking[ranker][idx]
|
||||
|
||||
def check_unstable(match, applicant_ranking, reviewer_ranking):
|
||||
applicants = applicant_ranking.columns[1:] # assume unique applicants
|
||||
for a, b in it.combinations(applicants, 2):
|
||||
A = match.select(c for c in match.iter_columns() if a in c).to_series().name # the reviewer a is matched to
|
||||
B = match.select(c for c in match.iter_columns() if b in c).to_series().name # the reviewer b is matched to
|
||||
|
||||
b_prefers_A = get_rank(applicant_ranking, b, A) < get_rank(applicant_ranking, b, B)
|
||||
A_prefers_b = get_rank(reviewer_ranking, A, b) < get_rank(reviewer_ranking, A, a)
|
||||
def check_unstable(match, applicant_ranking, reviewer_ranking):
|
||||
applicants = applicant_ranking.columns[1:] # assume unique applicants
|
||||
for a, b in it.combinations(applicants, 2):
|
||||
A = (
|
||||
match.select(c for c in match.iter_columns() if a in c).to_series().name
|
||||
) # the reviewer a is matched to
|
||||
B = (
|
||||
match.select(c for c in match.iter_columns() if b in c).to_series().name
|
||||
) # the reviewer b is matched to
|
||||
|
||||
b_prefers_A = get_rank(applicant_ranking, b, A) < get_rank(
|
||||
applicant_ranking, b, B
|
||||
)
|
||||
A_prefers_b = get_rank(reviewer_ranking, A, b) < get_rank(
|
||||
reviewer_ranking, A, a
|
||||
)
|
||||
if b_prefers_A and A_prefers_b:
|
||||
return True
|
||||
|
||||
# or
|
||||
a_prefers_B = get_rank(applicant_ranking, a, B) < get_rank(applicant_ranking, a, A)
|
||||
B_prefers_a = get_rank(reviewer_ranking, B, a) < get_rank(reviewer_ranking, B, b)
|
||||
a_prefers_B = get_rank(applicant_ranking, a, B) < get_rank(
|
||||
applicant_ranking, a, A
|
||||
)
|
||||
B_prefers_a = get_rank(reviewer_ranking, B, a) < get_rank(
|
||||
reviewer_ranking, B, b
|
||||
)
|
||||
if a_prefers_B and B_prefers_a:
|
||||
return True
|
||||
# else
|
||||
return False
|
||||
|
||||
|
||||
def check_stable(*args, **kwargs):
|
||||
return not check_unstable(*args, **kwargs)
|
||||
|
||||
|
||||
def deferred_acceptance(A, R):
|
||||
"""Find the Gale-Shapley deferred-acceptance stable matching for preferences A, R."""
|
||||
# TODO - the core algorithm!
|
||||
pass
|
||||
|
||||
|
||||
def assgn_to_match(assgn):
|
||||
# TODO
|
||||
pass
|
||||
|
||||
|
||||
def match_to_assgn(match):
|
||||
# TODO
|
||||
pass
|
||||
|
||||
|
||||
def main() -> None:
|
||||
rich.print("Hello from [italic red]carousel[/italic red]!")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue