generator of Source updated, minor bug fixed

parent 12aee243
...@@ -56,6 +56,7 @@ class EntityGenerator(Process): ...@@ -56,6 +56,7 @@ class EntityGenerator(Process):
# the generator of the EntitiesGenerator # the generator of the EntitiesGenerator
#=========================================================================== #===========================================================================
def run(self): def run(self):
# print 'entity generator starts'
while 1: while 1:
entity=self.victim.createEntity() # create the Entity object and assign its name entity=self.victim.createEntity() # create the Entity object and assign its name
entity.creationTime=now() # assign the current simulation time as the Entity's creation time entity.creationTime=now() # assign the current simulation time as the Entity's creation time
...@@ -66,8 +67,8 @@ class EntityGenerator(Process): ...@@ -66,8 +67,8 @@ class EntityGenerator(Process):
self.victim.getActiveObjectQueue().append(entity) # append the entity to the resource self.victim.getActiveObjectQueue().append(entity) # append the entity to the resource
self.victim.numberOfArrivals+=1 # we have one new arrival self.victim.numberOfArrivals+=1 # we have one new arrival
G.numberOfEntities+=1 G.numberOfEntities+=1
yield hold,self,self.victim.calculateInterarrivalTime() # wait until the next arrival
self.victim.entityCreated.signal(str(entity.name)+' created') self.victim.entityCreated.signal(str(entity.name)+' created')
yield hold,self,self.victim.calculateInterarrivalTime() # wait until the next arrival
#============================================================================ #============================================================================
# The Source object is a Process # The Source object is a Process
...@@ -111,8 +112,9 @@ class Source(CoreObject): ...@@ -111,8 +112,9 @@ class Source(CoreObject):
self.Res.activeQ=[] self.Res.activeQ=[]
self.Res.waitQ=[] self.Res.waitQ=[]
activate(self.entityGenerator,self.entityGenerator.run())
self.entityGenerator.initialize() self.entityGenerator.initialize()
activate(self.entityGenerator,self.entityGenerator.run())
#=========================================================================== #===========================================================================
# the generator of the Source class # the generator of the Source class
...@@ -123,19 +125,34 @@ class Source(CoreObject): ...@@ -123,19 +125,34 @@ class Source(CoreObject):
activeObjectQueue=self.getActiveObjectQueue() activeObjectQueue=self.getActiveObjectQueue()
while 1: while 1:
# if the source has no entity to dispose of has to wait till it has something # wait for any event (entity creation or request for disposal of entity)
if not self.haveToDispose(): yield waitevent, self, [self.entityCreated, self.canDispose]
yield waitevent, self, self.entityCreated # if an entity is created try to signal the receiver and continue
# if there is no available successor to signal the source has to wait till there is one available if self.entityCreated.signalparam:
if not activeObject.signalReceiver(): self.entityCreated.signalparam=None
while 1: if self.signalReceiver():
yield waitevent, self, self.canDispose continue
if activeObject.signalReceiver(): # otherwise, if the receiver requests availability then try to signal him if there is anything to dispose of
break if self.canDispose.signalparam:
# note, it needs to lose the control here. self.canDispose.signalparam=None
# TODO Need to think if self.haveToDispose():
else: if self.signalReceiver():
yield hold, self, 0 continue
# # if the source has no entity to dispose of has to wait till it has something
# if not self.haveToDispose():
# yield waitevent, self, self.entityCreated
# # if there is no available successor to signal the source has to wait till there is one available
# if not activeObject.signalReceiver():
# while 1:
# yield waitevent, self, self.canDispose
# if activeObject.signalReceiver():
# break
# # note, it needs to lose the control here.
# # TODO Need to think
# else:
# yield hold, self, 0
#============================================================================ #============================================================================
# sets the routing out element for the Source # sets the routing out element for the Source
......
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