Commit d6afca93 authored by Ioannis Papagiannopoulos's avatar Ioannis Papagiannopoulos Committed by Georgios Dagkakis

level attribute and control moved to Queue

parent 10eef807
...@@ -37,7 +37,7 @@ class Queue(CoreObject): ...@@ -37,7 +37,7 @@ class Queue(CoreObject):
#=========================================================================== #===========================================================================
# the __init__ method of the Queue # the __init__ method of the Queue
#=========================================================================== #===========================================================================
def __init__(self, id, name, capacity=1, isDummy=False, schedulingRule="FIFO", gatherWipStat=False): def __init__(self, id, name, capacity=1, isDummy=False, schedulingRule="FIFO", level=None, gatherWipStat=False):
CoreObject.__init__(self, id, name) CoreObject.__init__(self, id, name)
# Process.__init__(self) # Process.__init__(self)
# used for the routing of the entities # used for the routing of the entities
...@@ -69,6 +69,10 @@ class Queue(CoreObject): ...@@ -69,6 +69,10 @@ class Queue(CoreObject):
self.gatherWipStat=gatherWipStat self.gatherWipStat=gatherWipStat
# Will be populated by an event generator # Will be populated by an event generator
self.wip_stat_list = [] self.wip_stat_list = []
# trigger level for the reallocation of operators
if level:
assert level<=self.capacity, "the level cannot be bigger than the capacity of the queue"
self.level=level
@staticmethod @staticmethod
def getSupportedSchedulingRules(): def getSupportedSchedulingRules():
...@@ -166,6 +170,16 @@ class Queue(CoreObject): ...@@ -166,6 +170,16 @@ class Queue(CoreObject):
if self.haveToDispose(): if self.haveToDispose():
# self.printTrace(self.id, attemptSignalReceiver='(removeEntity)') # self.printTrace(self.id, attemptSignalReceiver='(removeEntity)')
self.signalReceiver() self.signalReceiver()
# check if the queue is empty, if yes then try to signal the router, operators may need reallocation
try:
if self.level:
if not len(self.getActiveObjectQueue()):
from Globals import G
if not G.Router.invoked:
G.Router.invoked=True
G.Router.isCalled.succeed(G.env.now)
except:
pass
return activeEntity return activeEntity
# ======================================================================= # =======================================================================
...@@ -185,6 +199,16 @@ class Queue(CoreObject): ...@@ -185,6 +199,16 @@ class Queue(CoreObject):
# ======================================================================= # =======================================================================
def getEntity(self): def getEntity(self):
activeEntity=CoreObject.getEntity(self) #run the default behavior activeEntity=CoreObject.getEntity(self) #run the default behavior
# if the level is reached then try to signal the Router to reallocate the operators
try:
if self.level:
if len(self.getActiveObjectQueue())==self.level:
from Globals import G
if not G.Router.invoked:
G.Router.invoked=True
G.Router.isCalled.succeed(G.env.now)
except:
pass
return activeEntity return activeEntity
#=========================================================================== #===========================================================================
......
...@@ -33,14 +33,14 @@ from Queue import Queue ...@@ -33,14 +33,14 @@ from Queue import Queue
# the Queue object # the Queue object
# =========================================================================== # ===========================================================================
class RoutingQueue(Queue): class RoutingQueue(Queue):
#=========================================================================== # #===========================================================================
# the __init__ method of the Queue # # the __init__ method of the Queue
#=========================================================================== # #===========================================================================
def __init__(self, id, name, capacity=1, isDummy=False, schedulingRule="FIFO", gatherWipStat=False,level=None): # def __init__(self, id, name, capacity=1, isDummy=False, schedulingRule="FIFO", gatherWipStat=False,level=None):
Queue.__init__(self, id, name,capacity,isDummy,schedulingRule,gatherWipStat) # Queue.__init__(self, id, name,capacity,isDummy,schedulingRule,gatherWipStat)
if level: # if level:
assert level<=self.capacity, "the level cannot be bigger than the capacity of the queue" # assert level<=self.capacity, "the level cannot be bigger than the capacity of the queue"
self.level=level # self.level=level
# ======================================================================= # =======================================================================
# checks if the Queue can dispose an entity to the following object # checks if the Queue can dispose an entity to the following object
...@@ -83,22 +83,22 @@ class RoutingQueue(Queue): ...@@ -83,22 +83,22 @@ class RoutingQueue(Queue):
entity.receiver=receiver entity.receiver=receiver
activeObjectQueue.sort(key=lambda x: x.receiver==receiver, reverse=True) activeObjectQueue.sort(key=lambda x: x.receiver==receiver, reverse=True)
# ======================================================================= # # =======================================================================
# removes an entity from the Object # # removes an entity from the Object
# ======================================================================= # # =======================================================================
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
try: # try:
if self.level: # if self.level:
if not len(self.getActiveObjectQueue()): # if not len(self.getActiveObjectQueue()):
from Globals import G # from Globals import G
if not G.Router.invoked: # if not G.Router.invoked:
G.Router.invoked=True # G.Router.invoked=True
G.Router.isCalled.succeed(G.env.now) # G.Router.isCalled.succeed(G.env.now)
except: # except:
pass # pass
return activeEntity # return activeEntity
# ======================================================================= # =======================================================================
# gets an entity from the predecessor that # gets an entity from the predecessor that
...@@ -117,16 +117,16 @@ class RoutingQueue(Queue): ...@@ -117,16 +117,16 @@ class RoutingQueue(Queue):
# 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
try: # try:
if self.level: # if self.level:
if len(self.getActiveObjectQueue())==self.level: # if len(self.getActiveObjectQueue())==self.level:
from Globals import G # from Globals import G
if not G.Router.invoked: # if not G.Router.invoked:
G.Router.invoked=True # G.Router.invoked=True
G.Router.isCalled.succeed(G.env.now) # G.Router.isCalled.succeed(G.env.now)
except: # except:
pass # pass
return activeEntity return activeEntity
# ======================================================================= # =======================================================================
......
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