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

MachineJobShop and QueueJobShop brought in a more generic way. Still there is...

MachineJobShop and QueueJobShop brought in a more generic way. Still there is one issue. If job route may be more than one candidates it will go wrong
parent d3fe6b05
......@@ -62,6 +62,9 @@ class CoreObject(Process):
# ============================== waiting flag ==============================================
self.waitToDispose=False #shows if the object waits to dispose an entity
# ============================== the below are currently used in Jobshop =======================
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
# ======================== the main process of the core object =================================
# ================ this is dummy, every object must have its own implementation ================
......
......@@ -560,8 +560,7 @@ def createWIP():
G.JobList.append(J)
G.WipList.append(J)
G.EntityList.append(J)
# ===========================================================================
# sets the WIP in the corresponding stations
......@@ -575,10 +574,17 @@ def setWIP():
if obj.id==objectId:
object=obj # find the object in the 'G.ObjList
object.getActiveObjectQueue().append(entity) # append the entity to its Queue
entity.remainingRoute.pop(0) # remove data from the remaining route.
object.receiver=findObjectById(entity.remainingRoute[1][0])
entity.remainingRoute.pop(0) # remove data from the remaining route.
entity.schedule.append([object,now()]) #append the time to schedule so that it can be read in the result
entity.currentStation=object # update the current station of the entity
def findObjectById(id):
from Globals import G
for obj in G.ObjList:
if obj.id==id:
return obj
# ===========================================================================
# the main script that is ran
# ===========================================================================
......
......@@ -279,7 +279,10 @@ class Machine(CoreObject):
# checks if the machine down or it can dispose the object
# =======================================================================
def ifCanDisposeOrHaveFailure(self):
return self.Up==False or self.getReceiverObject().canAccept(self) or len(self.getActiveObjectQueue())==0
try:
return self.Up==False or self.getReceiverObject().canAccept(self) or len(self.getActiveObjectQueue())==0
except AttributeError:
return False
# =======================================================================
# removes an entity from the Machine
......
......@@ -33,13 +33,18 @@ from Machine import Machine
#the MachineJobShop object
class MachineJobShop(Machine):
def initialize(self):
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):
avtiveEntity=Machine.getEntity(self) #run the default code
self.procTime=avtiveEntity.remainingRoute[0][1] #read the processing time from the entity
self.nextStationId=avtiveEntity.remainingRoute[1][0] #read the next station id
avtiveEntity.remainingRoute.pop(0) #remove data from the remaining route of the entity
return avtiveEntity
activeEntity=Machine.getEntity(self) #run the default code
self.procTime=activeEntity.remainingRoute[0][1] #read the processing time from the entity
self.receiver=self.findObjectById(activeEntity.remainingRoute[1][0]) #read the next station
activeEntity.remainingRoute.pop(0) #remove data from the remaining route of the entity
return activeEntity
#calculates the processing time
def calculateProcessingTime(self):
......@@ -58,20 +63,40 @@ class MachineJobShop(Machine):
#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):
if self.getGiverObject():
return self.getGiverObject().haveToDispose(self) and len(self.getActiveObjectQueue())<self.capacity\
and self.Up
else:
return False
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):
if callerObject!=None:
#check it the object that called the method holds an Entity that requests for current object
if self.getReceiverObject()==callerObject:
return len(self.getActiveObjectQueue())>0 and self.waitToDispose and self.Up #return according to the state of the machine
return False
# get active object and its queue
activeObject=self.getActiveObject()
activeObjectQueue=self.getActiveObjectQueue()
#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.
......@@ -79,27 +104,26 @@ class MachineJobShop(Machine):
#if there are successors use default method
if len(self.next)>0:
return Machine.getReceiverObject(self)
if len(self.getActiveObjectQueue())>0:
from Globals import G
receiverObjectId=self.getActiveObjectQueue()[0].remainingRoute[0][0]
#loop through the objects to to assign the next station to the one that has the id
for obj in G.ObjList:
if obj.id==receiverObjectId:
return obj
else:
return None
#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
def findObjectById(self, id):
from Globals import G
#loop through the objects to see if there is one that holds an Entity requesting for current object
for obj in G.ObjList:
if len(obj.getActiveObjectQueue())>0 and (obj!=self):
activeEntity=obj.getActiveObjectQueue()[0]
if activeEntity.remainingRoute[0][0]==self.id:
return obj
return None
\ No newline at end of file
if obj.id==id:
return obj
\ No newline at end of file
......@@ -34,6 +34,11 @@ from Queue import Queue
#the MachineJobShop object
class QueueJobShop(Queue):
def initialize(self):
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
def canAccept(self, callerObject=None):
......@@ -47,54 +52,72 @@ class QueueJobShop(Queue):
#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):
if self.getGiverObject():
return self.getGiverObject().haveToDispose(self) and len(self.getActiveObjectQueue())<self.capacity
else:
return False
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
#checks if the Machine can dispose an entity. Returns True only to the potential receiver
def haveToDispose(self, callerObject=None):
if callerObject!=None:
#check it the object that called the method holds an Entity that requests for current object
if self.getReceiverObject()==callerObject:
return len(self.getActiveObjectQueue())>0 #return according to the state of the machine
return False
# get active object and its queue
activeObject=self.getActiveObject()
activeObjectQueue=self.getActiveObjectQueue()
#return True if the Queue has Entities and the caller is the receiver
return len(activeObjectQueue)>0 and (callerObject is self.receiver)
#gets an entity from the predecessor that the predecessor index points to
def getEntity(self):
activeEntity=Queue.getEntity(self)
self.nextStationId=activeEntity.remainingRoute[1][0] #read the next station id
self.receiver=self.findObjectById(activeEntity.remainingRoute[1][0]) #read the next station
activeEntity.remainingRoute.pop(0) #remove data from the remaining route of the entity
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 Queue.getGiverObject(self)
return Machine.getGiverObject(self)
#else if there is a giver return it
elif self.giver:
return self.giver
return None
def findObjectById(self, id):
from Globals import G
#loop through the objects to see if there is one that holds an Entity requesting for current object
for obj in G.ObjList:
if len(obj.getActiveObjectQueue())>0 and (obj!=self) and now()!=0:
activeEntity=obj.getActiveObjectQueue()[0]
if activeEntity.remainingRoute[0][0]==self.id:
return obj
return None
#get the receiver object in a removeEntity transaction.
def getReceiverObject(self):
#if there are successors use default method
if len(self.next)>0:
return Queue.getReceiverObject(self)
if len(self.getActiveObjectQueue())>0:
from Globals import G
receiverObjectId=self.getActiveObjectQueue()[0].remainingRoute[0][0]
#loop through the objects to to assign the next station to the one that has the id
for obj in G.ObjList:
if obj.id==receiverObjectId:
return obj
else:
return None
if obj.id==id:
return obj
\ 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