Commit 99327cbd authored by Ioannis Papagiannopoulos's avatar Ioannis Papagiannopoulos Committed by Jérome Perrin

redundant code removed from MouldAssembly

parent 0f9e90fc
...@@ -276,96 +276,4 @@ class MouldAssembly(MachinePreemptive): ...@@ -276,96 +276,4 @@ class MouldAssembly(MachinePreemptive):
except: except:
# added for testing # added for testing
print 'the mould to be created', component.get('name', 'not found'), 'cannot be created', 'time', now() print 'the mould to be created', component.get('name', 'not found'), 'cannot be created', 'time', now()
# ======================================================================= \ No newline at end of file
# check if the assemble can accept an entity
# returns true if it is empty
# =======================================================================
def canAccept(self, callerObject=None):
activeObject=self.getActiveObject()
activeObjectQueue=activeObject.getActiveObjectQueue()
thecaller=callerObject
if thecaller!=None:
#check it the caller object holds an Entity that requests for current object
if len(thecaller.getActiveObjectQueue())>0:
# TODO: make sure that the first entity of the callerObject is to be disposed
activeEntity=thecaller.getActiveObjectQueue()[0]
# if the machine's Id is in the list of the entity's next stations
if activeObject.id in activeEntity.remainingRoute[0].get('stationIdsList',[]):
#return according to the state of the Queue
# check if (if the machine is to be operated) there are available operators
if (activeObject.operatorPool!='None' and (any(type=='Load' for type in activeObject.multOperationTypeList)\
or any(type=='Setup' for type in activeObject.multOperationTypeList))):
return activeObject.operatorPool.checkIfResourceIsAvailable()\
and len(activeObject.getActiveObjectQueue())==0\
and activeObject.Up
else:
return len(activeObject.getActiveObjectQueue())==0\
and activeObject.Up
return False
# =======================================================================
# checks if the Machine can accept an entity and there is an entity in
# some predecessor waiting for it and updates the giver to the one that is to be taken
# The internal queue of the assembler must be empty
# and the parent order of the entities to be received must have
# the flag componentsReadyForAssembly set to True
# =======================================================================
def canAcceptAndIsRequested(self):
# get active and giver objects
activeObject=self.getActiveObject()
activeObjectQueue=self.getActiveObjectQueue()
giverObject=self.getGiverObject()
# if we have only one predecessor just check if the machine is empty,
# the machine is up and the predecessor has an entity to dispose
if(len(activeObject.previous)==1):
# if the machine has to compete for an Operator that loads the entities onto it
# check if the predecessor if blocked by an other Machine
# if not then the machine has to block the predecessor giverObject to avoid conflicts
# with other competing machines
if (activeObject.operatorPool!='None' and any(type=='Load' for type in activeObject.multOperationTypeList)):
if activeObject.operatorPool.checkIfResourceIsAvailable()\
and activeObject.Up\
and len(activeObjectQueue)==0\
and giverObject.haveToDispose(activeObject)\
and not giverObject.exitIsAssigned():
activeObject.giver.assignExit()
return True
else:
return False
# otherwise, use the default behaviour
else:
return activeObject.Up and len(activeObjectQueue)==0\
and giverObject.haveToDispose(activeObject)
# dummy variables that help prioritise the objects requesting to give objects to the Machine (activeObject)
isRequested=False # isRequested 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 possible givers to see which have to dispose and which is the one blocked for longer
for object in activeObject.previous:
# if the predecessor objects have entities to dispose of
if(object.haveToDispose(activeObject) and object.receiver==self):
isRequested=True
# and if the predecessor has been down while trying to give away the Entity
if(object.downTimeInTryingToReleaseCurrentEntity>0):
# the timeWaiting dummy variable counts the time end of the last failure of the giver object
timeWaiting=now()-object.timeLastFailureEnded
# in any other case, it holds the time since the end of the Entity processing
else:
timeWaiting=now()-object.timeLastEntityEnded
#if more than one predecessor have to dispose, take the part from the one that is blocked longer
if(timeWaiting>=maxTimeWaiting):
activeObject.giver=object
maxTimeWaiting=timeWaiting
if (activeObject.operatorPool!='None' and any(type=='Load' for type in activeObject.multOperationTypeList)):
if activeObject.operatorPool.checkIfResourceIsAvailable()\
and activeObject.Up\
and len(activeObjectQueue)==0\
and isRequested\
and not activeObject.giver.exitIsAssigned():
activeObject.giver.assignExit()
return True
else:
return False
else:
return activeObject.Up and len(activeObjectQueue)==0 and isRequested
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