equal
deleted
inserted
replaced
250 |
250 |
251 def reliableAlgorithm(self): |
251 def reliableAlgorithm(self): |
252 """An algorithm that reliable calculates the slots assignments. |
252 """An algorithm that reliable calculates the slots assignments. |
253 """ |
253 """ |
254 |
254 |
255 adjusted_orgs = self.adjusted_orgs |
255 # adjusted_orgs = self.adjusted_orgs |
256 adjusted_slots = self.adjusted_slots |
256 # adjusted_slots = self.adjusted_slots |
257 locked_orgs = self.locked_orgs |
257 locked_orgs = self.locked_orgs |
258 locked_slots = self.locked_slots |
258 locked_slots = self.locked_slots |
259 unlocked_orgs = self.unlocked_orgs |
259 unlocked_orgs = self.unlocked_orgs |
260 total_popularity = self.total_popularity |
260 total_popularity = self.total_popularity |
261 |
261 |
262 available_slots = self.slots |
262 available_slots = self.slots |
263 allocations = {} |
263 allocations = {} |
264 slack = {} |
264 # slack = {} |
265 |
265 |
266 # take out the easy ones |
266 # take out the easy ones |
267 for org in locked_orgs: |
267 for org in locked_orgs: |
268 popularity = self.popularity[org] |
268 popularity = self.popularity[org] |
269 slots = locked_slots[org] |
269 slots = locked_slots[org] |
281 if total_popularity <= 0: |
281 if total_popularity <= 0: |
282 return allocations |
282 return allocations |
283 |
283 |
284 pop_per_slot = float(available_slots)/float(total_popularity) |
284 pop_per_slot = float(available_slots)/float(total_popularity) |
285 |
285 |
286 slack = 0 |
286 # slack = 0 |
287 wanted = {} |
287 wanted = {} |
288 |
288 |
289 # filter out all those that deserve more than their maximum |
289 # filter out all those that deserve more than their maximum |
290 for org in unlocked_orgs: |
290 for org in unlocked_orgs: |
291 popularity = self.popularity[org] |
291 popularity = self.popularity[org] |
301 |
301 |
302 available_slots = self.slots - sum(allocations.values()) |
302 available_slots = self.slots - sum(allocations.values()) |
303 |
303 |
304 # distribute the slack |
304 # distribute the slack |
305 while available_slots > 0 and (sum(wanted.values()) > 0): |
305 while available_slots > 0 and (sum(wanted.values()) > 0): |
306 for org, amount in wanted.iteritems(): |
306 for org, _ in wanted.iteritems(): |
307 available_slots = self.slots - sum(allocations.values()) |
307 available_slots = self.slots - sum(allocations.values()) |
308 if available_slots <= 0: |
308 if available_slots <= 0: |
309 break |
309 break |
310 |
310 |
311 if wanted[org] <= 0: |
311 if wanted[org] <= 0: |