小住真央のデモノートです。コードはこちら
In [1]:
using MyMatching
testを実行します。
In [2]:
Pkg.test("MyMatching")
ShingakuMatchingを用いて進学選択シミュレーションを行います。
In [3]:
using ShingakuMatching
departments = get_departments()
num_students = 300 #number of students
students = get_students(num_students)
prop_prefs, resp_prefs, caps = get_random_prefs(students, departments)
Out[3]:
In [4]:
prop_matched, resp_matched, indptr = my_deferred_acceptance(prop_prefs, resp_prefs, caps)
Out[4]:
以下では、どの生徒ともマッチングしなかった学科を探します。
In [9]:
r = 1
while r <= length(resp_prefs)
if (resp_matched[indptr[r]:indptr[r+1]-1] == [0])
println("resp $r ""got no student.")
end
r += 1
end
実際に上記の学科のresp_matchedが0になっているかどうかを確認してみます。
In [10]:
j = 4
resp_matched[indptr[j]:indptr[j+1]-1]
Out[10]:
In [11]:
j = 5
resp_matched[indptr[j]:indptr[j+1]-1]
Out[11]:
In [12]:
j = 22
resp_matched[indptr[j]:indptr[j+1]-1]
Out[12]:
In [13]:
j = 32
resp_matched[indptr[j]:indptr[j+1]-1]
Out[13]:
次に、各学科が受け入れた学生の数を調べます。
In [39]:
resp_num = Vector{Int}(length(resp_prefs))
for u in 1:length(resp_prefs)
u_matched = resp_matched[indptr[u]:indptr[u+1]-1]
stu_num = 1
while !(u_matched[stu_num] == 0)
stu_num += 1
if stu_num > length(u_matched)
break
end
end
resp_num[u] = stu_num -1
end
resp_num
Out[39]:
最も多くの学生を受け入れた学科を探します。
In [48]:
maximum(resp_num)
Out[48]:
In [49]:
for max_resp in 1:length(resp_prefs)
if !(resp_num[max_resp] == maximum(resp_num))
max_resp += 1
else
print(max_resp)
break
end
end
最も多くの学生を受け入れた学科122と学生とのマッチングに着目します。
学科122に内定した学生が、学科1を何番目に志望していたかを、以下の関数を使ってみてみます。
In [50]:
function student_pref_rank(resp_number)
x = 1
while x <= num_students
if x in resp_matched[indptr[resp_number]:indptr[resp_number+1]-1]
pref_rank = 1
x_pref = prop_prefs[x]
while !(x_pref[pref_rank] == resp_number)
pref_rank += 1
end
println("student $x; ""pref_rank = $pref_rank")
end
x += 1
end
end
Out[50]:
In [51]:
student_pref_rank(122)
今度は学科122に内定した学生が、学科122の受け入れ順位の何番目に位置していたかを、以下の関数を使ってみてみます。
In [56]:
function student_resp_rank(resp_number)
w = resp_matched[indptr[resp_number]:indptr[resp_number+1]-1]
for y in 1: caps[resp_number]
if !(w[y] == 0)
resp_rank = 1
pref = resp_prefs[resp_number]
while !(pref[resp_rank] == w[y])
resp_rank += 1
end
stu = w[y]
println("student $stu; ""resp_rank = $resp_rank")
else
break
end
end
end
Out[56]:
In [57]:
student_resp_rank(122)
ここから、学科122に内定した学生にとって、学科122は選好順位が比較的高く魅力的であった一方で、学科122に内定した学生は、学科122から見てさほど魅力的ではなかったと言えそうです。
以上で検証を終わります。