In [1]:
%matplotlib inline
import matchfuncs as mf
In [2]:
prop_num = 5
resp_num = 3
prop_prefs = [
[2, 0, 1],
[2, 1, 0],
[1, 2, 0],
[1, 2, 0],
[1, 2, 0]
]
resp_prefs = [
[4, 3, 1, 2, 0],
[1, 0, 4, 3, 2],
[1, 3, 0, 2, 4]
]
prop_caps = [1, 3, 2, 2, 1]
resp_caps = [2, 2, 4]
list_length = 3
In [3]:
prop_matched, resp_matched, prop_indptr, resp_indptr = mf.BOS(prop_prefs, resp_prefs, resp_caps, prop_caps, list_length)
print('prop_matched = ' + str(prop_matched))
print('resp_matched = ' + str(resp_matched))
print('prop_indptr = ' + str(prop_indptr))
print('resp_indptr = ' + str(resp_indptr))
mf.Graph(prop_matched, resp_matched, prop_indptr, resp_indptr)
In [4]:
prop_matched, resp_matched, prop_indptr, resp_indptr = mf.DA(prop_prefs, resp_prefs, resp_caps, prop_caps, list_length-1)
print('prop_matched = ' + str(prop_matched))
print('resp_matched = ' + str(resp_matched))
print('prop_indptr = ' + str(prop_indptr))
print('resp_indptr = ' + str(resp_indptr))
mf.Graph(prop_matched, resp_matched, prop_indptr, resp_indptr)
In [5]:
prop_matched, resp_matched, prop_indptr, resp_indptr = mf.AddBOS(prop_prefs, resp_prefs, prop_matched, resp_matched, resp_caps, prop_caps)
print('prop_matched = ' + str(prop_matched))
print('resp_matched = ' + str(resp_matched))
print('prop_indptr = ' + str(prop_indptr))
print('resp_indptr = ' + str(resp_indptr))
mf.Graph(prop_matched, resp_matched, prop_indptr, resp_indptr)
In [6]:
prop_matched, resp_matched, prop_indptr, resp_indptr = mf.DA(prop_prefs, resp_prefs, resp_caps, prop_caps, resp_num)
print('prop_matched = ' + str(prop_matched))
print('resp_matched = ' + str(resp_matched))
print('prop_indptr = ' + str(prop_indptr))
print('resp_indptr = ' + str(resp_indptr))
mf.Graph(prop_matched, resp_matched, prop_indptr, resp_indptr)
In [7]:
# BOS
mf.Comp('BOS', prop_prefs, resp_prefs, resp_caps, prop_caps, list_length)
Out[7]:
In [8]:
# DAAdd
mf.Comp('DAAdd', prop_prefs, resp_prefs, resp_caps, prop_caps, list_length)
Out[8]:
In [9]:
# DA
mf.Comp('DA', prop_prefs, resp_prefs, resp_caps, prop_caps, resp_num)
Out[9]:
In [10]:
# BOS
mf.NashComp('BOS', prop_prefs, resp_prefs, resp_caps, prop_caps, list_length)
Out[10]:
In [11]:
# DAAdd
mf.NashComp('DAAdd', prop_prefs, resp_prefs, resp_caps, prop_caps, list_length)
Out[11]:
In [12]:
# DA
mf.NashComp('DA', prop_prefs, resp_prefs, resp_caps, prop_caps, resp_num)
Out[12]:
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 seminar. (popularity etc.)
$PV_{ij}$ means the i-th student's private value to the j-th seminar.
These are uniformly distributed over [0, 1), and the lower j is, the higher CV is.
$\alpha$ is a parameter, default set is 0.3.
Utility Function for the j-th seminar is given as follows.
$U_{j} = \beta CV_{i} + (1-\beta) PV_{ji}$
$CV_{i}$ means a common value to the i-th student. (grade etc.)
$PV_{ji}$ means the j-th seminar's private value to the i-th student.
These are uniformly distributed over [0, 1), and the lower i is, the higher CV is.
$\beta$ is a parameter, default set is also 0.3.
Suppose that the preferences of the students and seminars are decided by these utility functions,
and the number of students is 345, that of seminars is 38.
Half of the seminars have capacity 6, while the other half have capacity 13.
All students have 2 capacity.
In [13]:
prop_num = 9
resp_num = 6
alpha = 0.3
beta = 0.3
prop_caps = [2 for i in range(prop_num)]
resp_caps = [2, 2, 2, 4, 4, 4]
list_length = 3
In [14]:
prop_prefs, resp_prefs = mf.MakeCVprefs(prop_num, resp_num, alpha, beta)
In [15]:
print('prop_prefs =')
print(prop_prefs)
print('\nresp_prefs = ')
print(resp_prefs)
print('\nprop_caps = ')
print(prop_caps)
print('\nresp_caps = ')
print(resp_caps)
In [16]:
result1 = mf.Comp('BOS', prop_prefs, resp_prefs, resp_caps, prop_caps, list_length)
result2 = mf.Comp('DAAdd', prop_prefs, resp_prefs, resp_caps, prop_caps, list_length)
result3 = mf.Comp('DA', prop_prefs, resp_prefs, resp_caps, prop_caps)
In [17]:
print('Justified Envy')
print('1: %s \n2: %s \n3: %s' % (result1[0], result2[0], result3[0]))
print('Truth-telling')
print('1: %s \n2: %s \n3: %s' % (result1[1], result2[1], result3[1]))
print('Efficiency of the students')
print('1: %s \n2: %s \n3: %s' % (result1[2], result2[2], result3[2]))
print('Efficiency of the seminars')
print('1: %s \n2: %s \n3: %s' % (result1[3], result2[3], result3[3]))
print('None Zemi')
print('1: %s \n2: %s \n3: %s' % (result1[4], result2[4], result3[4]))
print('Vacant Caps')
print('1: %s \n2: %s \n3: %s' % (result1[5], result2[5], result3[5]))
print('Interviews')
print('1: %s \n2: %s \n3: %s' % (result1[6], result2[6], result3[6]))
Therefore, the result is
| BOS | DAAdd | DA | |
|---|---|---|---|
| Stability | 5 | 2 | 0 |
| Truth-telling | 9 | 9 | 9 |
| Efficiency | 1.389, 3.833 | 1.722, 4.0 | 1.556, 3.625 |
| Fairness | 0, 0 | 0, 2 | 0, 0 |
| Feasibility | 20 | 24 | 54 |