45 # additional comments (with the exception of the set notation for |
45 # additional comments (with the exception of the set notation for |
46 # the convenience of any mathematicians that happen to read this |
46 # the convenience of any mathematicians that happen to read this |
47 # piece of code ;). |
47 # piece of code ;). |
48 |
48 |
49 def __init__(self, orgs, popularity, max, slots, |
49 def __init__(self, orgs, popularity, max, slots, |
50 max_slots_per_org, min_slots_per_org, iterative): |
50 max_slots_per_org, min_slots_per_org, algorithm): |
51 """Initializes the allocator. |
51 """Initializes the allocator. |
52 |
52 |
53 Args: |
53 Args: |
54 orgs: a list of all the orgs that need to be allocated |
54 orgs: a list of all the orgs that need to be allocated |
55 popularity: the amount of applications per org |
55 popularity: the amount of applications per org |
56 mentors: the amount of assigned mentors per org |
56 max: the amount of assigned mentors per org |
57 slots: the total amount of available slots |
57 slots: the total amount of available slots |
58 max_slots_per_org: how many slots an org should get at most |
58 max_slots_per_org: how many slots an org should get at most |
59 min_slots_per_org: how many slots an org should at least get |
59 min_slots_per_org: how many slots an org should at least get |
|
60 algorithm: the algorithm to use |
60 """ |
61 """ |
61 |
62 |
62 self.locked_slots = {} |
63 self.locked_slots = {} |
63 self.adjusted_slots = {} |
64 self.adjusted_slots = {} |
64 self.adjusted_orgs = [] |
65 self.adjusted_orgs = [] |
71 self.orgs = set(orgs) |
72 self.orgs = set(orgs) |
72 self.popularity = None |
73 self.popularity = None |
73 self.total_popularity = None |
74 self.total_popularity = None |
74 self.initial_popularity = popularity |
75 self.initial_popularity = popularity |
75 self.max = max |
76 self.max = max |
76 self.iterative = iterative |
77 self.algorithm = algorithm |
77 |
78 |
78 def allocate(self, locked_slots): |
79 def allocate(self, locked_slots): |
79 """Allocates the slots and returns the result. |
80 """Allocates the slots and returns the result. |
80 |
81 |
81 Args: |
82 Args: |
82 locked_slots: a dict with orgs and the number of slots they get |
83 locked_slots: a dict with orgs and the number of slots they get |
83 adjusted_slots: a dict with orgs and the number of extra slots they get |
|
84 """ |
84 """ |
85 |
85 |
86 self.locked_slots = locked_slots |
86 self.locked_slots = locked_slots |
87 |
87 |
88 self.buildSets() |
88 self.buildSets() |
89 |
89 |
90 if not sum(self.popularity.values()) or not sum(self.max.values()): |
90 if not sum(self.popularity.values()) or not sum(self.max.values()): |
91 return dict([(i, 0) for i in self.orgs]) |
91 return dict([(i, 0) for i in self.orgs]) |
92 |
92 |
93 if self.iterative: |
93 if self.algorithm == 1: |
94 return self.iterativeAllocation() |
|
95 else: |
|
96 return self.preprocessingAllocation() |
94 return self.preprocessingAllocation() |
|
95 |
|
96 return self.iterativeAllocation() |
97 |
97 |
98 def buildSets(self): |
98 def buildSets(self): |
99 """Allocates slots with the specified constraints. |
99 """Allocates slots with the specified constraints. |
100 """ |
100 """ |
101 |
101 |