updateMoveTime() added to calculate the timeToWait of the conveyerMover

parent 4aeea5d2
...@@ -98,13 +98,16 @@ class Conveyer(CoreObject): ...@@ -98,13 +98,16 @@ class Conveyer(CoreObject):
while 1: while 1:
#calculate the time to reach end. If this is greater than 0 (we did not already have an entity at the end) #calculate the time to reach end. If this is greater than 0 (we did not already have an entity at the end)
#set it as the timeToWait of the conveyerMover and raise call=true so that it will be triggered #set it as the timeToWait of the conveyerMover and raise call=true so that it will be triggered
self.timeToReachEnd=0 # self.timeToReachEnd=0
if self.position: # if self.position:
if (not self.length-self.position[0]<0.000001): # if (not self.length-self.position[0]<0.000001):
self.timeToReachEnd=((self.length-self.position[0])/float(self.speed))/60 # self.timeToReachEnd=((self.length-self.position[0])/float(self.speed))/60
if self.timeToReachEnd>0: # if self.timeToReachEnd>0:
self.conveyerMover.timeToWait=self.timeToReachEnd # self.conveyerMover.timeToWait=self.timeToReachEnd
self.conveyerMover.canMove.signal(now()) # self.conveyerMover.canMove.signal(now())
if self.updateMoveTime():
# print self.id, 'time to move', self.conveyerMover.timeToWait
self.conveyerMover.canMove.signal(now())
self.printTrace(self.id, 'will wait for event') self.printTrace(self.id, 'will wait for event')
yield waitevent, self, [self.isRequested,self.canDispose, self.moveEnd] # , self.loadOperatorAvailable] yield waitevent, self, [self.isRequested,self.canDispose, self.moveEnd] # , self.loadOperatorAvailable]
...@@ -148,9 +151,35 @@ class Conveyer(CoreObject): ...@@ -148,9 +151,35 @@ class Conveyer(CoreObject):
self.signalReceiver() self.signalReceiver()
#=========================================================================== #===========================================================================
# checks if there is any entity at the exit # calculate move time
#===========================================================================
def updateMoveTime(self):
# calculate time to reach end
timeToReachEnd=0
if self.position:
if (not self.length-self.position[0]<0.000001):
timeToReachEnd=((self.length-self.position[0])/float(self.speed))/60
# calculate time to become available
timeToBecomeAvailable=0
if self.position:
if self.currentRequestedLength>self.position[-1]:
timeToBecomeAvailable=((self.currentRequestedLength-self.position[-1])/float(self.speed))/60
# pick the smallest but not zero
timeToWait=0
if timeToReachEnd>0:
timeToWait=timeToReachEnd
if timeToBecomeAvailable>0:
if timeToBecomeAvailable<timeToWait:
timeToWait=timeToBecomeAvailable
self.conveyerMover.timeToWait=timeToWait
if timeToWait>0.000001:
return True
return False
#=========================================================================== #===========================================================================
def entityAtExit(self): # calculate the requested length
#===========================================================================
def requestedLength(self):
pass pass
#=========================================================================== #===========================================================================
...@@ -280,9 +309,14 @@ class Conveyer(CoreObject): ...@@ -280,9 +309,14 @@ class Conveyer(CoreObject):
giverObject=callerObject giverObject=callerObject
assert giverObject, 'there must be a caller for canAcceptAndIsRequested' assert giverObject, 'there must be a caller for canAcceptAndIsRequested'
self.calculateAvailableLength() self.calculateAvailableLength()
return self.enoughSpaceFor(giverObject)and\ if self.enoughSpaceFor(giverObject)and\
giverObject.haveToDispose(activeObject) and\ giverObject.haveToDispose(activeObject) and\
giverObject in activeObject.previous giverObject in activeObject.previous:
# if the conveyer can accept an entity is not blocked and thus the requested length has to be reset
# print 'reseting requested length'
self.currentRequestedLength=0
return True
return False
#=========================================================================== #===========================================================================
# gets an entity from the predecessor # gets an entity from the predecessor
...@@ -314,15 +348,14 @@ class Conveyer(CoreObject): ...@@ -314,15 +348,14 @@ class Conveyer(CoreObject):
if self.wasFull: if self.wasFull:
# self.totalBlockageTime+=now()-self.timeBlockageStarted # self.totalBlockageTime+=now()-self.timeBlockageStarted
self.wasFull=False self.wasFull=False
#calculate the time that the conveyer will become available again and trigger the conveyerMover # #calculate the time that the conveyer will become available again and trigger the conveyerMover
self.timeToBecomeAvailable=((self.position[-1]+self.currentRequestedLength)/float(self.speed))/60 # self.timeToBecomeAvailable=((self.position[-1]+self.currentRequestedLength)/float(self.speed))/60
# print self.id, 'time to become available', self.timeToBecomeAvailable # # print self.id, 'time to become available', self.timeToBecomeAvailable
self.conveyerMover.timeToWait=self.timeToBecomeAvailable # self.conveyerMover.timeToWait=self.timeToBecomeAvailable
# self.conveyerMover.canMove.signal(now())
if self.updateMoveTime():
# print self.id, 'time to move', self.conveyerMover.timeToWait
self.conveyerMover.canMove.signal(now()) self.conveyerMover.canMove.signal(now())
# # if the available length is not zero then try to signal a giver
# if self.canAccept():
# self.printTrace(self.id, 'will try to signal Giver from removeEntity')
# self.signalGiver()
# if there is anything to dispose of then signal a receiver # if there is anything to dispose of then signal a receiver
if self.haveToDispose(): if self.haveToDispose():
self.printTrace(self.id, 'will try to signal a receiver from removeEntity') self.printTrace(self.id, 'will try to signal a receiver from removeEntity')
...@@ -378,7 +411,7 @@ class Conveyer(CoreObject): ...@@ -378,7 +411,7 @@ class Conveyer(CoreObject):
def postProcessing(self, MaxSimtime=None): def postProcessing(self, MaxSimtime=None):
if MaxSimtime==None: if MaxSimtime==None:
from Globals import G from Globals import G
MaxSimtime=G.maxSimTime MaxSimtime=G.maxSimTime
self.moveEntities() #move the entities to count the working time self.moveEntities() #move the entities to count the working time
#if the conveyer is full count the blockage time #if the conveyer is full count the blockage time
if self.isFull(): if self.isFull():
...@@ -386,7 +419,7 @@ class Conveyer(CoreObject): ...@@ -386,7 +419,7 @@ class Conveyer(CoreObject):
#when the conveyer was nor working or blocked it was waiting #when the conveyer was nor working or blocked it was waiting
self.totalWaitingTime=MaxSimtime-self.totalWorkingTime-self.totalBlockageTime self.totalWaitingTime=MaxSimtime-self.totalWorkingTime-self.totalBlockageTime
#update the lists to hold data for multiple runs #update the lists to hold data for multiple runs
self.Waiting.append(100*self.totalWaitingTime/MaxSimtime) self.Waiting.append(100*self.totalWaitingTime/MaxSimtime)
self.Working.append(100*self.totalWorkingTime/MaxSimtime) self.Working.append(100*self.totalWorkingTime/MaxSimtime)
......
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