・One-to-One Matching
・Many-to-One Matching
・Modeling Simulation
Import a class, Matching() from matching.py.
In [1]:
# coding: UTF-8
%matplotlib inline
from matching import *
from matching_simu import *
In [2]:
prop_prefs = [[1, 0, 2],
[0, 1, 2],
[0, 1, 2]]
resp_prefs = [[0, 2, 1],
[1, 0, 2],
[1, 0, 2]]
In [3]:
M1 = Matching(prop_prefs, resp_prefs)
In [4]:
prop_matched, resp_matched = M1.DA()
In [5]:
prop_matched
Out[5]:
In [6]:
resp_matched
Out[6]:
In [7]:
M1.summary()
In [8]:
M1.graph()
In [9]:
prop_matched, resp_matched = M1.TTC()
In [10]:
prop_matched
Out[10]:
In [11]:
resp_matched
Out[11]:
In [12]:
M1.summary()
In [13]:
M1.graph()
In [14]:
prop_matched, resp_matched = M1.BS()
In [15]:
prop_matched
Out[15]:
In [16]:
resp_matched
Out[16]:
In [17]:
M1.summary()
In [18]:
M1.graph()
In [19]:
prop_prefs = [[1, 2, 0],
[2, 0, 1],
[2, 1, 0],
[2, 0, 1]]
resp_prefs = [[3, 2, 1, 0],
[2, 1, 3, 0],
[0, 1, 3, 2]]
caps = [1, 2, 2]
In [20]:
M2 = Matching(prop_prefs, resp_prefs, caps)
In [21]:
prop_matched, resp_matched, indptr = M2.DA()
In [22]:
prop_matched
Out[22]:
In [23]:
resp_matched
Out[23]:
In [24]:
indptr
Out[24]:
In [25]:
M2.summary()
In [26]:
M2.graph()
In [27]:
prop_matched, resp_matched, indptr = M2.TTC()
In [28]:
prop_matched
Out[28]:
In [29]:
resp_matched
Out[29]:
In [30]:
indptr
Out[30]:
In [31]:
M2.summary()
In [32]:
M2.graph()
In [33]:
prop_matched, resp_matched, indptr = M2.BS()
In [34]:
prop_matched
Out[34]:
In [35]:
resp_matched
Out[35]:
In [36]:
indptr
Out[36]:
In [37]:
M2.graph()
Utility Function for the i-th student is given as follows.
$U_{i} = \alpha CV_{j} + (1-\alpha) PV_{ij}$
$CV_{j}$ means a common value to the j-th laboratory.
$PV_{ij}$ means the i-th student's private value to the j-th laboratory.
These are uniformly distributed over [0, 1).
$\alpha$ is a parameter, default set is 0.8.
Suppose that the preferences of the students are decided by this utility function,
and the number of students is 100, that of laboratories is 20.
Simulate 3000 times at each capacity
and return an average rank.
In [38]:
caps_list = [5, 7, 9, 11, 13, 15]
aves_DA = simulate(caps_list, 'DA')
aves_TTC = simulate(caps_list, 'TTC')
aves_BS = simulate(caps_list, 'BS')
In [39]:
aves_DA
Out[39]:
In [40]:
aves_TTC
Out[40]:
In [41]:
aves_BS
Out[41]:
In [42]:
plt.plot(caps_list, aves_DA, label="DA")
plt.plot(caps_list, aves_TTC, label="TTC")
plt.plot(caps_list, aves_BS, label="BS")
plt.title('Compare the mechanisms')
plt.xlim(5, 15)
plt.ylim(1, 5)
plt.xlabel('Capacity')
plt.ylabel('Average Rank')
plt.legend(loc=1)
plt.show()