In [1]:
from __future__ import print_function
import numpy as np
In [2]:
from bocchan.matching import deferred_acceptance as bocchan
from keiikegami.deferred_acceptance import deferred_acceptance as keiikegami
from mhanami.gs_one import deferred_acceptance as mhanami
from NlGG.matching import deferred_acceptance as NlGG
from ogaway.matching import deferred_acceptance as ogaway
from oyamad.matching import deferred_acceptance as oyamad
In [3]:
from oyamad.matching_tools import random_prefs
In [4]:
funcs = {"bocchan": bocchan,
"keiikegami": keiikegami,
"mhanami": mhanami,
"NlGG": NlGG,
"ogaway": ogaway,
"oyamad": oyamad}
In [5]:
# Test case
m_unmatched = 3
m_prefs = [[0, 1, 2, m_unmatched],
[2, 0, 1, m_unmatched],
[1, 2, 0, m_unmatched],
[2, 0, 1, m_unmatched]]
f_unmatched = 4
f_prefs = [[2, 0, 1, 3, f_unmatched],
[0, 1, 2, 3, f_unmatched],
[2, f_unmatched, 1, 0, 3]]
# Unique stable matching
m_matched = [0, 1, 2, m_unmatched]
f_matched = [0, 1, 2]
for name, func in funcs.iteritems():
m_matched_computed, f_matched_computed = func(m_prefs, f_prefs)
msg = 'OK' if np.array_equal(m_matched_computed, m_matched) and \
np.array_equal(f_matched_computed, f_matched) \
else 'Failed'
print(name + ': ' + msg)
In [6]:
funcs = {"bocchan": bocchan,
"keiikegami": keiikegami,
#"mhanami": mhanami,
"NlGG": NlGG,
"ogaway": ogaway,
"oyamad": oyamad}
for name, func in funcs.iteritems():
m_matched_computed, f_matched_computed = func(m_prefs, f_prefs)
msg = 'OK' if np.array_equal(m_matched_computed, m_matched) and \
np.array_equal(f_matched_computed, f_matched) \
else 'Failed'
print(name + ': ' + msg)
In [7]:
m, n = 50, 50
prop_prefs, resp_prefs = random_prefs(m, n)
prop_prefs_list, resp_prefs_list = prop_prefs.tolist(), resp_prefs.tolist()
funcs = {"bocchan": bocchan,
"keiikegami": keiikegami,
#"mhanami": mhanami,
"NlGG": NlGG,
"ogaway": ogaway,
"oyamad": oyamad}
for name, func in funcs.iteritems():
print(name)
%timeit func(prop_prefs, resp_prefs)
In [8]:
m, n = 50, 50
prop_prefs, resp_prefs = random_prefs(m, n)
prop_prefs_list, resp_prefs_list = prop_prefs.tolist(), resp_prefs.tolist()
funcs = {"bocchan": bocchan,
"keiikegami": keiikegami,
#"mhanami": mhanami,
"NlGG": NlGG,
"ogaway": ogaway,
"oyamad": oyamad}
for name, func in funcs.iteritems():
print(name)
if name in ['bocchan']:
print('NA')
else:
%timeit func(prop_prefs, resp_prefs)
%timeit func(prop_prefs_list, resp_prefs_list)
In [9]:
m, n = 1000, 1000
prop_prefs, resp_prefs = random_prefs(m, n)
prop_prefs_list, resp_prefs_list = prop_prefs.tolist(), resp_prefs.tolist()
funcs = {"bocchan": bocchan,
"keiikegami": keiikegami,
#"mhanami": mhanami,
"NlGG": NlGG,
"ogaway": ogaway,
"oyamad": oyamad}
for name, func in funcs.iteritems():
print(name)
if name in ['bocchan']:
print('NA')
else:
%timeit func(prop_prefs, resp_prefs)
%timeit func(prop_prefs_list, resp_prefs_list)
In [10]:
# Test case
num_s, num_c = 11, 5
s_unmatched = num_c
s_prefs = [[2, 0, 4, 3, s_unmatched, 1],
[0, 2, 3, 1, 4, s_unmatched],
[3, 4, 2, 0, 1, s_unmatched],
[2, 3, 0, 4, s_unmatched, 1],
[0, 3, 1, s_unmatched, 2, 4],
[3, 2, 1, 0, 4, s_unmatched],
[1, 4, 0, 2, s_unmatched, 3],
[0, 2, 1, 4, 3, s_unmatched],
[3, 0, 4, s_unmatched, 1, 2],
[2, 0, 4, 1, 3, s_unmatched],
[4, 3, 0, 2, 1, s_unmatched]]
c_unmatched = num_s
c_prefs = [[2, 6, 8, 10, 4, 3, 9, 7, 5, 0, 1, c_unmatched],
[4, 6, 9, 5, 7, 1, 2, 10, c_unmatched, 0, 3, 8],
[10, 5, 7, 2, 1, 3, 6, 0, 9, c_unmatched, 4, 8],
[9, 0, 1, 10, 3, 8, 4, 2, 5, 7, c_unmatched, 6],
[1, 3, 9, 6, 5, 0, 7, 2, 10, 8, c_unmatched, 4]]
caps = [4, 1, 3, 2, 1]
indptr = [0, 4, 5, 8, 10, 11]
# Unique stable matching
s_matched = [2, 0, 3, 2, 0, 2, 1, 0, 3, 0, 4]
c_matched = [1, 4, 7, 9, 6, 0, 3, 5, 2, 8, 10]
In [11]:
funcs = {"bocchan": bocchan,
"keiikegami": keiikegami,
#"mhanami": mhanami,
"NlGG": NlGG,
"ogaway": ogaway,
"oyamad": oyamad}
for name, func in funcs.iteritems():
m_matched_computed, f_matched_computed = func(m_prefs, f_prefs)
msg = 'OK' if np.array_equal(m_matched_computed, m_matched) and \
np.array_equal(f_matched_computed, f_matched) \
else 'Failed'
print(name + ': ' + msg)
In [12]:
m, n = 50, 50
prop_prefs, resp_prefs, caps = random_prefs(m, n, return_caps=True)
prop_prefs_list, resp_prefs_list, caps_list \
= prop_prefs.tolist(), resp_prefs.tolist(), caps.tolist()
funcs = {"bocchan": bocchan,
"keiikegami": keiikegami,
#"mhanami": mhanami,
"NlGG": NlGG,
"ogaway": ogaway,
"oyamad": oyamad}
for name, func in funcs.iteritems():
print(name)
if name in ['bocchan']:
print('NA')
else:
%timeit func(prop_prefs, resp_prefs, caps)
%timeit func(prop_prefs_list, resp_prefs_list, caps_list)
In [13]:
m, n = 50, 50
prop_prefs, resp_prefs, caps = random_prefs(m, n, return_caps=True)
prop_prefs_list, resp_prefs_list, caps_list \
= prop_prefs.tolist(), resp_prefs.tolist(), caps.tolist()
funcs = {"bocchan": bocchan,
"keiikegami": keiikegami,
#"mhanami": mhanami,
#"NlGG": NlGG,
"ogaway": ogaway,
"oyamad": oyamad}
for name, func in funcs.iteritems():
print(name)
if name in ['bocchan', 'NlGG']:
print('NA')
else:
%timeit func(prop_prefs, resp_prefs, caps)
%timeit func(prop_prefs_list, resp_prefs_list, caps_list)
In [14]:
m, n = 50, 50
prop_prefs, resp_prefs, caps = random_prefs(m, n, return_caps=True)
prop_prefs_list, resp_prefs_list, caps_list \
= prop_prefs.tolist(), resp_prefs.tolist(), caps.tolist()
funcs = {"bocchan": bocchan,
#"keiikegami": keiikegami,
#"mhanami": mhanami,
#"NlGG": NlGG,
"ogaway": ogaway,
"oyamad": oyamad}
for name, func in funcs.iteritems():
print(name)
if name in ['bocchan', 'NlGG']:
print('NA')
else:
%timeit func(prop_prefs, resp_prefs, caps)
%timeit func(prop_prefs_list, resp_prefs_list, caps_list)
In [15]:
m, n = 1000, 1000
prop_prefs, resp_prefs, caps = random_prefs(m, n, return_caps=True)
prop_prefs_list, resp_prefs_list, caps_list \
= prop_prefs.tolist(), resp_prefs.tolist(), caps.tolist()
funcs = {"bocchan": bocchan,
#"keiikegami": keiikegami,
#"mhanami": mhanami,
#"NlGG": NlGG,
"ogaway": ogaway,
"oyamad": oyamad}
for name, func in funcs.iteritems():
print(name)
if name in ['bocchan', 'NlGG']:
print('NA')
else:
%timeit func(prop_prefs, resp_prefs, caps)
%timeit func(prop_prefs_list, resp_prefs_list, caps_list)
In [16]:
import platform
print(platform.platform())
In [17]:
import sys
print(sys.version)
In [18]:
import numpy
print(numpy.__version__)
In [19]:
import numba
print(numba.__version__)
In [ ]: