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):
self.Working=[]
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 =============
self.exitAssignedToReceiver = False # by default the objects are not blocked
# when the entities have to be loaded to operatedMachines
......@@ -104,15 +102,12 @@ class Assembly(CoreObject):
self.Res=Resource(1)
self.Res.activeQ=[]
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):
while 1:
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
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):
#checks if the Assembly can accept an entity and there is a Frame waiting for it
def canAcceptAndIsRequested(self):
activeObjectQueue=self.getActiveObjectQueue()
i=0
#loop through the predecessors
for giver in self.previous:
#activate only if the predecessor is not empty
if(len(giver.getActiveObjectQueue())>0):
#loop through the possible givers
for object in self.previous:
#activate only if the possible giver is not empty
if(len(object.getActiveObjectQueue())>0):
#activate only if the caller carries Frame
if(giver.getActiveObjectQueue()[0].type=='Frame'):
#update the predecessorIndex
self.predecessorIndex=i
return len(activeObjectQueue)==0 and giver.haveToDispose(self)
i=i+1
if(object.getActiveObjectQueue()[0].type=='Frame'):
#update the giver
self.giver=object
return len(activeObjectQueue)==0 and object.haveToDispose(self)
return False
#checks if the Assembly can accept an entity and there is a Frame waiting for it
def isRequestedFromPart(self):
activeObjectQueue=self.getActiveObjectQueue()
i=0
#loop through the predecessors
for giver in self.previous:
#activate only if the predecessor is not empty
if(len(giver.getActiveObjectQueue())>0):
#loop through the possible givers
for object in self.previous:
#activate only if the possible giver is not empty
if(len(object.getActiveObjectQueue())>0):
#activate only if the caller carries Part
if(giver.getActiveObjectQueue()[0].type=='Part'):
#update the predecessorIndex
self.predecessorIndex=i
return len(activeObjectQueue)==1 and giver.haveToDispose(self)
i=i+1
if(object.getActiveObjectQueue()[0].type=='Part'):
#update giver
self.giver=object
return len(activeObjectQueue)==1 and object.haveToDispose(self)
return False
#checks if the Assembly can dispose an entity to the following object
......@@ -191,7 +182,7 @@ class Assembly(CoreObject):
self.waitToDispose=False
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
def getEntity(self, type):
activeObject=self.getActiveObject()
......@@ -202,11 +193,11 @@ class Assembly(CoreObject):
activeEntity=giverObjectQueue[0]
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
self.outputTrace(activeEntity.name, "got into "+ self.objName)
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
self.outputTrace(activeEntity.name, "got into "+ self.objName)
self.nameLastEntityEntered=activeEntity.name
......
......@@ -36,6 +36,7 @@ from CoreObject import CoreObject
class Conveyer(CoreObject):
def __init__(self, id, name,length,speed):
CoreObject.__init__(self)
self.id=id
self.objName=name
self.type="Conveyer"
......@@ -61,6 +62,7 @@ class Conveyer(CoreObject):
def initialize(self):
Process.__init__(self)
CoreObject.initialize(self)
self.Res=Resource(capacity=infinity)
self.Up=True #Boolean that shows if the object is in failure ("Down") or not ("up")
......
......@@ -41,8 +41,6 @@ class CoreObject(Process):
def initialize(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.currentEntity=None
# ============================== total times ===============================================
......@@ -111,8 +109,7 @@ class CoreObject(Process):
pass
return activeEntity
# ================================== gets an entity from the ====================================
# ===================== predecessor that the predecessor index points to ========================
# ================================== gets an entity from the giver ====================================
def getEntity(self):
# get giver object, its queue, and sort the entities according to this object priorities
giverObject=self.getGiverObject()
......@@ -177,7 +174,7 @@ class CoreObject(Process):
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):
pass
......@@ -207,9 +204,8 @@ class CoreObject(Process):
# =================== get the giver object in a getEntity transaction. =========================
def getGiverObject(self):
if self.type=='Queue':#
return self.giver
return self.previous[self.predecessorIndex]
return self.giver
# ============== get the giver object queue in a getEntity transaction. ========================
def getGiverObjectQueue(self):
......@@ -217,9 +213,7 @@ class CoreObject(Process):
# ============== get the receiver object in a removeEntity transaction. =======================
def getReceiverObject(self):
if self.type=='Queue':
return self.receiver
return self.next[self.successorIndex]
return self.receiver
# ========== get the receiver object queue in a removeEntity transaction. ======================
def getReceiverObjectQueue(self):
......
......@@ -39,6 +39,7 @@ class Dismantle(CoreObject):
#initialize the object
def __init__(self, id, name, distribution='Fixed', mean=1, stdev=0.1, min=0, max=5):
CoreObject.__init__(self)
self.id=id
self.objName=name
self.type="Dismantle" #String that shows the type of object
......@@ -61,8 +62,6 @@ class Dismantle(CoreObject):
self.Waiting=[]
self.Working=[]
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 =============
self.exitAssignedToReceiver = False # by default the objects are not blocked
......@@ -73,6 +72,7 @@ class Dismantle(CoreObject):
def initialize(self):
Process.__init__(self)
CoreObject.initialize(self)
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.waitToDisposeFrame=False #flag that shows if the object waits to dispose a frame
......@@ -108,14 +108,11 @@ class Dismantle(CoreObject):
self.Res.activeQ=[]
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):
while 1:
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.timeLastEntityEntered=now()
......@@ -169,7 +166,7 @@ class Dismantle(CoreObject):
def isEmpty(self):
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):
activeEntity=CoreObject.getEntity(self) #run the default method
activeObjectQueue=self.getActiveObjectQueue()
......
......@@ -98,16 +98,13 @@ class Exit(CoreObject):
object=activeObject.previous[0]
return object.haveToDispose(self)
isRequested=False # dummy variable used to check if any of the predecessors has something to deliver
i=0
# check if any of the predecessors has something to deliver
# if yes, then return true and the predecessorIndex equal to the
# index of the predecessor in the previous lists
isRequested=False # dummy variable used to check if any of the possible givers has something to deliver
# check if any of the possible givers has something to deliver
# if yes, then return true and update the giver
for object in self.previous:
if(object.haveToDispose(activeObject)):
isRequested=True
self.predecessorIndex=i
i+=1
self.giver=object
return isRequested
# =======================================================================
# gets an entity from the predecessor
......
......@@ -78,8 +78,8 @@ def moveExcess(argumentDict={}):
consumption=int(argumentDict.get('consumption', 1))
if giver and receiver:
if len(giver.getActiveObjectQueue())>safetyStock:
giver.next=[receiver]
receiver.previous=[giver]
giver.receiver=receiver
receiver.giver=giver
for i in range(consumption):
receiver.getEntity()
giver.next=[]
......
......@@ -44,10 +44,7 @@ class Machine(CoreObject):
failureDistribution='No', MTTF=0, MTTR=0, availability=0, repairman='None'):
# Process.__init__(self)
CoreObject.__init__(self)
# used for the routing of the entities
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
# hold the id, name, and type of the Machine instance
self.id=id
self.objName=name
self.type="Machine" #String that shows the type of object
......@@ -67,16 +64,7 @@ class Machine(CoreObject):
self.MTTF=MTTF
self.MTTR=MTTR
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
......@@ -240,7 +228,7 @@ class Machine(CoreObject):
# =======================================================================
# checks if the Machine can accept an entity and there is an entity in
# 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):
# get active and giver objects
......@@ -248,7 +236,7 @@ class Machine(CoreObject):
activeObjectQueue=self.getActiveObjectQueue()
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
# this is done to achieve better (cpu) processing time
if(len(activeObject.previous)==1):
......@@ -259,8 +247,7 @@ class Machine(CoreObject):
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
# loop through the predecessors 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
# loop through the possible givers to see which have to dispose and which is the one blocked for longer
for object in activeObject.previous:
if(object.haveToDispose(activeObject)):
isRequested=True # if the predecessor objects have entities to dispose of
......@@ -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(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
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
# =======================================================================
......@@ -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
if(timeWaiting>maxTimeWaiting or maxTimeWaiting==0):# if the timeWaiting is the maximum among the ones of the successors
maxTimeWaiting=timeWaiting
activeObject.successorIndex=i # set the successorIndex equal to the index of the longest waiting successor
i+=1 # in the next loops, check the other successors in the previous list
activeObject.receiver=object # set the receiver as the longest waiting possible receiver
# in the next loops, check the other successors in the previous list
return len(activeObjectQueue)>0 and activeObject.waitToDispose\
and activeObject.Up and (thecaller is receiverObject)
......
......@@ -438,8 +438,8 @@ class OperatedMachine(Machine):
# =======================================================================
# checks if the Machine can accept an entity and there is an entity in
# some predecessor waiting for it
# also updates the predecessorIndex to the one that is to be taken
# some possible giver waiting for it
# also updates the giver to the one that is to be taken
# =======================================================================
def canAcceptAndIsRequested(self):
# get active and giver objects
......@@ -480,21 +480,19 @@ class OperatedMachine(Machine):
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
# loop through the predecessors 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
# 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
for object in activeObject.previous:
if(object.haveToDispose(activeObject)):# and not object.exitIsAssigned()):
isRequested=True # if the predecessor objects have entities to dispose of
if(object.downTimeInTryingToReleaseCurrentEntity>0):# and the predecessor has been down while trying to give away the Entity
isRequested=True # if the possible giver have entities to dispose of
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
else:
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):
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
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.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