Commit b899a133 authored by Georgios Dagkakis's avatar Georgios Dagkakis Committed by Sebastien Robin

Dismantle code cleaned with the use of new supplementary methods

parent 5884aa88
...@@ -62,7 +62,8 @@ class Assembly(CoreObject): ...@@ -62,7 +62,8 @@ class Assembly(CoreObject):
self.Working=[] self.Working=[]
self.Blockage=[] self.Blockage=[]
self.predecessorIndex=0 #holds the index of the predecessor from which the Queue will take an entity next 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 initialize(self): def initialize(self):
...@@ -191,6 +192,7 @@ class Assembly(CoreObject): ...@@ -191,6 +192,7 @@ class Assembly(CoreObject):
activeObject=self.getActiveObject() activeObject=self.getActiveObject()
activeObjectQueue=self.getActiveObjectQueue() activeObjectQueue=self.getActiveObjectQueue()
giverObject=self.getGiverObject() giverObject=self.getGiverObject()
giverObject.sortEntities() #sort the Entities of the giver according to the scheduling rule if applied
giverObjectQueue=self.getGiverObjectQueue() giverObjectQueue=self.getGiverObjectQueue()
activeEntity=giverObjectQueue[0] activeEntity=giverObjectQueue[0]
......
...@@ -61,6 +61,9 @@ class Dismantle(CoreObject): ...@@ -61,6 +61,9 @@ 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
def initialize(self): def initialize(self):
Process.__init__(self) Process.__init__(self)
...@@ -106,9 +109,7 @@ class Dismantle(CoreObject): ...@@ -106,9 +109,7 @@ class Dismantle(CoreObject):
#and one "frame" predecessor requests it #and one "frame" predecessor requests it
self.getEntity() #get the Frame with the parts self.getEntity() #get the Frame with the parts
self.timeLastEntityEntered=now() self.timeLastEntityEntered=now()
self.outputTrace(self.Res.activeQ[0].name, "got into "+ self.objName)
startWorkingTime=now() startWorkingTime=now()
yield hold,self,self.rng.generateNumber() #hold for the time the dismantle operation is carried yield hold,self,self.rng.generateNumber() #hold for the time the dismantle operation is carried
self.totalWorkingTime+=now()-startWorkingTime self.totalWorkingTime+=now()-startWorkingTime
...@@ -129,16 +130,16 @@ class Dismantle(CoreObject): ...@@ -129,16 +130,16 @@ 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(self) return len(self.getActiveObjectQueue())==0 and self.getGiverObject().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):
return len(self.Res.activeQ)==0 return len(self.getActiveObjectQueue())==0
#defines where parts and frames go after they leave the object #defines where parts and frames go after they leave the object
def definePartFrameRouting(self, np, nf): def definePartFrameRouting(self, successorPartList=[], successorFrameList=[]):
self.nextPart=np self.nextPart=successorPartList
self.nextFrame=nf self.nextFrame=successorFrameList
#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, callerObject=None): def haveToDispose(self, callerObject=None):
...@@ -147,28 +148,37 @@ class Dismantle(CoreObject): ...@@ -147,28 +148,37 @@ class Dismantle(CoreObject):
#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:
return len(self.Res.activeQ)>1 and self.waitToDisposePart return len(self.getActiveObjectQueue())>1 and self.waitToDisposePart
elif thecaller in self.nextFrame: elif thecaller in self.nextFrame:
return len(self.Res.activeQ)==1 and self.waitToDisposeFrame return len(self.getActiveObjectQueue())==1 and self.waitToDisposeFrame
#checks if the frame is emptied #checks if the frame is emptied
def frameIsEmpty(self): def frameIsEmpty(self):
return len(self.Res.activeQ)==1 return len(self.getActiveObjectQueue())==1
#checks if Dismantle is emptied #checks if Dismantle is emptied
def isEmpty(self): def isEmpty(self):
return len(self.Res.activeQ)==0 return len(self.getActiveObjectQueue())==0
#gets a frame from the predecessor that the predecessor index points to #gets a frame from the predecessor that the predecessor index points to
def getEntity(self): def getEntity(self):
self.Res.activeQ.append(self.previous[0].Res.activeQ[0]) #get the frame from the predecessor activeObjectQueue=self.getActiveObjectQueue()
self.previous[0].removeEntity() giverObject=self.getGiverObject()
giverObject.sortEntities() #sort the Entities of the giver according to the scheduling rule if applied
giverObjectQueue=self.getGiverObjectQueue()
activeEntity=giverObjectQueue[0]
activeObjectQueue.append(activeEntity) #get the frame from the predecessor
giverObject.removeEntity()
#append also the parts in the res so that they can be popped #append also the parts in the res so that they can be popped
for i in range(self.Res.activeQ[0].capacity): for part in activeEntity.getFrameQueue():
self.Res.activeQ.append(self.Res.activeQ[0].Res.activeQ[i]) activeObjectQueue.append(part)
self.Res.activeQ[0].Res.activeQ=[] activeEntity.getFrameQueue=[] #empty the frame
self.Res.activeQ.append(self.Res.activeQ[0]) #move the frame to the end of the internal queue since we want the frame to be disposed first
self.Res.activeQ.pop(0) activeObjectQueue.append(activeEntity)
activeObjectQueue.pop(0)
self.outputTrace(activeEntity.name, "got into "+ self.objName)
#removes an entity from the Dismantle #removes an entity from the Dismantle
def removeEntity(self): def removeEntity(self):
......
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