Commit 351faa1e authored by Georgios Dagkakis's avatar Georgios Dagkakis Committed by Sebastien Robin

haveToDispose updated so that the caller is passed as an Argument. Now there...

haveToDispose updated so that the caller is passed as an Argument. Now there is not use of the sys._getFrame method in ManPy, that might caue problems in different version. Execution does not seem to get faster
parent d06b9bed
......@@ -149,7 +149,7 @@ class Assembly(CoreObject):
if(coreObject.Res.activeQ[0].type=='Frame'):
#update the predecessorIndex
self.predecessorIndex=i
return len(self.Res.activeQ)==0 and coreObject.haveToDispose()
return len(self.Res.activeQ)==0 and coreObject.haveToDispose(self)
i=i+1
return False
......@@ -164,25 +164,12 @@ class Assembly(CoreObject):
if(coreObject.Res.activeQ[0].type=='Part'):
#update the predecessorIndex
self.predecessorIndex=i
return len(self.Res.activeQ)==1 and coreObject.haveToDispose()
return len(self.Res.activeQ)==1 and coreObject.haveToDispose(self)
i=i+1
return False
#activate only if the caller is not empty
if(len(thecaller.Res.activeQ)>0):
#activate only if the caller carries Part
if(thecaller.Res.activeQ[0].type=='Part'):
#update the predecessorIndex
i=0
for coreObject in self.previous:
if coreObject is thecaller:
self.predecessorIndex=i
i=i+1
return len(self.Res.activeQ)==1 and thecaller.haveToDispose()
return False
#checks if the Assembly can dispose an entity to the following object
def haveToDispose(self):
def haveToDispose(self, callerObject=None):
return len(self.Res.activeQ)>0 and self.waitToDispose
#removes an entity from the Assembly
......
......@@ -187,7 +187,7 @@ class Conveyer(CoreObject):
#checks if the Conveyer can accept an entity and there is a Frame waiting for it
def canAcceptAndIsRequested(self):
return self.canAccept(self) and self.previous[0].haveToDispose()
return self.canAccept(self) and self.previous[0].haveToDispose(self)
#gets an entity from the predecessor
def getEntity(self):
......@@ -217,7 +217,7 @@ class Conveyer(CoreObject):
self.call=True
#checks if the Conveyer can dispose an entity to the following object
def haveToDispose(self):
def haveToDispose(self, callerObject=None):
#it has meaning only if there are one or more entities in the conveyer
if len(self.position)>0:
return len(self.Res.activeQ)>0 and self.length-self.position[0]<0.000001 #the conveyer can dispose an object
......
......@@ -97,7 +97,7 @@ class CoreObject(Process):
pass
#checks if the Object can dispose an entity to the following object
def haveToDispose(self):
def haveToDispose(self, callerObject=None):
return len(self.Res.activeQ)>0
#checks if the Object can accept an entity and there is an entity in some predecessor waiting for it
......
......@@ -127,7 +127,7 @@ class Dismantle(CoreObject):
#checks if the Dismantle can accept an entity and there is a Frame waiting for it
def canAcceptAndIsRequested(self):
return len(self.Res.activeQ)==0 and self.previous[0].haveToDispose()
return len(self.Res.activeQ)==0 and self.previous[0].haveToDispose(self)
#checks if the Dismantle can accept an entity
def canAccept(self, callerObject=None):
......@@ -139,15 +139,9 @@ class Dismantle(CoreObject):
self.nextFrame=nf
#checks if the caller waits for a part or a frame and if the Dismantle is in the state of disposing one it returnse true
def haveToDispose(self):
#identify the caller method
frame = sys._getframe(1)
arguments = frame.f_code.co_argcount
if arguments == 0:
print "Not called from a method"
return
caller_calls_self = frame.f_code.co_varnames[0]
thecaller = frame.f_locals[caller_calls_self]
def haveToDispose(self, callerObject=None):
thecaller=callerObject
#according to the caller return true or false
if thecaller in self.nextPart:
......
......@@ -103,11 +103,11 @@ class Exit(CoreObject):
#checks if the Exit can accept an entity and there is an entity waiting for it
def canAcceptAndIsRequested(self):
if(len(self.previous)==1):
return self.previous[0].haveToDispose()
return self.previous[0].haveToDispose(self)
isRequested=False
for i in range(len(self.previous)):
if(self.previous[i].haveToDispose()):
if(self.previous[i].haveToDispose(self)):
isRequested=True
self.predecessorIndex=i
return isRequested
......
......@@ -33,7 +33,6 @@ from CoreObject import CoreObject
from RandomNumberGenerator import RandomNumberGenerator
import scipy.stats as stat
import sys
#the Machine object
class Machine(CoreObject):
......@@ -217,14 +216,14 @@ class Machine(CoreObject):
def canAcceptAndIsRequested(self):
#if we have only one predecessor just check if there is a place, the machine is up and the predecessor has an entity to dispose
if(len(self.previous)==1):
return self.Up and len(self.Res.activeQ)==0 and self.previous[0].haveToDispose()
return self.Up and len(self.Res.activeQ)==0 and self.previous[0].haveToDispose(self)
isRequested=False
maxTimeWaiting=0
#loop through the predecessors to see which have to dispose and which is the one blocked for longer
for i in range(len(self.previous)):
if(self.previous[i].haveToDispose()):
if(self.previous[i].haveToDispose(self)):
isRequested=True
if(self.previous[i].downTimeInTryingToReleaseCurrentEntity>0):
timeWaiting=now()-self.previous[i].timeLastFailureEnded
......@@ -251,24 +250,17 @@ class Machine(CoreObject):
self.downTimeInTryingToReleaseCurrentEntity=0
#checks if the Machine can dispose an entity to the following object
def haveToDispose(self):
def haveToDispose(self, callerObject=None):
#if we have only one successor just check if machine waits to dispose and also is up
if(len(self.next)==1):
if(len(self.next)==1 or callerObject==None):
return len(self.Res.activeQ)>0 and self.waitToDispose and self.Up
#if the Machine is empty it returns false right away
if(len(self.Res.activeQ)==0):
return False
#identify the caller method
frame = sys._getframe(1)
arguments = frame.f_code.co_argcount
if arguments == 0:
print "Not called from a method"
return
caller_calls_self = frame.f_code.co_varnames[0]
thecaller = frame.f_locals[caller_calls_self]
thecaller=callerObject
#give the entity to the successor that is waiting for the most time.
#plant does not do this in every occasion!
maxTimeWaiting=0
......
......@@ -29,8 +29,6 @@ Models a FIFO queue where entities can wait in order to get into a server
from SimPy.Simulation import *
from CoreObject import CoreObject
#import sys
#the Queue object
class Queue(CoreObject):
......@@ -111,23 +109,16 @@ class Queue(CoreObject):
#checks if the Queue can dispose an entity to the following object
#it checks also who called it and returns TRUE only to the successor that will give the entity.
#this is kind of slow I think got to check
def haveToDispose(self):
def haveToDispose(self, callerObject=None):
#if we have only one successor just check if the Queue holds one or more entities
if(len(self.next)==1):
if(len(self.next)==1 or callerObject==None):
return len(self.Res.activeQ)>0
#if the Queue is empty it returns false right away
if(len(self.Res.activeQ)==0):
return False
#identify the caller method
frame = sys._getframe(1)
arguments = frame.f_code.co_argcount
if arguments == 0:
print "Not called from a method"
return
caller_calls_self = frame.f_code.co_varnames[0]
thecaller = frame.f_locals[caller_calls_self]
thecaller=callerObject
#give the entity to the successor that is waiting for the most time.
#plant does not do this in every occasion!
......@@ -150,14 +141,14 @@ class Queue(CoreObject):
def canAcceptAndIsRequested(self):
#if we have only one predecessor just check if there is a place available and the predecessor has an entity to dispose
if(len(self.previous)==1):
return len(self.Res.activeQ)<self.capacity and self.previous[0].haveToDispose()
return len(self.Res.activeQ)<self.capacity and self.previous[0].haveToDispose(self)
isRequested=False
maxTimeWaiting=0
#loop through the predecessors to see which have to dispose and which is the one blocked for longer
for i in range(len(self.previous)):
if(self.previous[i].haveToDispose()):
if(self.previous[i].haveToDispose(self)):
isRequested=True
if(self.previous[i].downTimeInTryingToReleaseCurrentEntity>0):
timeWaiting=now()-self.previous[i].timeLastFailureEnded
......
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