Commit 66004ac5 authored by Georgios Dagkakis's avatar Georgios Dagkakis

CapacityStationController inherits run from EventGenerator

parent c8aae66a
...@@ -33,7 +33,7 @@ from Globals import G ...@@ -33,7 +33,7 @@ from Globals import G
class CapacityStationController(EventGenerator): class CapacityStationController(EventGenerator):
def __init__(self, id=id, name=None, start=0, stop=float('inf'), interval=1, def __init__(self, id=id, name=None, start=0, stop=float('inf'), interval=1,
duration=0, method=None, argumentDict=None, dueDateThreshold=float('inf'), duration=0, method=None, argumentDict={}, dueDateThreshold=float('inf'),
prioritizeIfCanFinish=False,**kw): prioritizeIfCanFinish=False,**kw):
EventGenerator.__init__(self, id, name, start, stop, interval, EventGenerator.__init__(self, id, name, start, stop, interval,
duration, method, argumentDict) duration, method, argumentDict)
...@@ -45,27 +45,12 @@ class CapacityStationController(EventGenerator): ...@@ -45,27 +45,12 @@ class CapacityStationController(EventGenerator):
self.prioritizeIfCanFinish=bool(int(prioritizeIfCanFinish)) self.prioritizeIfCanFinish=bool(int(prioritizeIfCanFinish))
# the total assemblySpace in the system # the total assemblySpace in the system
self.assemblySpace=float(G.extraPropertyDict.get('assemblySpace', float('inf'))) self.assemblySpace=float(G.extraPropertyDict.get('assemblySpace', float('inf')))
self.method=self.steps
def initialize(self): def initialize(self):
EventGenerator.initialize(self) EventGenerator.initialize(self)
self.stepsAreComplete=self.env.event()
def run(self):
# sort the buffers so if they have shared resources the ones with highest priority will go in front # sort the buffers so if they have shared resources the ones with highest priority will go in front
self.sortBuffers() self.sortBuffers()
yield self.env.timeout(self.start) #wait until the start time
#loop until the end of the simulation
while 1:
#if the stop time is exceeded then break the loop
if self.stop:
if self.env.now>self.stop:
break
# activate the main loop
self.env.process(self.steps())
# wait until the main loop is completed
yield self.stepsAreComplete
self.stepsAreComplete=self.env.event()
yield self.env.timeout(self.interval) #wait for the predetermined interval
# the main loop that is carried in every interval # the main loop that is carried in every interval
def steps(self): def steps(self):
...@@ -99,6 +84,8 @@ class CapacityStationController(EventGenerator): ...@@ -99,6 +84,8 @@ class CapacityStationController(EventGenerator):
# if the last exits led to an empty system then the simulation must be stopped # 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 # step returns and the generator never yields the stepsAreComplete signal
if self.checkIfSystemEmpty(): if self.checkIfSystemEmpty():
# if the system is empty set stop to now so that the generator stops and return
self.stop=self.env.now
return return
# if there is need to merge entities in a buffer # if there is need to merge entities in a buffer
...@@ -158,10 +145,7 @@ class CapacityStationController(EventGenerator): ...@@ -158,10 +145,7 @@ 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)
# send message that the main loop is completed
self.stepsAreComplete.succeed()
# 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
......
...@@ -32,7 +32,7 @@ from ObjectInterruption import ObjectInterruption ...@@ -32,7 +32,7 @@ from ObjectInterruption import ObjectInterruption
class EventGenerator(ObjectInterruption): class EventGenerator(ObjectInterruption):
def __init__(self, id=id, name=None, start=0, stop=float('inf'), interval=1, def __init__(self, id=id, name=None, start=0, stop=float('inf'), interval=1,
duration=0, method=None, argumentDict=None,**kw): duration=0, method=None, argumentDict=None, **kw):
ObjectInterruption.__init__(self) ObjectInterruption.__init__(self)
self.id=id self.id=id
self.name=name self.name=name
...@@ -47,6 +47,10 @@ class EventGenerator(ObjectInterruption): ...@@ -47,6 +47,10 @@ class EventGenerator(ObjectInterruption):
if method: if method:
import Globals import Globals
self.method=Globals.getMethodFromName(method) self.method=Globals.getMethodFromName(method)
def initialize(self):
ObjectInterruption.initialize(self)
self.methodEnded=self.env.event()
def run(self): def run(self):
yield self.env.timeout(self.start) #wait until the start time yield self.env.timeout(self.start) #wait until the start time
...@@ -56,8 +60,15 @@ class EventGenerator(ObjectInterruption): ...@@ -56,8 +60,15 @@ class EventGenerator(ObjectInterruption):
if self.stop: if self.stop:
if self.env.now>self.stop: if self.env.now>self.stop:
break break
self.method(**self.argumentDict) #call the method import inspect
yield self.env.timeout(self.interval) #wait for the predetermined interval # if the method is generator yield it
if inspect.isgeneratorfunction(self.method):
yield self.env.process(self.method(**self.argumentDict))
# else just call the method
else:
self.method(**self.argumentDict)
# wait for the predetermined interval
yield self.env.timeout(self.interval)
......
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