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): ...@@ -149,7 +149,7 @@ class Assembly(CoreObject):
if(coreObject.Res.activeQ[0].type=='Frame'): if(coreObject.Res.activeQ[0].type=='Frame'):
#update the predecessorIndex #update the predecessorIndex
self.predecessorIndex=i 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 i=i+1
return False return False
...@@ -164,25 +164,12 @@ class Assembly(CoreObject): ...@@ -164,25 +164,12 @@ class Assembly(CoreObject):
if(coreObject.Res.activeQ[0].type=='Part'): if(coreObject.Res.activeQ[0].type=='Part'):
#update the predecessorIndex #update the predecessorIndex
self.predecessorIndex=i 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 i=i+1
return False 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 #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 return len(self.Res.activeQ)>0 and self.waitToDispose
#removes an entity from the Assembly #removes an entity from the Assembly
......
...@@ -187,7 +187,7 @@ class Conveyer(CoreObject): ...@@ -187,7 +187,7 @@ class Conveyer(CoreObject):
#checks if the Conveyer can accept an entity and there is a Frame waiting for it #checks if the Conveyer can accept an entity and there is a Frame waiting for it
def canAcceptAndIsRequested(self): 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 #gets an entity from the predecessor
def getEntity(self): def getEntity(self):
...@@ -217,7 +217,7 @@ class Conveyer(CoreObject): ...@@ -217,7 +217,7 @@ class Conveyer(CoreObject):
self.call=True self.call=True
#checks if the Conveyer can dispose an entity to the following object #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 #it has meaning only if there are one or more entities in the conveyer
if len(self.position)>0: 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 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): ...@@ -97,7 +97,7 @@ class CoreObject(Process):
pass pass
#checks if the Object can dispose an entity to the following object #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 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 #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): ...@@ -127,7 +127,7 @@ class Dismantle(CoreObject):
#checks if the Dismantle can accept an entity and there is a Frame waiting for it #checks if the Dismantle can accept an entity and there is a Frame waiting for it
def canAcceptAndIsRequested(self): 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 #checks if the Dismantle can accept an entity
def canAccept(self, callerObject=None): def canAccept(self, callerObject=None):
...@@ -139,15 +139,9 @@ class Dismantle(CoreObject): ...@@ -139,15 +139,9 @@ class Dismantle(CoreObject):
self.nextFrame=nf 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 #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): def haveToDispose(self, callerObject=None):
#identify the caller method
frame = sys._getframe(1) thecaller=callerObject
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]
#according to the caller return true or false #according to the caller return true or false
if thecaller in self.nextPart: if thecaller in self.nextPart:
......
...@@ -103,11 +103,11 @@ class Exit(CoreObject): ...@@ -103,11 +103,11 @@ class Exit(CoreObject):
#checks if the Exit can accept an entity and there is an entity waiting for it #checks if the Exit can accept an entity and there is an entity waiting for it
def canAcceptAndIsRequested(self): def canAcceptAndIsRequested(self):
if(len(self.previous)==1): if(len(self.previous)==1):
return self.previous[0].haveToDispose() return self.previous[0].haveToDispose(self)
isRequested=False isRequested=False
for i in range(len(self.previous)): for i in range(len(self.previous)):
if(self.previous[i].haveToDispose()): if(self.previous[i].haveToDispose(self)):
isRequested=True isRequested=True
self.predecessorIndex=i self.predecessorIndex=i
return isRequested return isRequested
......
...@@ -33,7 +33,6 @@ from CoreObject import CoreObject ...@@ -33,7 +33,6 @@ from CoreObject import CoreObject
from RandomNumberGenerator import RandomNumberGenerator from RandomNumberGenerator import RandomNumberGenerator
import scipy.stats as stat import scipy.stats as stat
import sys
#the Machine object #the Machine object
class Machine(CoreObject): class Machine(CoreObject):
...@@ -217,14 +216,14 @@ class Machine(CoreObject): ...@@ -217,14 +216,14 @@ class Machine(CoreObject):
def canAcceptAndIsRequested(self): 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 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): 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 isRequested=False
maxTimeWaiting=0 maxTimeWaiting=0
#loop through the predecessors to see which have to dispose and which is the one blocked for longer #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)): for i in range(len(self.previous)):
if(self.previous[i].haveToDispose()): if(self.previous[i].haveToDispose(self)):
isRequested=True isRequested=True
if(self.previous[i].downTimeInTryingToReleaseCurrentEntity>0): if(self.previous[i].downTimeInTryingToReleaseCurrentEntity>0):
timeWaiting=now()-self.previous[i].timeLastFailureEnded timeWaiting=now()-self.previous[i].timeLastFailureEnded
...@@ -251,23 +250,16 @@ class Machine(CoreObject): ...@@ -251,23 +250,16 @@ class Machine(CoreObject):
self.downTimeInTryingToReleaseCurrentEntity=0 self.downTimeInTryingToReleaseCurrentEntity=0
#checks if the Machine can dispose an entity to the following object #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 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 return len(self.Res.activeQ)>0 and self.waitToDispose and self.Up
#if the Machine is empty it returns false right away #if the Machine is empty it returns false right away
if(len(self.Res.activeQ)==0): if(len(self.Res.activeQ)==0):
return False return False
#identify the caller method thecaller=callerObject
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]
#give the entity to the successor that is waiting for the most time. #give the entity to the successor that is waiting for the most time.
#plant does not do this in every occasion! #plant does not do this in every occasion!
......
...@@ -29,8 +29,6 @@ Models a FIFO queue where entities can wait in order to get into a server ...@@ -29,8 +29,6 @@ Models a FIFO queue where entities can wait in order to get into a server
from SimPy.Simulation import * from SimPy.Simulation import *
from CoreObject import CoreObject from CoreObject import CoreObject
#import sys
#the Queue object #the Queue object
class Queue(CoreObject): class Queue(CoreObject):
...@@ -111,23 +109,16 @@ class Queue(CoreObject): ...@@ -111,23 +109,16 @@ class Queue(CoreObject):
#checks if the Queue can dispose an entity to the following object #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. #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 #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 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 return len(self.Res.activeQ)>0
#if the Queue is empty it returns false right away #if the Queue is empty it returns false right away
if(len(self.Res.activeQ)==0): if(len(self.Res.activeQ)==0):
return False return False
#identify the caller method thecaller=callerObject
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]
#give the entity to the successor that is waiting for the most time. #give the entity to the successor that is waiting for the most time.
#plant does not do this in every occasion! #plant does not do this in every occasion!
...@@ -150,14 +141,14 @@ class Queue(CoreObject): ...@@ -150,14 +141,14 @@ class Queue(CoreObject):
def canAcceptAndIsRequested(self): 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 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): 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 isRequested=False
maxTimeWaiting=0 maxTimeWaiting=0
#loop through the predecessors to see which have to dispose and which is the one blocked for longer #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)): for i in range(len(self.previous)):
if(self.previous[i].haveToDispose()): if(self.previous[i].haveToDispose(self)):
isRequested=True isRequested=True
if(self.previous[i].downTimeInTryingToReleaseCurrentEntity>0): if(self.previous[i].downTimeInTryingToReleaseCurrentEntity>0):
timeWaiting=now()-self.previous[i].timeLastFailureEnded 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