equal
deleted
inserted
replaced
20 __authors__ = [ |
20 __authors__ = [ |
21 '"Sverre Rabbelier" <sverre@rabbelier.nl>', |
21 '"Sverre Rabbelier" <sverre@rabbelier.nl>', |
22 ] |
22 ] |
23 |
23 |
24 |
24 |
25 import itertools |
|
26 import math |
25 import math |
27 |
26 |
28 |
27 |
29 class Error(Exception): |
28 class Error(Exception): |
30 """Error class for the Allocation module. |
29 """Error class for the Allocation module. |
62 |
61 |
63 self.locked_slots = {} |
62 self.locked_slots = {} |
64 self.adjusted_slots = {} |
63 self.adjusted_slots = {} |
65 self.adjusted_orgs = [] |
64 self.adjusted_orgs = [] |
66 self.locked_orgs = [] |
65 self.locked_orgs = [] |
|
66 self.unlocked_orgs = [] |
67 self.unlocked_applications = [] |
67 self.unlocked_applications = [] |
68 self.slots = slots |
68 self.slots = slots |
69 self.max_slots_per_org = max_slots_per_org |
69 self.max_slots_per_org = max_slots_per_org |
70 self.min_slots_per_org = min_slots_per_org |
70 self.min_slots_per_org = min_slots_per_org |
71 self.orgs = set(orgs) |
71 self.orgs = set(orgs) |
|
72 self.popularity = None |
|
73 self.total_popularity = None |
72 self.initial_popularity = popularity |
74 self.initial_popularity = popularity |
73 self.mentors = mentors |
75 self.mentors = mentors |
74 self.iterative = iterative |
76 self.iterative = iterative |
75 |
77 |
76 def allocate(self, locked_slots, adjusted_slots): |
78 def allocate(self, locked_slots, adjusted_slots): |
93 return self.iterativeAllocation() |
95 return self.iterativeAllocation() |
94 else: |
96 else: |
95 return self.preprocessingAllocation() |
97 return self.preprocessingAllocation() |
96 |
98 |
97 def buildSets(self): |
99 def buildSets(self): |
98 """Allocates slots with the specified constraints |
100 """Allocates slots with the specified constraints. |
99 """ |
101 """ |
100 |
102 |
101 popularity = self.initial_popularity.copy() |
103 popularity = self.initial_popularity.copy() |
102 |
104 |
103 # set s |
105 # set s |
221 total_popularity += adjustment |
223 total_popularity += adjustment |
222 |
224 |
223 # adjust the popularity so that the invariants are always met |
225 # adjust the popularity so that the invariants are always met |
224 for org in unlocked_orgs: |
226 for org in unlocked_orgs: |
225 popularity = self.popularity[org] |
227 popularity = self.popularity[org] |
226 mentors = self.mentors[org] |
228 # mentors = self.mentors[org] |
227 |
229 |
228 slots = (float(popularity)/float(total_popularity))*available_slots |
230 slots = (float(popularity)/float(total_popularity))*available_slots |
229 slots = self.rangeSlots(slots, org) |
231 slots = self.rangeSlots(slots, org) |
230 |
232 |
231 popularity = (float(total_popularity)/float(available_slots))*slots |
233 popularity = (float(total_popularity)/float(available_slots))*slots |
244 allocations[org] = slots |
246 allocations[org] = slots |
245 |
247 |
246 slots_left = available_slots - sum(allocations.values()) |
248 slots_left = available_slots - sum(allocations.values()) |
247 |
249 |
248 # add leftover slots, sorted by slack, decending |
250 # add leftover slots, sorted by slack, decending |
249 for org, slack in sorted(slack.iteritems(), key=lambda (k,v): v, reverse=True): |
251 for org, slack in sorted(slack.iteritems(), |
|
252 key=lambda (k, v): v, reverse=True): |
250 if slots_left < 1: |
253 if slots_left < 1: |
251 break |
254 break |
252 |
255 |
253 current = allocations[org] |
256 current = allocations[org] |
254 slots = self.rangeSlots(current + 1, org) |
257 slots = self.rangeSlots(current + 1, org) |