Commit 5d8e0425 authored by Georgios Dagkakis's avatar Georgios Dagkakis Committed by Jérome Perrin

changes so that the system can run for infinite time and end when it gets empty

parent c69bbc2a
...@@ -49,13 +49,15 @@ class CapacityStationController(EventGenerator): ...@@ -49,13 +49,15 @@ class CapacityStationController(EventGenerator):
if self.stop: if self.stop:
if self.env.now>self.stop: if self.env.now>self.stop:
break break
# activate the main loop
self.env.process(self.steps()) self.env.process(self.steps())
# wait until the main loop is completed
yield self.stepsAreComplete yield self.stepsAreComplete
self.stepsAreComplete=self.env.event() self.stepsAreComplete=self.env.event()
yield self.env.timeout(self.interval) #wait for the predetermined interval yield self.env.timeout(self.interval) #wait for the predetermined interval
def steps(self):
# the main loop that is carried in every interval
def steps(self):
# loop through the stations # loop through the stations
for station in G.CapacityStationList: for station in G.CapacityStationList:
exit=station.next[0] # take the exit exit=station.next[0] # take the exit
...@@ -72,6 +74,11 @@ class CapacityStationController(EventGenerator): ...@@ -72,6 +74,11 @@ class CapacityStationController(EventGenerator):
# lock the exit again # lock the exit again
exit.isLocked=True exit.isLocked=True
# if the last exits led to an empty system then the simulation must be stopped
# step returns and the generator never yields the stepsAreComplete signal
if self.checkIfSystemEmpty():
return
# create the entities in the following stations # create the entities in the following stations
self.createInCapacityStationBuffers() self.createInCapacityStationBuffers()
# if there is need to merge entities in a buffer # if there is need to merge entities in a buffer
...@@ -84,6 +91,7 @@ class CapacityStationController(EventGenerator): ...@@ -84,6 +91,7 @@ class CapacityStationController(EventGenerator):
# and set the flags to the entities of StationBuffers # and set the flags to the entities of StationBuffers
self.calculateWhatIsToBeProcessed() self.calculateWhatIsToBeProcessed()
# move the entities into the stations
# loop through the stations # loop through the stations
for station in G.CapacityStationList: for station in G.CapacityStationList:
station.isLocked=False # unlock the station station.isLocked=False # unlock the station
...@@ -104,13 +112,9 @@ class CapacityStationController(EventGenerator): ...@@ -104,13 +112,9 @@ class CapacityStationController(EventGenerator):
# for every station update the remaining interval capacity so that it is ready for next loop # for every station update the remaining interval capacity so that it is ready for next loop
for station in G.CapacityStationList: for station in G.CapacityStationList:
station.remainingIntervalCapacity.pop(0) station.remainingIntervalCapacity.pop(0)
self.stepsAreComplete.succeed()
# send message that the main loop is completed
def checkIfStationsEmpty(self): self.stepsAreComplete.succeed()
for station in G.CapacityStationList:
if len(station.getActiveObjectQueue()):
return False
return True
# invoked after entities have exited one station to create # invoked after entities have exited one station to create
# the corresponding entities to the following buffer # the corresponding entities to the following buffer
...@@ -211,11 +215,12 @@ class CapacityStationController(EventGenerator): ...@@ -211,11 +215,12 @@ class CapacityStationController(EventGenerator):
entityToCreate.currentStation=buffer entityToCreate.currentStation=buffer
entityToCreate.initialize() entityToCreate.initialize()
import Globals import Globals
Globals.setWIP([entityToCreate]) #set the new components as wip Globals.setWIP([entityToCreate]) #set the new components as wip
# checks if the system is empty so that the simulation can be stopped
def checkIfBufferFinished(self, buffer): def checkIfSystemEmpty(self):
if buffer.getActiveObjectQueue(): for object in G.CapacityStationList+G.CapacityStationBufferList+G.CapacityStationExitList:
return False if len(object.getActiveObjectQueue()):
return True return False
return True
\ No newline at end of file
\ No newline at end of file
...@@ -817,6 +817,7 @@ def createObjects(): ...@@ -817,6 +817,7 @@ def createObjects():
nextCapacityStationBufferId=element.get('nextCapacityStationBufferId', None) nextCapacityStationBufferId=element.get('nextCapacityStationBufferId', None)
CE=CapacityStationExit(id,name,nextCapacityStationBufferId=nextCapacityStationBufferId) CE=CapacityStationExit(id,name,nextCapacityStationBufferId=nextCapacityStationBufferId)
G.CapacityStationExitList.append(CE) G.CapacityStationExitList.append(CE)
G.ExitList.append(CE)
G.ObjList.append(CE) G.ObjList.append(CE)
# ----------------------------------------------------------------------- # -----------------------------------------------------------------------
......
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