DA algorithm(1 to 1)

瀧川英輝


In [5]:
include("DA_1to1.jl")


Out[5]:
Match (generic function with 1 method)

まずは、wikipediaの例を試してみます。


In [2]:
m_prefs = [1 3 1 3; 2 2 2 1; 3 1 4 4; 4 4 3 2; 0 0 0 0]


Out[2]:
5x4 Array{Int64,2}:
 1  3  1  3
 2  2  2  1
 3  1  4  4
 4  4  3  2
 0  0  0  0

In [3]:
n_prefs = [1 2 2 1; 2 1 3 4; 3 4 1 3; 4 3 4 2; 0 0 0 0]


Out[3]:
5x4 Array{Int64,2}:
 1  2  2  1
 2  1  3  4
 3  4  1  3
 4  3  4  2
 0  0  0  0

In [6]:
Match(m_prefs, n_prefs)


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

無事にwikipediaと同じ結果を得ることができました。 次にランダムな選好表で試してみます。


In [7]:
using Matching

In [8]:
m_prefs, f_prefs = random_prefs(4, 3);

In [9]:
m_prefs


Out[9]:
4x4 Array{Int64,2}:
 1  2  3  1
 3  3  0  3
 0  0  2  0
 2  1  1  2

In [10]:
f_prefs


Out[10]:
5x3 Array{Int64,2}:
 4  3  2
 2  2  1
 0  1  3
 3  4  4
 1  0  0

In [12]:
Match(m_prefs, f_prefs)


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

問題なさそうです。

最後にテストを実行します。


In [13]:
include("test_deferred_acceptance.jl")


Test Summary:      | Pass  Total
Testing DA_1to1.jl |    4      4
Out[13]:
BaseTestNext.DefaultTestSet("Testing DA_1to1.jl",Any[BaseTestNext.DefaultTestSet("Match",Any[Test Passed
  Expression: m_matched_computed == m_matched_expected
   Evaluated: [1,2,3,0] == [1,2,3,0],Test Passed
  Expression: f_matched_computed == f_matched_expected
   Evaluated: [1,2,3] == [1,2,3],Test Passed
  Expression: m_matched_computed == m_matched_expected
   Evaluated: [1,2,3,0] == [1,2,3,0],Test Passed
  Expression: f_matched_computed == f_matched_expected
   Evaluated: [1,2,3] == [1,2,3]],false)],false)

通りました。