In [1]:
using DA
In [93]:
function permutation2(array)
len = length(array)
perms = Array{Tuple{Int, Int}}(len * (len - 1))
c = 1
for i in 1:len
for j in 1:len
if i != j
perms[c] = (i, j)
c += 1
end
end
end
return perms
end
Out[93]:
In [102]:
num_props, num_resps = 10, 10
#caps = 5 * ones(Int, num_resps)
max_prop_pref, max_resp_pref = 2, num_props
original_prop_prefs, original_resp_prefs = generate_random_prefs(num_props, num_resps, max_prop_pref=max_prop_pref, max_resp_pref=max_resp_pref)
Out[102]:
In [103]:
#prop_prefs, resp_prefs = copy(original_prop_prefs), copy(original_resp_prefs)
seed = 0
srand(seed)
prop_prefs, resp_prefs = generate_random_prefs(num_props, num_resps, max_prop_pref=max_prop_pref, max_resp_pref=max_resp_pref)
println(original_prop_prefs)
println(prop_prefs)
prop_matched0, resp_matched0 = deferred_acceptance(prop_prefs, resp_prefs)
prop_ranks0 = [findfirst(original_prop_prefs[i], prop_matched0[i]) for i in 1:num_props]
prop_ranks = copy(prop_ranks0)
prefs_changing = true
println(prop_ranks0)
while prefs_changing
prefs_changing = false
for i in 1:num_props#shuffle(1:num_props)
for (r1, r2) in permutation2(1:num_resps)
new_prop_prefs = copy(prop_prefs)
new_prop_prefs[i] = [r1, r2]
prop_matched, resp_matched = deferred_acceptance(new_prop_prefs, resp_prefs)
prop_i_rank = findfirst(original_prop_prefs[i], prop_matched[i])
if prop_i_rank != 0 && (prop_ranks[i] == 0 || prop_i_rank < prop_ranks[i])
#println(i, "success")
prop_ranks[i] = prop_i_rank
prop_prefs[i] = new_prop_prefs[i]
prefs_changing = true
end
end
end
println(prop_ranks)
end
println(prop_prefs)
In [ ]: