Commit 10eef807 authored by Ioannis Papagiannopoulos's avatar Ioannis Papagiannopoulos Committed by Georgios Dagkakis

failure to signal Router if it is not initiated fixed

parent 59855e0f
...@@ -53,7 +53,7 @@ class RoutingQueue(Queue): ...@@ -53,7 +53,7 @@ class RoutingQueue(Queue):
activeObjectQueue=self.Res.users activeObjectQueue=self.Res.users
#if we have only one possible receiver just check if the Queue holds one or more entities #if we have only one possible receiver just check if the Queue holds one or more entities
if(callerObject==None): if(callerObject==None):
return len(activeObjectQueue)>0 return len(activeObjectQueue)>0
thecaller=callerObject thecaller=callerObject
# local flag to control whether the callerObject can receive any of the entities in the buffers internal queue # local flag to control whether the callerObject can receive any of the entities in the buffers internal queue
isInRouting=False isInRouting=False
...@@ -89,12 +89,15 @@ class RoutingQueue(Queue): ...@@ -89,12 +89,15 @@ class RoutingQueue(Queue):
def removeEntity(self, entity=None): def removeEntity(self, entity=None):
activeEntity=Queue.removeEntity(self, entity) #run the default method activeEntity=Queue.removeEntity(self, entity) #run the default method
# check if the queue is empty, if yes then try to signal the router, operators may need reallocation # check if the queue is empty, if yes then try to signal the router, operators may need reallocation
if self.level: try:
if not len(self.getActiveObjectQueue()): if self.level:
from Globals import G if not len(self.getActiveObjectQueue()):
if not G.Router.invoked: from Globals import G
G.Router.invoked=True if not G.Router.invoked:
G.Router.isCalled.succeed(G.env.now) G.Router.invoked=True
G.Router.isCalled.succeed(G.env.now)
except:
pass
return activeEntity return activeEntity
# ======================================================================= # =======================================================================
...@@ -104,22 +107,26 @@ class RoutingQueue(Queue): ...@@ -104,22 +107,26 @@ class RoutingQueue(Queue):
def getEntity(self): def getEntity(self):
activeEntity=Queue.getEntity(self) #run the default behavior activeEntity=Queue.getEntity(self) #run the default behavior
# update the receiver object of the entity just received according to the routing of the parent batch # update the receiver object of the entity just received according to the routing of the parent batch
route = activeEntity.parentBatch.routing()
activeEntity.receiver=None activeEntity.receiver=None
try: try:
for nextObj in self.next: for nextObj in self.next:
if nextObj in entity.parentBatch.routing(): if nextObj in activeEntity.parentBatch.routing():
entity.receiver=nextObj activeEntity.receiver=nextObj
break break
# if none of the siblings (same parentBatch) has gone through the buffer then the receiver should remain None # if none of the siblings (same parentBatch) has gone through the buffer then the receiver should remain None
except: except:
pass pass
# if the level is reached then try to signal the Router to reallocate the operators # if the level is reached then try to signal the Router to reallocate the operators
if self.level: try:
if len(self.getActiveObjectQueue())==self.level: if self.level:
from Globals import G if len(self.getActiveObjectQueue())==self.level:
if not G.Router.invoked: from Globals import G
G.Router.invoked=True if not G.Router.invoked:
G.Router.isCalled.succeed(G.env.now) G.Router.invoked=True
G.Router.isCalled.succeed(G.env.now)
except:
pass
return activeEntity return activeEntity
# ======================================================================= # =======================================================================
...@@ -137,4 +144,7 @@ class RoutingQueue(Queue): ...@@ -137,4 +144,7 @@ class RoutingQueue(Queue):
self.activeQSorter() self.activeQSorter()
# sort again according to the existence or not of receiver attribute of the entities # sort again according to the existence or not of receiver attribute of the entities
activeObjectQueue=self.getActiveObjectQueue() activeObjectQueue=self.getActiveObjectQueue()
activeObjectQueue.sort(key=lambda x: x.receiver, reverse=True) # if no entity.receiver, then show preference to these entities
activeObjectQueue.sort(key=lambda x: x.receiver==None, reverse=True)
# if there is entity.receiver then check if it is the same as the self.receiver of the queue (if any)
activeObjectQueue.sort(key=lambda x: x.receiver==self.receiver, reverse=True)
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