Commit 1690ed88 authored by Georgios Dagkakis's avatar Georgios Dagkakis

Exit to be able to end the simulation - not working correct yet

parent cf9e01f9
......@@ -37,7 +37,7 @@ class Exit(CoreObject):
family='Exit'
def __init__(self, id, name, **kw):
def __init__(self, id, name, cancelCondition={},**kw):
self.type="Exit" # XXX needed ?
#lists to hold statistics of multiple runs
self.Exits=[]
......@@ -48,6 +48,7 @@ class Exit(CoreObject):
CoreObject.__init__(self, id, name)
from Globals import G
G.ExitList.append(self)
self.cancelCondition=cancelCondition
def initialize(self):
# using the Process __init__ and not the CoreObject __init__
......@@ -121,6 +122,12 @@ class Exit(CoreObject):
self.timeLastEntityLeft=self.env.now # update the time that the last entity left from the Exit
activeObjectQueue=self.getActiveObjectQueue()
del self.Res.users[:]
# if there is a cancelCondition the exit may end the simulation
if self.cancelCondition:
if self.cancelCondition.get('reason',None) =='throughput' and int(self.cancelCondition.get('number',-1))==self.numOfExits:
self.endSimulation()
if self.cancelCondition.get('reason',None) =='empty' and self.checkIfSystemEmpty():
self.endSimulation()
return activeEntity
@staticmethod
......
......@@ -175,3 +175,22 @@ class ManPyObject(object):
# =======================================================================
def outputResultsJSON(self):
pass
# =======================================================================
# ends the simulation
# ======================================================================
@staticmethod
def endSimulation():
from Globals import G
G.env.exit()
# =======================================================================
# checks if there are entities in the system
# ======================================================================
@staticmethod
def checkIfSystemEmpty():
from Globals import G
for object in G.ObjList:
if len(object.getActiveObjectQueue()):
return False
return 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