課題4

高橋 雅士             

コードはこちら(https://github.com/masashitshit/MyMatching.jl/blob/master/src/MyMatching.jl)


In [1]:
using MyMatching

前回と同じくwikipediaの例より


In [2]:
prop_prefs = [[1, 2, 3, 4], [3, 2, 1, 4], [1, 2, 4, 3], [3, 1,  4, 2]]
resp_prefs = [[1, 2, 3, 4], [2, 1, 4, 3], [2, 3, 1, 4], [1, 4, 3, 2]]


Out[2]:
4-element Array{Array{Int64,1},1}:
 [1, 2, 3, 4]
 [2, 1, 4, 3]
 [2, 3, 1, 4]
 [1, 4, 3, 2]

In [3]:
matching3(prop_prefs,resp_prefs)


Out[3]:
([1, 3, 2, 4], [1, 3, 2, 4])

医師臨床研修マッチング協議会の例より


In [4]:
prop_prefs = [[2], [2, 1], [2, 1], [1, 2, 3, 4], [2, 1, 4, 3], [2, 3, 1, 4], [2, 1, 4, 3], [4, 2, 1, 3]]
resp_prefs = [[3, 7], [7, 8, 5, 1, 2, 3, 4, 6], [2, 5, 8, 1, 3, 4, 7], [2, 5, 1, 3, 6, 4, 7]]
caps = [2, 2, 2, 2]


Out[4]:
4-element Array{Int64,1}:
 2
 2
 2
 2

In [5]:
matching3(prop_prefs,resp_prefs,caps)


Out[5]:
([0, 0, 1, 3, 4, 4, 2, 2], [3, 0, 7, 8, 4, 0, 5, 6], [1, 3, 5, 7, 9])

最後にテストしてみます


In [6]:
Pkg.test("MyMatching")


INFO: Testing MyMatching
Test Summary:               | Pass  Total
Testing deferred acceptance |   18     18
INFO: MyMatching tests passed

……!!!