Commit 73263eb9 authored by Georgios Dagkakis's avatar Georgios Dagkakis

more generic implementation of SelectiveQueue

parent 9a746399
...@@ -4,9 +4,10 @@ from dream.simulation.imports import Queue ...@@ -4,9 +4,10 @@ from dream.simulation.imports import Queue
class SelectiveQueue(Queue): class SelectiveQueue(Queue):
#override so that it chooses receiver according to priority #override so that it chooses receiver according to priority
def selectReceiver(self,possibleReceivers=[]): def selectReceiver(self,possibleReceivers=[]):
#if the priorities are the same work as cycle #if all the possibleReceivers have the same priority work as cycle
if possibleReceivers[0].priority==possibleReceivers[1].priority: if len(possibleReceivers):
return Queue.selectReceiver(possibleReceivers) if possibleReceivers.count(possibleReceivers[0]) == len(possibleReceivers):
return Queue.selectReceiver(possibleReceivers)
# sort the receivers according to their priority # sort the receivers according to their priority
possibleReceivers.sort(key=lambda x: x.priority, reverse=True) possibleReceivers.sort(key=lambda x: x.priority, reverse=True)
if possibleReceivers[0].canAccept(): if possibleReceivers[0].canAccept():
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment