Last active
December 23, 2015 18:59
-
-
Save khaeru/6680015 to your computer and use it in GitHub Desktop.
Team-case matching for ESD.801 Fall 2013
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from numpy import * | |
T = 8 # number of teams | |
C = 3 # cases per team | |
# preferences of the teams | |
# p = array([random.permutation(range(T)) for i in range(T)]) # for testing | |
p = array([ | |
[4, 5, 6, 1, 2, 7, 8, 3], # abdulla | |
[8, 4, 2, 1, 6, 7, 5, 3], # accuardi | |
[6, 4, 5, 1, 2, 7, 8, 3], # guinto | |
[1, 6, 8, 7, 3, 5, 2, 4], # jessedj | |
[8, 1, 6, 7, 4, 5, 2, 3], # jmcna | |
[2, 6, 3, 8, 5, 4, 1, 7], # jmoline | |
[8, 2, 1, 6, 5, 7, 3, 4], # nbmac | |
[6, 2, 3, 8, 1, 7, 4, 5], # maouyo | |
]) | |
p -= 1 # to 0-index | |
p_ = array(p) # for output | |
c = [set() for i in range(T)] # assigned cases | |
N1 = lambda: array([len(c[i]) for i in range(T)]) # number assigned | |
N2 = lambda i: sum([1 if i in j else 0 for j in c]) # case i count | |
while any(N1() < C): # loop until each team has C cases | |
low = where(N1() == min(N1()))[0] # lowest 'resource dominance' first… | |
if len(low) == 1: | |
i = low[0] | |
else: | |
i = random.permutation(low)[0] # …otherwise select randomly | |
while N2(p[i,0]) >= C: # roll team i's preferences… | |
p[i,:] = roll(p[i,:], -1) # …until top choice available | |
c[i].add(p[i,0]) # assign | |
p[i,:] = roll(p[i,:], -1) # roll again | |
# output | |
p = p_ | |
for i, name in enumerate(['abdulla', 'accuardi', 'guinto', 'jessedj', | |
'jmcna', 'jmoline', 'nbmac', 'maouyo']): | |
print('DG {:8}: '.format(name), end='') | |
for j in range(T): | |
print(('({})' if p[i,j] in c[i] else ' {} ').format(p[i,j] + 1), end='') | |
print('') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment