basic signalling altered. now succeed() should be provided with the...

basic signalling altered. now succeed() should be provided with the transmitter and the time as arguments
parent 12ebe2f8
......@@ -156,7 +156,8 @@ class Assembly(CoreObject):
# wait until the Queue can accept an entity and one predecessor requests it
yield self.isRequested #[self.isRequested,self.canDispose, self.loadOperatorAvailable]
if self.isRequested.value:
self.printTrace(self.id, isRequested=self.isRequested.value.id)
transmitter, eventTime=self.isRequested.value
self.printTrace(self.id, isRequested=transmitter.id)
# reset the isRequested signal parameter
self.isRequested=self.env.event()
......@@ -166,7 +167,8 @@ class Assembly(CoreObject):
self.printTrace(self.id, waitEvent='(to load parts)')
yield self.isRequested
if self.isRequested.value:
self.printTrace(self.id, isRequested=self.isRequested.value.id)
transmitter, eventTime=self.isRequested.value
self.printTrace(self.id, isRequested=transmitter.id)
# reset the isRequested signal parameter
self.isRequested=self.env.event()
# TODO: fix the getEntity 'Part' case
......@@ -205,14 +207,16 @@ class Assembly(CoreObject):
# if there was interruption
# TODO not good implementation
if self.interruptionStart in receivedEvent:
assert self.interruptionStart.value==self.env.now, 'the interruption has not been processed on the time of activation'
transmitter, eventTime=self.interruptionStart.value
assert eventTime==self.env.now, 'the interruption has not been processed on the time of activation'
self.interruptionStart=self.env.event()
# wait for the end of the interruption
self.interruptionActions() # execute interruption actions
# loop until we reach at a state that there is no interruption
while 1:
yield self.interruptionEnd # interruptionEnd to be triggered by ObjectInterruption
assert self.env.now==self.interruptionEnd.value, 'the victim of the failure is not the object that received it'
transmitter, eventTime=self.interruptionEnd.value
assert eventTime==self.env.now, 'the victim of the failure is not the object that received it'
self.interruptionEnd=self.env.event()
if self.Up and self.onShift:
break
......@@ -223,10 +227,11 @@ class Assembly(CoreObject):
else:
continue
if self.canDispose in receivedEvent:
if self.canDispose.value!=self.env.now:
transmitter, eventTime=self.canDispose.value
if eventTime!=self.env.now:
self.canDispose=self.env.event()
continue
assert self.canDispose.value==self.env.now,'canDispose signal is late'
assert eventTime==self.env.now,'canDispose signal is late'
self.canDispose=self.env.event()
# try to signal a receiver, if successful then proceed to get an other entity
if self.signalReceiver():
......@@ -242,8 +247,9 @@ class Assembly(CoreObject):
self.waitEntityRemoval=True
self.printTrace(self.id, waitEvent='(entityRemoved)')
yield self.entityRemoved
self.printTrace(self.id, entityRemoved=self.entityRemoved.value)
assert self.entityRemoved.value==self.env.now,'entityRemoved event activated earlier than received'
transmitter, eventTime=self.entityRemoved.value
self.printTrace(self.id, entityRemoved=eventTime)
assert eventTime==self.env.now,'entityRemoved event activated earlier than received'
self.waitEntityRemoval=False
self.entityRemoved=self.env.event()
# if while waiting (for a canDispose event) became free as the machines that follows emptied it, then proceed
......
......@@ -103,12 +103,14 @@ class Conveyer(CoreObject):
#set it as the timeToWait of the conveyerMover and raise call=true so that it will be triggered
if self.updateMoveTime():
# print self.id, 'time to move', self.conveyerMover.timeToWait
self.conveyerMover.canMove.succeed(self.env.now)
succeedTuple=(self,self.env.now)
self.conveyerMover.canMove.succeed(succeedTuple)
self.printTrace(self.id, waitEvent='')
receivedEvent=yield self.env.any_of([self.isRequested , self.canDispose , self.moveEnd]) # , self.loadOperatorAvailable]
# if the event that activated the thread is isRequested then getEntity
if self.isRequested in receivedEvent:
transmitter, eventTime=self.isRequested.value
self.printTrace(self.id, isRequested='')
# reset the isRequested signal parameter
self.isRequested=self.env.event()
......@@ -122,10 +124,12 @@ class Conveyer(CoreObject):
# self.loadOperatorAvailable.value=None
# if the queue received an canDispose with signalparam time, this means that the signals was sent from a MouldAssemblyBuffer
if self.canDispose in receivedEvent:
transmitter, eventTime=self.canDispose.value
self.printTrace(self.id, canDispose='')
self.canDispose=self.env.event()
# if the object received a moveEnd signal from the ConveyerMover
if self.moveEnd in receivedEvent:
transmitter, eventTime=self.moveEnd.value
self.printTrace(self.id, moveEnd='')
self.moveEnd=self.env.event()
# check if there is a possibility to accept and signal a giver
......@@ -359,7 +363,8 @@ class Conveyer(CoreObject):
#calculate the time that the conveyer will become available again and trigger the conveyerMover
if self.updateMoveTime():
# print self.id, 'time to move', self.conveyerMover.timeToWait
self.conveyerMover.canMove.succeed(self.env.now)
succeedTuple=(self,self.env.now)
self.conveyerMover.canMove.succeed(succeedTuple)
# if there is anything to dispose of then signal a receiver
if self.haveToDispose():
self.printTrace(self.id, attemptSingalReceiver='(removeEntity)')
......@@ -519,13 +524,15 @@ class ConveyerMover(object):
while 1:
self.conveyer.printTrace(self.conveyer.id, waitEvent='(canMove)')
yield self.canMove #wait until the conveyer triggers the mover
transmitter, eventTime=self.canMove.value
self.canMove=self.env.event()
self.conveyer.printTrace(self.conveyer.id, received='(canMove)')
yield self.env.timeout(self.timeToWait) #wait for the time that the conveyer calculated
# continue if interrupted
self.conveyer.moveEntities() # move the entities of the conveyer
self.conveyer.moveEnd.succeed(self.env.now) # send a signal to the conveyer that the move has ended
succeedTuple=(self,self.env.now)
self.conveyer.moveEnd.succeed(succeedTuple) # send a signal to the conveyer that the move has ended
......@@ -267,11 +267,13 @@ class CoreObject(ManPyObject):
# print self.id,'triggered and waiting'
self.entityRemoved=self.env.event()
self.printTrace(self.id, signal='(removedEntity)')
self.entityRemoved.succeed(self.env.now)
succeedTuple=(self,self.env.now)
self.entityRemoved.succeed(succeedTuple)
elif self.waitEntityRemoval:
# print self.id,'not triggered and waiting'
self.printTrace(self.id, signal='(removedEntity)')
self.entityRemoved.succeed(self.env.now)
succeedTuple=(self,self.env.now)
self.entityRemoved.succeed(succeedTuple)
elif not self.waitEntityRemoval:
# print self.id,'not triggered but not waiting'
pass
......@@ -460,7 +462,8 @@ class CoreObject(ManPyObject):
self.printTrace(self.id, signalReceiver=self.receiver.id)
# assign the entry of the receiver
self.receiver.assignEntryTo()
self.receiver.isRequested.succeed(self)
succeedTuple=(self,self.env.now)
self.receiver.isRequested.succeed(succeedTuple)
return True
# if no receiver can accept then try to preempt a receive if the stations holds a critical order
self.preemptReceiver()
......@@ -531,7 +534,8 @@ class CoreObject(ManPyObject):
self.giver=giver
self.giver.receiver=self
self.printTrace(self.id, signalGiver=self.giver.id)
self.giver.canDispose.succeed(self.env.now)
succeedTuple=(self,self.env.now)
self.giver.canDispose.succeed(succeedTuple)
return True
return False
......
......@@ -280,7 +280,8 @@ def setWIP(entityList):
if issubclass(entity.currentStation.__class__, Queue):
# send the signal only if it is not already triggered
if not entity.currentStation.canDispose.triggered:
entity.currentStation.canDispose.succeed(G.env.now)
succeedTuple=(G.env,G.env.now)
entity.currentStation.canDispose.succeed(succeedTuple)
# if we are in the start of the simulation the object is of server type then we should send initialWIP signal
# TODO, maybe use 'class_family attribute here'
if G.env.now==0 and entity.currentStation:
......@@ -291,7 +292,8 @@ def setWIP(entityList):
# trigger initialWIP event only if it has not been triggered. Otherwise
# if we set more than one entities (e.g. in reassembly) it will crash
if not (entity.currentStation.initialWIP.triggered):
entity.currentStation.initialWIP.succeed(G.env)
succeedTuple=(G.env,G.env.now)
entity.currentStation.initialWIP.succeed(succeedTuple)
def countIntervalThroughput():
......
This diff is collapsed.
......@@ -72,7 +72,8 @@ class ObjectInterruption(ManPyObject):
# signalling can be done via Machine request/releaseOperator
# =======================================================================
def invoke(self):
self.isCalled.succeed(self.env.now)
succeedTuple=(self.victim,self.env.now)
self.isCalled.succeed(succeedTuple)
#===========================================================================
# returns the internal queue of the victim
......@@ -94,7 +95,8 @@ class ObjectInterruption(ManPyObject):
# inform the victim by whom will it be interrupted
# TODO: reconsider what happens when failure and ShiftScheduler (e.g.) signal simultaneously
self.victim.interruptedBy=self.type
self.victim.interruptionStart.succeed(self.env.now)
succeedTuple=(self,self.env.now)
self.victim.interruptionStart.succeed(succeedTuple)
# if the machines are operated by dedicated operators
if self.victim.dedicatedOperator:
# request allocation
......@@ -104,7 +106,8 @@ class ObjectInterruption(ManPyObject):
# reactivate the victim
#===========================================================================
def reactivateVictim(self):
self.victim.interruptionEnd.succeed(self.env.now)
succeedTuple=(self,self.env.now)
self.victim.interruptionEnd.succeed(succeedTuple)
#reset the interruptionStart event of the victim
self.victim.interruptionStart=self.env.event()
# TODO: reconsider what happens when failure and ShiftScheduler (e.g.) signal simultaneously
......
......@@ -72,7 +72,8 @@ class Broker(ObjectInterruption):
while 1:
# TODO: add new broker event - brokerIsCalled
yield self.isCalled
assert self.isCalled.value==self.env.now, 'the broker should be granted control instantly'
transmitter, eventTime=self.isCalled.value
assert eventTime==self.env.now, 'the broker should be granted control instantly'
self.isCalled=self.env.event()
self.victim.printTrace(self.victim.id, received='(broker)')
# ======= request a resource
......@@ -94,11 +95,13 @@ class Broker(ObjectInterruption):
if not G.Router.invoked:
self.victim.printTrace(self.victim.id, signal='router (broker)')
G.Router.invoked=True
G.Router.isCalled.succeed(self.env.now)
succeedTuple=(self,self.env.now)
G.Router.isCalled.succeed(succeedTuple)
self.waitForOperator=True
self.victim.printTrace(self.victim.id, waitEvent='(resourceIsAvailable broker)')
yield self.resourceAvailable
transmitter, eventTime=self.resourceAvailable.value
self.resourceAvailable=self.env.event()
# remove the currentEntity from the pendingEntities
if self.victim.currentEntity in G.pendingEntities:
......@@ -110,6 +113,7 @@ class Broker(ObjectInterruption):
self.waitForOperator=True
self.victim.printTrace(self.victim.id, waitEvent='(resourceIsAvailable broker)')
yield self.resourceAvailable
transmitter, eventTime=self.resourceAvailable.value
self.resourceAvailable=self.env.event()
self.waitForOperator=False
#===============================================================
......@@ -132,13 +136,15 @@ class Broker(ObjectInterruption):
self.victim.outputTrace(self.victim.currentOperator.objName, "started work in "+ self.victim.objName)
self.victim.currentOperator.timeLastOperationStarted=self.env.now#()
# signal the machine that an operator is reserved
self.victim.brokerIsSet.succeed(self.env.now)
succeedTuple=(self,self.env.now)
self.victim.brokerIsSet.succeed(succeedTuple)
# update the schedule of the operator
self.victim.currentOperator.schedule.append([self.victim, self.env.now])
# wait till the processing is over
yield self.isCalled
assert self.isCalled.value==self.env.now, 'the broker should be granted control instantly'
transmitter, eventTime=self.isCalled.value
assert eventTime==self.env.now, 'the broker should be granted control instantly'
self.isCalled=self.env.event()
# The operator is released (the router is not called in the case of skilled ops that work constantly on the same machine)
......@@ -153,7 +159,8 @@ class Broker(ObjectInterruption):
if not self.victim.router.invoked:
self.victim.printTrace(self.victim.id, signal='router (broker)')
self.victim.router.invoked=True
self.victim.router.isCalled.succeed(self.env.now)
succeedTuple=(self,self.env.now)
self.victim.router.isCalled.succeed(succeedTuple)
# TODO: signalling the router will give the chance to it to take the control, but when will it eventually receive it.
# after signalling the broker will signal it's victim that it has finished it's processes
# TODO: this wont work for the moment. The actions that follow must be performed by all operated brokers.
......@@ -168,5 +175,6 @@ class Broker(ObjectInterruption):
else:
pass
# return the control to the victim
self.victim.brokerIsSet.succeed(self.env.now)
succeedTuple=(self,self.env.now)
self.victim.brokerIsSet.succeed(succeedTuple)
......@@ -107,6 +107,7 @@ class Router(ObjectInterruption):
while 1:
# wait until the router is called
yield self.isCalled
transmitter, eventTime=self.isCalled.value
self.isCalled=self.env.event()
self.printTrace('','=-'*15)
self.printTrace('','router received event')
......@@ -238,13 +239,15 @@ class Router(ObjectInterruption):
elif station.broker.waitForOperator:
# signal this station's broker that the resource is available
self.printTrace('router', 'signalling broker of'+' '*50+operator.isAssignedTo().id)
station.broker.resourceAvailable.succeed(self.env.now)
succeedTuple=(self,self.env.now)
station.broker.resourceAvailable.succeed(succeedTuple)
else:
# signal the queue proceeding the station
if station.canAccept()\
and any(type=='Load' for type in station.multOperationTypeList):
self.printTrace('router', 'signalling'+' '*50+operator.isAssignedTo().id)
station.loadOperatorAvailable.succeed(self.env.now)
succeedTuple=(self,self.env.now)
station.loadOperatorAvailable.succeed(succeedTuple)
#===========================================================================
# clear the pending lists of the router
......
......@@ -102,7 +102,8 @@ class Queue(CoreObject):
self.printTrace(self.id, received='')
# if the event that activated the thread is isRequested then getEntity
if self.isRequested in receivedEvent:
self.printTrace(self.id, isRequested=self.isRequested.value.id)
transmitter, eventTime=self.isRequested.value
self.printTrace(self.id, isRequested=transmitter.id)
# reset the isRequested signal parameter
self.isRequested=self.env.event()
self.getEntity()
......@@ -111,10 +112,11 @@ class Queue(CoreObject):
activeObjectQueue[0].startTime=self.env.now
# if the queue received an loadOperatorIsAvailable (from Router) with signalparam time
if self.loadOperatorAvailable:
# self.printTrace(self.id, loadOperatorAvailable=str(self.loadOperatorAvailable.signalparam))
# transmitter, eventTime=self.loadOperatorAvailable.value
self.loadOperatorAvailable=self.env.event()
# if the queue received an canDispose with signalparam time, this means that the signals was sent from a MouldAssemblyBuffer
if self.canDispose in receivedEvent:
transmitter, eventTime=self.canDispose.value
self.printTrace(self.id, canDispose='')
self.canDispose=self.env.event()
# if the event that activated the thread is canDispose then signalReceiver
......
......@@ -63,7 +63,8 @@ class EntityGenerator(object):
self.victim.numberOfArrivals+=1 # we have one new arrival
G.numberOfEntities+=1
self.victim.appendEntity(entity)
self.victim.entityCreated.succeed(entity)
succeedTupple=(entity,self.env.now)
self.victim.entityCreated.succeed(succeedTupple)
# else put it on the time list for scheduled Entities
else:
entityCounter=G.numberOfEntities+len(self.victim.scheduledEntities) # this is used just ot output the trace correctly
......@@ -138,10 +139,15 @@ class Source(CoreObject):
self.printTrace(self.id, received='')
# if an entity is created try to signal the receiver and continue
if self.entityCreated in receivedEvent:
transmitter, eventTime=self.entityCreated.value
self.entityCreated=self.env.event()
# otherwise, if the receiver requests availability then try to signal him if there is anything to dispose of
if self.canDispose in receivedEvent or self.loadOperatorAvailable in receivedEvent:
if self.canDispose in receivedEvent:
transmitter, eventTime=self.canDispose.value
self.canDispose=self.env.event()
if self.loadOperatorAvailable in receivedEvent:
transmitter, eventTime=self.loadOperatorAvailable.value
self.loadOperatorAvailable=self.env.event()
if self.haveToDispose():
if self.signalReceiver():
......@@ -192,5 +198,6 @@ class Source(CoreObject):
self.appendEntity(newEntity)
activeEntity=CoreObject.removeEntity(self, entity) # run the default method
if len(self.getActiveObjectQueue())==1:
self.entityCreated.succeed(newEntity)
succeedTuple=(newEntity,self.env.now)
self.entityCreated.succeed(succeedTuple)
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