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

clean-up in job-shop objects

parent 06ebfb2c
......@@ -249,7 +249,7 @@ class Machine(CoreObject):
# 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)):
if(object.haveToDispose(activeObject) and object.receiver==self):
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
timeWaiting=now()-object.timeLastFailureEnded # the timeWaiting dummy variable counts the time end of the last failure of the giver object
......
......@@ -34,9 +34,11 @@ from Machine import Machine
class MachineJobShop(Machine):
def initialize(self):
from Globals import G
self.previous=G.ObjList
self.next=G.ObjList
Machine.initialize(self)
self.giver=None #the CoreObject that the activeObject will take an Entity from
self.receiver=None #the CoreObject that the activeObject will give an Entity to
#gets an entity from the predecessor that the predecessor index points to
def getEntity(self):
......@@ -61,35 +63,7 @@ class MachineJobShop(Machine):
if activeEntity.remainingRoute[0][0]==self.id:
return len(self.getActiveObjectQueue())<self.capacity #return according to the state of the Queue
return False
#checks if the Queue 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
def canAcceptAndIsRequested(self):
# get active object and its queue
activeObject=self.getActiveObject()
activeObjectQueue=self.getActiveObjectQueue()
# dummy variables that help prioritize the objects requesting to give objects to the Machine (activeObject)
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
from Globals import G
# loop through the objects 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 G.ObjList:
if(object.haveToDispose(activeObject) and object.receiver==self): #if the caller is the receiver and it has to dispose
isRequested=True # if the predecessor objects have entities to dispose of
if(object.downTimeInTryingToReleaseCurrentEntity>0):# and the object 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 have to dispose take the part from the one that is blocked longer
if(timeWaiting>=maxTimeWaiting):
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
return activeObject.Up and len(activeObjectQueue)<activeObject.capacity and isRequested
#checks if the Machine can dispose an entity. Returns True only to the potential receiver
def haveToDispose(self, callerObject=None):
# get active object and its queue
......@@ -98,26 +72,6 @@ class MachineJobShop(Machine):
#return True if the Machine in the state of disposing and the caller is the receiver
return len(activeObjectQueue)>0 and activeObject.waitToDispose\
and activeObject.Up and (callerObject is self.receiver)
#get the receiver object in a removeEntity transaction.
def getReceiverObject(self):
#if there are successors use default method
if len(self.next)>0:
return Machine.getReceiverObject(self)
#else if there is a receiver return it
elif self.receiver:
return self.receiver
return None
#get the giver object in a getEntity transaction.
def getGiverObject(self):
#if there are predecessors use default method
if len(self.previous)>0:
return Machine.getGiverObject(self)
#else if there is a giver return it
elif self.giver:
return self.giver
return None
\ No newline at end of file
......@@ -176,7 +176,7 @@ class Queue(CoreObject):
#loop through the predecessors to see which have to dispose and which is the one blocked for longer # loop through all the predecessors
for object in activeObject.previous:
if(object.haveToDispose(activeObject)): # if they have something to dispose off
if(object.haveToDispose(activeObject) and object.receiver==self): # if they have something to dispose off
isRequested=True # then the Queue is requested to handle the entity
if(object.downTimeInTryingToReleaseCurrentEntity>0):# if the predecessor has failed wile waiting
timeWaiting=now()-object.timeLastFailureEnded # then update according the timeWaiting to be compared with the ones
......
......@@ -35,9 +35,10 @@ from Queue import Queue
class QueueJobShop(Queue):
def initialize(self):
from Globals import G
self.previous=G.ObjList
self.next=G.ObjList
Queue.initialize(self)
self.giver=None #the CoreObject that the activeObject will take an Entity from
self.receiver=None #the CoreObject that the activeObject will give an Entity to
#checks if the Queue can accept an entity
#it checks also the next station of the Entity and returns true only if the active object is the next station
......@@ -48,36 +49,7 @@ class QueueJobShop(Queue):
activeEntity=callerObject.getActiveObjectQueue()[0]
if activeEntity.remainingRoute[0][0]==self.id:
return len(self.getActiveObjectQueue())<self.capacity #return according to the state of the Queue
return False
#checks if the Queue 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
def canAcceptAndIsRequested(self):
# get active object and its queue
activeObject=self.getActiveObject()
activeObjectQueue=self.getActiveObjectQueue()
# dummy variables that help prioritize the objects requesting to give objects to the Machine (activeObject)
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
from Globals import G
# loop through the objects 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 G.ObjList:
if(object.haveToDispose(activeObject) and object.receiver==self): #if the caller is the receiver and it has to dispose
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
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(timeWaiting>=maxTimeWaiting):
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
return activeObject.Up and len(activeObjectQueue)<activeObject.capacity and isRequested
return False
#checks if the Machine can dispose an entity. Returns True only to the potential receiver
def haveToDispose(self, callerObject=None):
......@@ -96,25 +68,7 @@ class QueueJobShop(Queue):
return activeEntity
#get the receiver object in a removeEntity transaction.
def getReceiverObject(self):
#if there are successors use default method
if len(self.next)>0:
return Machine.getReceiverObject(self)
#else if there is a receiver return it
elif self.receiver:
return self.receiver
return None
#get the giver object in a getEntity transaction.
def getGiverObject(self):
#if there are predecessors use default method
if len(self.previous)>0:
return Machine.getGiverObject(self)
#else if there is a giver return it
elif self.giver:
return self.giver
return None
\ No newline at end of file
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