Commit 1eb1a536 authored by Ioannis Papagiannopoulos's avatar Ioannis Papagiannopoulos Committed by Jérome Perrin

modified Machine and OperatorPreemptive

parent 99327cbd
......@@ -92,7 +92,7 @@ class ConditionalBuffer(QueuePreemptive):
and activeObject.checkCondition()
# =======================================================================
# check weather the condition is True
# check whether the condition is True
# =======================================================================
def checkCondition(self):
activeObject = self.getActiveObject()
......
......@@ -90,7 +90,7 @@ class Machine(CoreObject):
self.currentOperator=None
# define if load/setup/removal/processing are performed by the operator
self.operationType=operationType
# boolean to check weather the machine is being operated
# boolean to check whether the machine is being operated
self.toBeOperated = False
# define the load times
self.loadDistType=loadDistribution
......@@ -162,6 +162,8 @@ class Machine(CoreObject):
self.loadOperatorWaitTimeCurrentEntity = 0 # holds the time that the machine waits for operator to load the it
self.loadTimeCurrentEntity = 0 # holds the time to load the current entity
self.setupTimeCurrentEntity = 0 # holds the time to setup the machine before processing the current entity
# TODO: check whether the requestingEntity variable can be used in OperatorPreemptive
self.requestingEntity=None
# =======================================================================
# the main process of the machine
......@@ -214,6 +216,8 @@ class Machine(CoreObject):
# wait until the Broker has finished processing
yield waituntil, self, self.broker.brokerIsSet
# TODO: reset the requestinEntity before receiving the currentEntity
self.requestingEntity=None
# get the entity
# TODO: if there was loading time then we must solve the problem of getting an entity
# from an unidentified giver or not getting an entity at all as the giver
......@@ -467,11 +471,23 @@ class Machine(CoreObject):
if(len(activeObject.previous)==1):
if (activeObject.operatorPool!='None' and (any(type=='Load' for type in activeObject.multOperationTypeList)\
or any(type=='Setup' for type in activeObject.multOperationTypeList))):
if activeObject.operatorPool.checkIfResourceIsAvailable()\
and activeObject.Up and len(activeObjectQueue)<activeObject.capacity\
and giverObject.haveToDispose(activeObject) and not giverObject.exitIsAssigned():
activeObject.giver.assignExit()
return True
if giverObject.haveToDispose(activeObject):
# TODO:
# check whether this entity is the one to be hand in
# to be used in operatorPreemptive
activeObject.requestingEntity=giverObject.getActiveObjectQueue()[0]
# TODO:
# update the objects requesting the operator
activeObject.operatorPool.requestingObject=activeObject.giver
# TODOD:
# update the last object calling the operatorPool
activeObject.operatorPool.receivingObject=activeObject
if activeObject.operatorPool.checkIfResourceIsAvailable()\
and activeObject.Up and len(activeObjectQueue)<activeObject.capacity\
and not giverObject.exitIsAssigned():
activeObject.giver.assignExit()
return True
else:
return False
else:
......@@ -508,11 +524,23 @@ class Machine(CoreObject):
if (activeObject.operatorPool!='None' and (any(type=='Load' for type in activeObject.multOperationTypeList)\
or any(type=='Setup' for type in activeObject.multOperationTypeList))):
if activeObject.operatorPool.checkIfResourceIsAvailable()\
and activeObject.Up and len(activeObjectQueue)<activeObject.capacity\
and isRequested and not activeObject.giver.exitIsAssigned():
activeObject.giver.assignExit()
return True
if isRequested:
# TODO:
# check whether this entity is the one to be hand in
# to be used in operatorPreemptive
activeObject.requestingEntity=activeObject.giver.getActiveObjectQueue()[0]
# TODO:
# update the object requesting the operator
activeObject.operatorPool.requestingObject=activeObject.giver
# TODOD:
# update the last object calling the operatorPool
activeObject.operatorPool.receivingObject=activeObject
if activeObject.operatorPool.checkIfResourceIsAvailable()\
and activeObject.Up and len(activeObjectQueue)<activeObject.capacity\
and isRequested and not activeObject.giver.exitIsAssigned():
activeObject.giver.assignExit()
return True
else:
return False
else:
......
......@@ -39,7 +39,7 @@ class ObjectResource(object):
self.totalWaitingTime=0 #holds the total waiting time
self.timeLastOperationStarted=0 #holds the time that the last repair was started
self.Res=Resource(self.capacity)
# variable that checks weather the resource is already initialized
# variable that checks whether the resource is already initialized
self.initialized = True
# =======================================================================
......
......@@ -52,6 +52,11 @@ class OperatorPool(ObjectResource):
self.coreObjects=[]
# holds the object/Machine that currently handles the operator pool
self.currentObject='None'
# TODO: variables to be used by OperatorPreemptive
# TODO: the object requesting the OperatorPreemptive
self.requestingObject=None
# TODO: the last object calling the OperatorPool
self.receivingObject=None
# check if an operatorsList is 'None'
if operatorsList=='None' or (operatorsList!='None' and len(operatorsList)==0):
......@@ -89,28 +94,28 @@ class OperatorPool(ObjectResource):
# =======================================================================
# checks if there are operators available
# =======================================================================
def checkIfResourceIsAvailable(self, callerObject=None):
# maxTimeWaiting = 0
# for operator in self.operators:
# for machine in operator.coreObjects:
# timeWaiting = now()-machine.broker.timeWaitForOperatorStarted
# if (timeWaiting>=maxTimeWaiting):
# maxTimeWaiting=timeWaiting
def checkIfResourceIsAvailable(self):
# TODO: to discuss with George if using a callerObject is the proper way to inform the OperatorPreemptive
# about the object that is requesting to know about its availability
thecaller=callerObject
# requestingEntity=thecaller.getActiveObjectQueue()[0]
# requestedOperator=requestingEntity.manager
# isAvailable=requestedOperator.checkIfResourceIsAvailable(callerObject)
return any(operator.checkIfResourceIsAvailable(callerObject=thecaller)==True for operator in self.operators)
# TODO: first check if there is any free operator, then check if the requesting entity is critical and preempt
# if callerOjbect is None then the checkIfResourceIsAvailable performs the default behaviour
# so initially it checks whether there is a free operator
isAvailable = any(operator.checkIfResourceIsAvailable()==True for operator in self.operators)
if isAvailable:
return True
# if there is no free operator, then check if any of the operators can preempt
return any(operator.checkIfResourceIsAvailable(callerObject=self)==True for operator in self.operators)
# =======================================================================
# find the first available operator and return it
# =======================================================================
def findAvailableOperator(self): # may need to implement different sorting of the operators
return next(x for x in self.operators if x.checkIfResourceIsAvailable())
# find the free operator if any
freeOperator = next(x for x in self.operators if x.checkIfResourceIsAvailable())
if freeOperator:
return freeOperator
# if there is no free operator, return the operator that can preempt
return next(x for x in self.operators if x.checkIfResourceIsAvailable(callerObject=self))
# =======================================================================
# returns the resource
......
......@@ -49,25 +49,37 @@ class OperatorPreemptive(Operator):
activeResourceQueue = activeResource.getResourceQueue()
# find out which station is requesting the operator?
thecaller=callerObject
# if the operator is occupied return True
# TODO: if the callerObject is None then
# perform then default behaviour. Used to find free operators
if thecaller==None:
# added for testing
len(self.Res.activeQ)<self.capacity
# Otherwise check the operator has a reason to preempt the machine he is currently working on
# TODO: update the objects requesting the operator
requestingObject=thecaller.requestingObject
# TODO: update the last object calling the operatorPool
receivingObject=thecaller.receivingObject
# TODO: the entity that is requesting the operator
requestingEntity=receivingObject.requestingEntity
# if the operator is not occupied return True
if len(activeResourceQueue)==0:
return True
# read the station currently operated by the operator
# TODO: the victim of the operator is the Broker of the Machine. Modify to preempt the machine and not the broker
victim=activeResourceQueue[0]
victim=activeResourceQueue[0].victim
# read its activeQ
victimQueue=victim.getActiveObjectQueue()
# if the callerObject is None then return False as the operator is occupied
if thecaller==None:
return False
thecallerQueue=thecaller.getActiveObjectQueue()
requestingObjectQueue=requestingObject.getActiveObjectQueue()
receivingObjectQueue=receivingObject.getActiveObjectQueue()
#if the receiver is not empty and the caller is not empty
if len(victimQueue)>0 and len(theCallerQueue):
if len(victimQueue) and len(requestingObjectQueue):
try:
#if the Entity to be forwarded to the station currently processed by the operator is critical
if thecallerQueue[0].isCritical:
if requestingObjectQueue[0].isCritical:
#if the receiver does not hold an Entity that is also critical
if not victimQueue[0].isCritical:
if not victimQueue[0].isCritical and not receivingObjectQueue[0].isCritical:
# then the receiver must be preemptied before it can receive any entities from the calerObject
victim.shouldPreempt=True
victim.preempt()
......
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