Public Interface
MatchingMarkets.deferred_acceptance
— Methoddeferred_acceptance(prop_prefs, resp_prefs, prop_caps, resp_caps)
Compute a stable matching by the DA algorithm for a many-to-many matching problem.
Arguments
prop_prefs::Matrix{Int}
: Array of shape (n+1, m) containing the proposers' preference orders as columns, where m is the number of proposers and n is that of the responders.prop_prefs[j, i]
is thej
-th preferred responder for thei
-th proposer, where "responder0
" represents "vacancy".resp_prefs::Matrix{Int}
: Array of shape (m+1, n) containing the responders' preference orders as columns.resp_prefs[i, j]
is thei
-th preferred proposer for thej
-th responder, where "proposer0
" epresents "vacancy".prop_caps::Vector{Int}
: Vector of length n containing the proposers' capacities.resp_caps::Vector{Int}
: Vector of length n containing the responders' capacities.
Returns
prop_matches::Vector{Int}
: Vector of length m representing the matches for the proposers, where the responders who proposeri
is matched with are contained inprop_matches[prop_indptr[i]:prop_indptr[i+1]-1]
.resp_matches::Vector{Int}
: Vector of length n representing the matches for the responders, where the proposers who responderj
is matched with are contained inresp_matches[resp_indptr[j]:resp_indptr[j+1]-1]
.prop_indptr::Vector{Int}
: Contains index pointers forprop_matches
.resp_indptr::Vector{Int}
: Contains index pointers forresp_matches
.
MatchingMarkets.deferred_acceptance
— Methoddeferred_acceptance(prop_prefs, resp_prefs)
Compute a stable matching by the DA algorithm for a one-to-one matching (marriage) problem.
Arguments
prop_prefs::Matrix{Int}
: Array of shape (n+1, m) containing the proposers' preference orders as columns, where m is the number of proposers and n is that of the responders.prop_prefs[j, i]
is thej
-th preferred responder for thei
-th proposer, where "responder0
" represents "being-single".resp_prefs::Matrix{Int}
: Array of shape (m+1, n) containing the responders' preference orders as columns.resp_prefs[i, j]
is thei
-th preferred proposer for thej
-th responder, where "proposer0
" represents "being-single".
Returns
prop_matches::Vector{Int}
: Vector of length m representing the matches for the proposers, whereprop_matches[i]
is the responder who proposeri
is matched with.resp_matches::Vector{Int}
: Vector of length n representing the matches for the responders, whereresp_matches[j]
is the proposer who responderj
is matched with.
MatchingMarkets.deferred_acceptance
— Methoddeferred_acceptance(s_prefs, c_prefs, caps[, proposal])
Compute a stable matching by the DA algorithm for a many-to-one matching (college admission) problem.
Arguments
s_prefs::Matrix{Int}
: Array of shape (n+1, m) containing the students' preference orders as columns, where m is the number of students and n is that of the colleges.s_prefs[j, i]
is thej
-th preferred college for thei
-th studnet, where "college0
" represents "being single".c_prefs::Matrix{Int}
: Array of shape (m+1, n) containing the colleges' preference orders as columns.c_prefs[i, j]
is thei
-th preferred student for thej
-th college, where "student0
" represents "vacancy".caps::Vector{Int}
: Vector of length n containing the colleges' capacities.proposal::Type(SProposing)
:SProposing
runs the student-proposing DA algorithm, whileCProposing
runs the college-proposing algorithm. Default to the former.
Returns
s_matches::Vector{Int}
: Vector of length m representing the matches for the students, wheres_matches[i]
is the college that proposeri
is matched with.c_matches::Vector{Int}
: Vector of length n representing the matches for the colleges, where the students who collegej
is matched with are contained inc_matches[indptr[j]:indptr[j+1]-1]
.indptr::Vector{Int}
: Contains index pointers forc_matches
.
MatchingMarkets.random_prefs
— Methodrandom_prefs([rng, ]m, n[, ReturnCaps]; allow_unmatched=true)
Generate random preference order lists for two groups, say, m males and n females.
Each male has a preference order over femals [1, ..., n] and "unmatched" which is represented by 0, while each female has a preference order over males [1, ..., m] and "unmatched" which is again represented by 0.
The argument ReturnCaps
should be supplied in the context of college admissions, in which case "males" and "females" should be read as "students" and "colleges", respectively, where each college has its capacity.
The optional rng
argument specifies a random number generator.
Arguments
m::Integer
: Number of males.n::Integer
: Number of females.::Type{ReturnCaps}
: If supplied,caps
is also returned.;allow_unmatched::Bool(true)
: If false, return preference order lists of males and females where 0 is always placed in the last place, (i.e., "unmatched" is least preferred by every individual).
Returns
m_prefs::Matrix{Int}
: Array of shape (n+1, m), where each column contains a random permutation of 0, 1, ..., n.f_prefs::Matrix{Int}
: Array of shape (m+1, n), where each column contains a random permutation of 0, 1, ..., m.caps::Vector{Int}
: Vector of length n containing each female's (or college's) capacity. Returned only whenReturnCaps
is supplied.
Examples
julia> m_prefs, f_prefs = random_prefs(4, 3);
julia> m_prefs
4x4 Array{Int64,2}:
3 3 1 3
0 2 3 1
2 1 2 0
1 0 0 2
julia> f_prefs
5x3 Array{Int64,2}:
1 2 4
4 3 1
3 4 2
0 0 0
2 1 3
julia> m_prefs, f_prefs = random_prefs(4, 3, allow_unmatched=false);
julia> m_prefs
4x4 Array{Int64,2}:
1 3 1 2
2 1 3 3
3 2 2 1
0 0 0 0
julia> f_prefs
5x3 Array{Int64,2}:
1 2 3
2 3 4
4 1 1
3 4 2
0 0 0
julia> s_prefs, c_prefs, caps = random_prefs(4, 3, ReturnCaps);
julia> s_prefs
4x4 Array{Int64,2}:
2 1 2 1
1 3 1 0
3 2 3 3
0 0 0 2
julia> c_prefs
5x3 Array{Int64,2}:
3 4 1
0 1 4
4 3 0
1 2 3
2 0 2
julia> caps
3-element Array{Int64,1}:
1
2
2