Commit a7672569 authored by Georgios Dagkakis's avatar Georgios Dagkakis Committed by Jérome Perrin

core objects updated so that predecessor/successorIndex are not needed

parent ac62132b
...@@ -62,8 +62,6 @@ class Assembly(CoreObject): ...@@ -62,8 +62,6 @@ class Assembly(CoreObject):
self.Working=[] self.Working=[]
self.Blockage=[] self.Blockage=[]
self.predecessorIndex=0 #holds the index of the predecessor from which the Assembly will take an entity next
self.successorIndex=0 #holds the index of the successor where the Assembly will dispose an entity next
# ============================== variable that is used for the loading of machines ============= # ============================== variable that is used for the loading of machines =============
self.exitAssignedToReceiver = False # by default the objects are not blocked self.exitAssignedToReceiver = False # by default the objects are not blocked
# when the entities have to be loaded to operatedMachines # when the entities have to be loaded to operatedMachines
...@@ -104,15 +102,12 @@ class Assembly(CoreObject): ...@@ -104,15 +102,12 @@ class Assembly(CoreObject):
self.Res=Resource(1) self.Res=Resource(1)
self.Res.activeQ=[] self.Res.activeQ=[]
self.Res.waitQ=[] self.Res.waitQ=[]
self.predecessorIndex=0 #holds the index of the predecessor from which the Assembly will take an entity next
self.successorIndex=0 #holds the index of the successor where the Assembly will dispose an entity next
def run(self): def run(self):
while 1: while 1:
yield waituntil, self, self.canAcceptAndIsRequested #wait until the Assembly can accept a frame yield waituntil, self, self.canAcceptAndIsRequested #wait until the Assembly can accept a frame
#and one "frame" predecessor requests it #and one "frame" giver requests it
self.getEntity("Frame") #get the Frame self.getEntity("Frame") #get the Frame
for i in range(self.getActiveObjectQueue()[0].capacity): #this loop will be carried until the Frame is full with the parts for i in range(self.getActiveObjectQueue()[0].capacity): #this loop will be carried until the Frame is full with the parts
...@@ -150,35 +145,31 @@ class Assembly(CoreObject): ...@@ -150,35 +145,31 @@ class Assembly(CoreObject):
#checks if the Assembly can accept an entity and there is a Frame waiting for it #checks if the Assembly can accept an entity and there is a Frame waiting for it
def canAcceptAndIsRequested(self): def canAcceptAndIsRequested(self):
activeObjectQueue=self.getActiveObjectQueue() activeObjectQueue=self.getActiveObjectQueue()
i=0 #loop through the possible givers
#loop through the predecessors for object in self.previous:
for giver in self.previous: #activate only if the possible giver is not empty
#activate only if the predecessor is not empty if(len(object.getActiveObjectQueue())>0):
if(len(giver.getActiveObjectQueue())>0):
#activate only if the caller carries Frame #activate only if the caller carries Frame
if(giver.getActiveObjectQueue()[0].type=='Frame'): if(object.getActiveObjectQueue()[0].type=='Frame'):
#update the predecessorIndex #update the giver
self.predecessorIndex=i self.giver=object
return len(activeObjectQueue)==0 and giver.haveToDispose(self) return len(activeObjectQueue)==0 and object.haveToDispose(self)
i=i+1
return False return False
#checks if the Assembly can accept an entity and there is a Frame waiting for it #checks if the Assembly can accept an entity and there is a Frame waiting for it
def isRequestedFromPart(self): def isRequestedFromPart(self):
activeObjectQueue=self.getActiveObjectQueue() activeObjectQueue=self.getActiveObjectQueue()
i=0 #loop through the possible givers
#loop through the predecessors for object in self.previous:
for giver in self.previous: #activate only if the possible giver is not empty
#activate only if the predecessor is not empty if(len(object.getActiveObjectQueue())>0):
if(len(giver.getActiveObjectQueue())>0):
#activate only if the caller carries Part #activate only if the caller carries Part
if(giver.getActiveObjectQueue()[0].type=='Part'): if(object.getActiveObjectQueue()[0].type=='Part'):
#update the predecessorIndex #update giver
self.predecessorIndex=i self.giver=object
return len(activeObjectQueue)==1 and giver.haveToDispose(self) return len(activeObjectQueue)==1 and object.haveToDispose(self)
i=i+1
return False 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
...@@ -191,7 +182,7 @@ class Assembly(CoreObject): ...@@ -191,7 +182,7 @@ class Assembly(CoreObject):
self.waitToDispose=False self.waitToDispose=False
return activeEntity #the object does not wait to dispose now return activeEntity #the object does not wait to dispose now
#gets an entity from the predecessor #gets an entity from the giver
#it may handle both Parts and Frames #it may handle both Parts and Frames
def getEntity(self, type): def getEntity(self, type):
activeObject=self.getActiveObject() activeObject=self.getActiveObject()
...@@ -202,11 +193,11 @@ class Assembly(CoreObject): ...@@ -202,11 +193,11 @@ class Assembly(CoreObject):
activeEntity=giverObjectQueue[0] activeEntity=giverObjectQueue[0]
if(type=="Part"): if(type=="Part"):
activeObjectQueue[0].getFrameQueue().append(activeEntity) #get the part from the predecessor and append it to the frame! activeObjectQueue[0].getFrameQueue().append(activeEntity) #get the part from the giver and append it to the frame!
giverObject.removeEntity() #remove the part from the previews object giverObject.removeEntity() #remove the part from the previews object
self.outputTrace(activeEntity.name, "got into "+ self.objName) self.outputTrace(activeEntity.name, "got into "+ self.objName)
elif(type=="Frame"): elif(type=="Frame"):
activeObjectQueue.append(giverObjectQueue[0]) #get the frame from the predecessor activeObjectQueue.append(giverObjectQueue[0]) #get the frame from the giver
giverObject.removeEntity() #remove the frame from the previews object giverObject.removeEntity() #remove the frame from the previews object
self.outputTrace(activeEntity.name, "got into "+ self.objName) self.outputTrace(activeEntity.name, "got into "+ self.objName)
self.nameLastEntityEntered=activeEntity.name self.nameLastEntityEntered=activeEntity.name
......
...@@ -36,6 +36,7 @@ from CoreObject import CoreObject ...@@ -36,6 +36,7 @@ from CoreObject import CoreObject
class Conveyer(CoreObject): class Conveyer(CoreObject):
def __init__(self, id, name,length,speed): def __init__(self, id, name,length,speed):
CoreObject.__init__(self)
self.id=id self.id=id
self.objName=name self.objName=name
self.type="Conveyer" self.type="Conveyer"
...@@ -61,6 +62,7 @@ class Conveyer(CoreObject): ...@@ -61,6 +62,7 @@ class Conveyer(CoreObject):
def initialize(self): def initialize(self):
Process.__init__(self) Process.__init__(self)
CoreObject.initialize(self)
self.Res=Resource(capacity=infinity) self.Res=Resource(capacity=infinity)
self.Up=True #Boolean that shows if the object is in failure ("Down") or not ("up") self.Up=True #Boolean that shows if the object is in failure ("Down") or not ("up")
......
...@@ -41,8 +41,6 @@ class CoreObject(Process): ...@@ -41,8 +41,6 @@ class CoreObject(Process):
def initialize(self): def initialize(self):
# Process.__init__(self) # Process.__init__(self)
self.predecessorIndex=0 #holds the index of the predecessor from which the Machine will take an entity next
self.successorIndex=0 #holds the index of the successor where the Machine will dispose an entity next
self.Up=True #Boolean that shows if the machine is in failure ("Down") or not ("up") self.Up=True #Boolean that shows if the machine is in failure ("Down") or not ("up")
self.currentEntity=None self.currentEntity=None
# ============================== total times =============================================== # ============================== total times ===============================================
...@@ -111,8 +109,7 @@ class CoreObject(Process): ...@@ -111,8 +109,7 @@ class CoreObject(Process):
pass pass
return activeEntity return activeEntity
# ================================== gets an entity from the ==================================== # ================================== gets an entity from the giver ====================================
# ===================== predecessor that the predecessor index points to ========================
def getEntity(self): def getEntity(self):
# get giver object, its queue, and sort the entities according to this object priorities # get giver object, its queue, and sort the entities according to this object priorities
giverObject=self.getGiverObject() giverObject=self.getGiverObject()
...@@ -177,7 +174,7 @@ class CoreObject(Process): ...@@ -177,7 +174,7 @@ class CoreObject(Process):
return len(activeObjectQueue)>0 return len(activeObjectQueue)>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 possible giver waiting for it
def canAcceptAndIsRequested(self): def canAcceptAndIsRequested(self):
pass pass
...@@ -207,9 +204,8 @@ class CoreObject(Process): ...@@ -207,9 +204,8 @@ class CoreObject(Process):
# =================== get the giver object in a getEntity transaction. ========================= # =================== get the giver object in a getEntity transaction. =========================
def getGiverObject(self): def getGiverObject(self):
if self.type=='Queue':# return self.giver
return self.giver
return self.previous[self.predecessorIndex]
# ============== get the giver object queue in a getEntity transaction. ======================== # ============== get the giver object queue in a getEntity transaction. ========================
def getGiverObjectQueue(self): def getGiverObjectQueue(self):
...@@ -217,9 +213,7 @@ class CoreObject(Process): ...@@ -217,9 +213,7 @@ class CoreObject(Process):
# ============== get the receiver object in a removeEntity transaction. ======================= # ============== get the receiver object in a removeEntity transaction. =======================
def getReceiverObject(self): def getReceiverObject(self):
if self.type=='Queue': return self.receiver
return self.receiver
return self.next[self.successorIndex]
# ========== get the receiver object queue in a removeEntity transaction. ====================== # ========== get the receiver object queue in a removeEntity transaction. ======================
def getReceiverObjectQueue(self): def getReceiverObjectQueue(self):
......
...@@ -39,6 +39,7 @@ class Dismantle(CoreObject): ...@@ -39,6 +39,7 @@ class Dismantle(CoreObject):
#initialize the object #initialize the object
def __init__(self, id, name, distribution='Fixed', mean=1, stdev=0.1, min=0, max=5): def __init__(self, id, name, distribution='Fixed', mean=1, stdev=0.1, min=0, max=5):
CoreObject.__init__(self)
self.id=id self.id=id
self.objName=name self.objName=name
self.type="Dismantle" #String that shows the type of object self.type="Dismantle" #String that shows the type of object
...@@ -61,8 +62,6 @@ class Dismantle(CoreObject): ...@@ -61,8 +62,6 @@ class Dismantle(CoreObject):
self.Waiting=[] self.Waiting=[]
self.Working=[] self.Working=[]
self.Blockage=[] self.Blockage=[]
self.predecessorIndex=0 #holds the index of the predecessor from which the Dismantle will take an entity next
self.successorIndex=0 #holds the index of the successor where the Dismantle will dispose an entity next
# ============================== variable that is used for the loading of machines ============= # ============================== variable that is used for the loading of machines =============
self.exitAssignedToReceiver = False # by default the objects are not blocked self.exitAssignedToReceiver = False # by default the objects are not blocked
...@@ -73,6 +72,7 @@ class Dismantle(CoreObject): ...@@ -73,6 +72,7 @@ class Dismantle(CoreObject):
def initialize(self): def initialize(self):
Process.__init__(self) Process.__init__(self)
CoreObject.initialize(self)
self.waitToDispose=False #flag that shows if the object waits to dispose an entity self.waitToDispose=False #flag that shows if the object waits to dispose an entity
self.waitToDisposePart=False #flag that shows if the object waits to dispose a part self.waitToDisposePart=False #flag that shows if the object waits to dispose a part
self.waitToDisposeFrame=False #flag that shows if the object waits to dispose a frame self.waitToDisposeFrame=False #flag that shows if the object waits to dispose a frame
...@@ -108,14 +108,11 @@ class Dismantle(CoreObject): ...@@ -108,14 +108,11 @@ class Dismantle(CoreObject):
self.Res.activeQ=[] self.Res.activeQ=[]
self.Res.waitQ=[] self.Res.waitQ=[]
self.predecessorIndex=0 #holds the index of the predecessor from which the Dismantle will take an entity next
self.successorIndex=0 #holds the index of the successor where the Dismantle will dispose an entity next
def run(self): def run(self):
while 1: while 1:
yield waituntil, self, self.canAcceptAndIsRequested #wait until the Assembly can accept a frame yield waituntil, self, self.canAcceptAndIsRequested #wait until the Assembly can accept a frame
#and one "frame" predecessor requests it #and one "frame" giver requests it
self.getEntity() #get the Frame with the parts self.getEntity() #get the Frame with the parts
self.timeLastEntityEntered=now() self.timeLastEntityEntered=now()
...@@ -169,7 +166,7 @@ class Dismantle(CoreObject): ...@@ -169,7 +166,7 @@ class Dismantle(CoreObject):
def isEmpty(self): def isEmpty(self):
return len(self.getActiveObjectQueue())==0 return len(self.getActiveObjectQueue())==0
#gets a frame from the predecessor that the predecessor index points to #gets a frame from the giver
def getEntity(self): def getEntity(self):
activeEntity=CoreObject.getEntity(self) #run the default method activeEntity=CoreObject.getEntity(self) #run the default method
activeObjectQueue=self.getActiveObjectQueue() activeObjectQueue=self.getActiveObjectQueue()
......
...@@ -98,16 +98,13 @@ class Exit(CoreObject): ...@@ -98,16 +98,13 @@ class Exit(CoreObject):
object=activeObject.previous[0] object=activeObject.previous[0]
return object.haveToDispose(self) return object.haveToDispose(self)
isRequested=False # dummy variable used to check if any of the predecessors has something to deliver isRequested=False # dummy variable used to check if any of the possible givers has something to deliver
i=0 # check if any of the possible givers has something to deliver
# check if any of the predecessors has something to deliver # if yes, then return true and update the giver
# if yes, then return true and the predecessorIndex equal to the
# index of the predecessor in the previous lists
for object in self.previous: for object in self.previous:
if(object.haveToDispose(activeObject)): if(object.haveToDispose(activeObject)):
isRequested=True isRequested=True
self.predecessorIndex=i self.giver=object
i+=1
return isRequested return isRequested
# ======================================================================= # =======================================================================
# gets an entity from the predecessor # gets an entity from the predecessor
......
...@@ -78,8 +78,8 @@ def moveExcess(argumentDict={}): ...@@ -78,8 +78,8 @@ def moveExcess(argumentDict={}):
consumption=int(argumentDict.get('consumption', 1)) consumption=int(argumentDict.get('consumption', 1))
if giver and receiver: if giver and receiver:
if len(giver.getActiveObjectQueue())>safetyStock: if len(giver.getActiveObjectQueue())>safetyStock:
giver.next=[receiver] giver.receiver=receiver
receiver.previous=[giver] receiver.giver=giver
for i in range(consumption): for i in range(consumption):
receiver.getEntity() receiver.getEntity()
giver.next=[] giver.next=[]
......
...@@ -44,10 +44,7 @@ class Machine(CoreObject): ...@@ -44,10 +44,7 @@ class Machine(CoreObject):
failureDistribution='No', MTTF=0, MTTR=0, availability=0, repairman='None'): failureDistribution='No', MTTF=0, MTTR=0, availability=0, repairman='None'):
# Process.__init__(self) # Process.__init__(self)
CoreObject.__init__(self) CoreObject.__init__(self)
# used for the routing of the entities # hold the id, name, and type of the Machine instance
self.predecessorIndex=0 #holds the index of the predecessor from which the Machine will take an entity next
self.successorIndex=0 #holds the index of the successor where the Machine will dispose an entity next
# hold the id, name, and type of the Machine instance
self.id=id self.id=id
self.objName=name self.objName=name
self.type="Machine" #String that shows the type of object self.type="Machine" #String that shows the type of object
...@@ -67,16 +64,7 @@ class Machine(CoreObject): ...@@ -67,16 +64,7 @@ class Machine(CoreObject):
self.MTTF=MTTF self.MTTF=MTTF
self.MTTR=MTTR self.MTTR=MTTR
self.availability=availability self.availability=availability
# # lists that hold the previous and next objects in the flow
# self.next=[] #list with the next objects in the flow
# self.previous=[] #list with the previous objects in the flow
# self.nextIds=[] #list with the ids of the next objects in the flow
# self.previousIds=[] #list with the ids of the previous objects in the flow
# # lists to hold statistics of multiple runs
# self.Failure=[]
# self.Working=[]
# self.Blockage=[]
# self.Waiting=[]
# ======================================================================= # =======================================================================
# initialize the Machine object # initialize the Machine object
...@@ -240,7 +228,7 @@ class Machine(CoreObject): ...@@ -240,7 +228,7 @@ class Machine(CoreObject):
# ======================================================================= # =======================================================================
# checks if the Machine can accept an entity and there is an entity in # checks if the Machine can accept an entity and there is an entity in
# some predecessor waiting for it # some predecessor waiting for it
# also updates the predecessorIndex to the one that is to be taken # also updates the giver to the one that is to be taken
# ======================================================================= # =======================================================================
def canAcceptAndIsRequested(self): def canAcceptAndIsRequested(self):
# get active and giver objects # get active and giver objects
...@@ -248,7 +236,7 @@ class Machine(CoreObject): ...@@ -248,7 +236,7 @@ class Machine(CoreObject):
activeObjectQueue=self.getActiveObjectQueue() activeObjectQueue=self.getActiveObjectQueue()
giverObject=self.getGiverObject() giverObject=self.getGiverObject()
# if we have only one predecessor just check if there is a place, # if we have only one possible giver just check if there is a place,
# the machine is up and the predecessor has an entity to dispose # the machine is up and the predecessor has an entity to dispose
# this is done to achieve better (cpu) processing time # this is done to achieve better (cpu) processing time
if(len(activeObject.previous)==1): if(len(activeObject.previous)==1):
...@@ -259,8 +247,7 @@ class Machine(CoreObject): ...@@ -259,8 +247,7 @@ class Machine(CoreObject):
isRequested=False # is requested is dummyVariable checking if it is requested to accept an item isRequested=False # is requested is dummyVariable checking if it is requested to accept an item
maxTimeWaiting=0 # dummy variable counting the time a predecessor is blocked maxTimeWaiting=0 # dummy variable counting the time a predecessor is blocked
# loop through the predecessors to see which have to dispose and which is the one blocked for longer # loop through the possible givers to see which have to dispose and which is the one blocked for longer
i=0 # index used to set the predecessorIndex to the giver waiting the most
for object in activeObject.previous: for object in activeObject.previous:
if(object.haveToDispose(activeObject)): if(object.haveToDispose(activeObject)):
isRequested=True # if the predecessor objects have entities to dispose of isRequested=True # if the predecessor objects have entities to dispose of
...@@ -271,9 +258,9 @@ class Machine(CoreObject): ...@@ -271,9 +258,9 @@ class Machine(CoreObject):
#if more than one predecessor have to dispose take the part from the one that is blocked longer #if more than one predecessor have to dispose take the part from the one that is blocked longer
if(timeWaiting>=maxTimeWaiting): if(timeWaiting>=maxTimeWaiting):
activeObject.predecessorIndex=i # the object to deliver the Entity to the activeObject is set to the ith member of the previous list activeObject.giver=object # the object to deliver the Entity to the activeObject is set to the ith member of the previous list
maxTimeWaiting=timeWaiting maxTimeWaiting=timeWaiting
i+=1 # in the next loops, check the other predecessors in the previous list # in the next loops, check the other predecessors in the previous list
return activeObject.Up and len(activeObjectQueue)<activeObject.capacity and isRequested return activeObject.Up and len(activeObjectQueue)<activeObject.capacity and isRequested
# ======================================================================= # =======================================================================
...@@ -324,8 +311,8 @@ class Machine(CoreObject): ...@@ -324,8 +311,8 @@ class Machine(CoreObject):
timeWaiting=now()-object.timeLastEntityLeft # the time it has been waiting is updated and stored in dummy variable timeWaiting timeWaiting=now()-object.timeLastEntityLeft # the time it has been waiting is updated and stored in dummy variable timeWaiting
if(timeWaiting>maxTimeWaiting or maxTimeWaiting==0):# if the timeWaiting is the maximum among the ones of the successors if(timeWaiting>maxTimeWaiting or maxTimeWaiting==0):# if the timeWaiting is the maximum among the ones of the successors
maxTimeWaiting=timeWaiting maxTimeWaiting=timeWaiting
activeObject.successorIndex=i # set the successorIndex equal to the index of the longest waiting successor activeObject.receiver=object # set the receiver as the longest waiting possible receiver
i+=1 # in the next loops, check the other successors in the previous list # in the next loops, check the other successors in the previous list
return len(activeObjectQueue)>0 and activeObject.waitToDispose\ return len(activeObjectQueue)>0 and activeObject.waitToDispose\
and activeObject.Up and (thecaller is receiverObject) and activeObject.Up and (thecaller is receiverObject)
......
...@@ -438,8 +438,8 @@ class OperatedMachine(Machine): ...@@ -438,8 +438,8 @@ class OperatedMachine(Machine):
# ======================================================================= # =======================================================================
# checks if the Machine can accept an entity and there is an entity in # checks if the Machine can accept an entity and there is an entity in
# some predecessor waiting for it # some possible giver waiting for it
# also updates the predecessorIndex to the one that is to be taken # also updates the giver to the one that is to be taken
# ======================================================================= # =======================================================================
def canAcceptAndIsRequested(self): def canAcceptAndIsRequested(self):
# get active and giver objects # get active and giver objects
...@@ -480,21 +480,19 @@ class OperatedMachine(Machine): ...@@ -480,21 +480,19 @@ class OperatedMachine(Machine):
isRequested=False # is requested is dummyVariable checking if it is requested to accept an item isRequested=False # is requested is dummyVariable checking if it is requested to accept an item
maxTimeWaiting=0 # dummy variable counting the time a predecessor is blocked maxTimeWaiting=0 # dummy variable counting the time a predecessor is blocked
# loop through the predecessors to see which have to dispose and which is the one blocked for longer # loop through the possible givers to see which have to dispose and which is the one blocked for longer # index used to set the predecessorIndex to the giver waiting the most
i=0 # index used to set the predecessorIndex to the giver waiting the most
for object in activeObject.previous: for object in activeObject.previous:
if(object.haveToDispose(activeObject)):# and not object.exitIsAssigned()): if(object.haveToDispose(activeObject)):# and not object.exitIsAssigned()):
isRequested=True # if the predecessor objects have entities to dispose of isRequested=True # if the possible giver have entities to dispose of
if(object.downTimeInTryingToReleaseCurrentEntity>0):# and the predecessor has been down while trying to give away the Entity if(object.downTimeInTryingToReleaseCurrentEntity>0):# and the possible giver has been down while trying to give away the Entity
timeWaiting=now()-object.timeLastFailureEnded # the timeWaiting dummy variable counts the time end of the last failure of the giver object timeWaiting=now()-object.timeLastFailureEnded # the timeWaiting dummy variable counts the time end of the last failure of the giver object
else: else:
timeWaiting=now()-object.timeLastEntityEnded # in any other case, it holds the time since the end of the Entity processing timeWaiting=now()-object.timeLastEntityEnded # in any other case, it holds the time since the end of the Entity processing
#if more than one predecessor have to dispose take the part from the one that is blocked longer #if more than one possible givers have to dispose take the part from the one that is blocked longer
if(timeWaiting>=maxTimeWaiting): if(timeWaiting>=maxTimeWaiting):
activeObject.predecessorIndex=i # the object to deliver the Entity to the activeObject is set to the ith member of the previous list activeObject.giver=object # set the giver
maxTimeWaiting=timeWaiting maxTimeWaiting=timeWaiting
i+=1 # in the next loops, check the other predecessors in the previous list
if (activeObject.operatorPool!='None' and any(type=='Load' for type in activeObject.multOperationTypeList)): if (activeObject.operatorPool!='None' and any(type=='Load' for type in activeObject.multOperationTypeList)):
if activeObject.operatorPool.checkIfResourceIsAvailable()\ if activeObject.operatorPool.checkIfResourceIsAvailable()\
......
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