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

JobShop objects code cleaned with the use of new supplementary methods. Also,...

JobShop objects code cleaned with the use of new supplementary methods. Also, a bug in main script fixed. Old version expected only integer processing times for jobs. The test results for topologies 18 to 20 had to be fixed too (e.g. instead of 1 it is 1.0 in the result now)
parent fdd0be2b
...@@ -35,30 +35,33 @@ class ExitJobShop(Exit): ...@@ -35,30 +35,33 @@ class ExitJobShop(Exit):
#checks if the Exit can accept an entity and there is an entity waiting for it #checks if the Exit can accept an entity and there is an entity waiting for it
def canAcceptAndIsRequested(self): def canAcceptAndIsRequested(self):
from Globals import G if self.getGiverObject():
#loop through the objects to see if there is one that holds an Entity requesting for current object return self.getGiverObject().haveToDispose(self)
for obj in G.ObjList: else:
if len(obj.Res.activeQ)>0 and now()!=0:
activeEntity=obj.Res.activeQ[0]
if activeEntity.remainingRoute[0][0]==self.id:
self.previousStation=obj
return self.previousStation.haveToDispose(self)
return False return False
#gets an entity from the previous station #gets an entity from the previous station
def getEntity(self): def getEntity(self):
activeObject=self.getActiveObject() activeObject=self.getActiveObject()
activeObjectQueue=self.getActiveObjectQueue() activeObjectQueue=self.getActiveObjectQueue()
giverObject=self.previousStation giverObject=self.getGiverObject()
giverObjectQueue=giverObject.Res.activeQ giverObjectQueue=self.getGiverObjectQueue()
activeEntity=giverObjectQueue[0] activeEntity=giverObjectQueue[0]
name=activeEntity.name #get the name of the entity for the trace name=activeEntity.name #get the name of the entity for the trace
self.totalLifespan+=now()-activeEntity.startTime #Add the entity's lifespan to the total one. self.totalLifespan+=now()-activeEntity.startTime #Add the entity's lifespan to the total one.
giverObject.removeEntity() #remove the entity from the previous object giverObject.removeEntity() #remove the entity from the previous object
self.outputTrace(name) self.outputTrace(name)
activeEntity.schedule.append([activeObject.id,now()]) #append the time to schedule so that it can be read in the result activeEntity.schedule.append([activeObject.id,now()]) #append the time to schedule so that it can be read in the result
#get the giver object in a getEntity transaction.
def getGiverObject(self):
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 now()!=0:
activeEntity=obj.getActiveObjectQueue()[0]
if activeEntity.remainingRoute[0][0]==self.id:
return obj
return None
\ No newline at end of file
...@@ -306,7 +306,7 @@ def createObjects(): ...@@ -306,7 +306,7 @@ def createObjects():
nextId=routeElement.get('stationId', 'not found') nextId=routeElement.get('stationId', 'not found')
processingTime=routeElement.get('processingTime', 'not found') processingTime=routeElement.get('processingTime', 'not found')
distributionType=processingTime.get('distributionType', 'not found') distributionType=processingTime.get('distributionType', 'not found')
mean=int(processingTime.get('mean', 'not found')) mean=float(processingTime.get('mean', 'not found'))
route[stepNumber]=[nextId, mean] route[stepNumber]=[nextId, mean]
J=Job(id, name, route, priority=priority, dueDate=dueDate, orderDate=orderDate) J=Job(id, name, route, priority=priority, dueDate=dueDate, orderDate=orderDate)
G.JobList.append(J) G.JobList.append(J)
......
...@@ -119,7 +119,7 @@ class Machine(CoreObject): ...@@ -119,7 +119,7 @@ class Machine(CoreObject):
self.getEntity() #get the entity from the predecessor self.getEntity() #get the entity from the predecessor
self.outputTrace("got into "+self.objName) self.outputTrace("got into "+self.objName)
self.currentEntity=self.Res.activeQ[0] #entity is the current entity processed in Machine self.currentEntity=self.getActiveObjectQueue()[0] #entity is the current entity processed in Machine
self.timeLastEntityEntered=now() #this holds the last time that an entity got into Machine self.timeLastEntityEntered=now() #this holds the last time that an entity got into Machine
self.nameLastEntityEntered=self.currentEntity.name #this holds the name of the last entity that got into Machine self.nameLastEntityEntered=self.currentEntity.name #this holds the name of the last entity that got into Machine
timeEntered=now() timeEntered=now()
......
...@@ -36,19 +36,14 @@ class MachineJobShop(Machine): ...@@ -36,19 +36,14 @@ class MachineJobShop(Machine):
#gets an entity from the predecessor that the predecessor index points to #gets an entity from the predecessor that the predecessor index points to
def getEntity(self): def getEntity(self):
Machine.getEntity(self) #run the default code Machine.getEntity(self) #run the default code
avtiveEntity=self.Res.activeQ[0] avtiveEntity=self.getActiveObjectQueue()[0]
self.procTime=avtiveEntity.remainingRoute[0][1] #read the processing time from the entity self.procTime=avtiveEntity.remainingRoute[0][1] #read the processing time from the entity
self.nextStationId=avtiveEntity.remainingRoute[1][0] #read the next station id self.nextStationId=avtiveEntity.remainingRoute[1][0] #read the next station id
avtiveEntity.remainingRoute.pop(0) #remove data from the remaining route of the entity avtiveEntity.remainingRoute.pop(0) #remove data from the remaining route of the entity
from Globals import G
#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==self.nextStationId:
self.nextStation=obj
#checks if the machine down or it can dispose the object #checks if the machine down or it can dispose the object
def ifCanDisposeOrHaveFailure(self): def ifCanDisposeOrHaveFailure(self):
return self.Up==False or self.nextStation.canAccept(self) or len(self.Res.activeQ)==0 return self.Up==False or self.getReceiverObject().canAccept(self) or len(self.getActiveObjectQueue())==0
#calculates the processing time #calculates the processing time
def calculateProcessingTime(self): def calculateProcessingTime(self):
...@@ -58,10 +53,21 @@ class MachineJobShop(Machine): ...@@ -58,10 +53,21 @@ class MachineJobShop(Machine):
def haveToDispose(self, callerObject=None): def haveToDispose(self, callerObject=None):
if callerObject!=None: if callerObject!=None:
#check it the object that called the method holds an Entity that requests for current object #check it the object that called the method holds an Entity that requests for current object
if self.Res.activeQ[0].remainingRoute[0][0]==callerObject.id: #if self.getActiveObjectQueue()[0].remainingRoute[0][0]==callerObject.id:
return len(self.Res.activeQ)>0 and self.waitToDispose and self.Up #return according to the state of the machine 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 return False
#get the receiver object in a removeEntity transaction.
def 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
\ No newline at end of file
...@@ -35,48 +35,50 @@ from Queue import Queue ...@@ -35,48 +35,50 @@ from Queue import Queue
class QueueJobShop(Queue): class QueueJobShop(Queue):
#checks if the Queue can accept an entity #checks if the Queue can accept an entity
#it checks also who called it and returns TRUE only to the object that will give the 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): def canAccept(self, callerObject=None):
if callerObject!=None: if callerObject!=None:
#check it the caller object holds an Entity that requests for current object #check it the caller object holds an Entity that requests for current object
if len(callerObject.Res.activeQ)>0: if len(callerObject.getActiveObjectQueue())>0:
activeEntity=callerObject.Res.activeQ[0] activeEntity=callerObject.getActiveObjectQueue()[0]
if activeEntity.remainingRoute[0][0]==self.id: if activeEntity.remainingRoute[0][0]==self.id:
return len(self.Res.activeQ)<self.capacity #return according to the state of the Queue return len(self.getActiveObjectQueue())<self.capacity #return according to the state of the Queue
return False return False
#checks if the Queue can accept an entity and there is an entity in some predecessor waiting for it #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 #also updates the predecessorIndex to the one that is to be taken
def canAcceptAndIsRequested(self): def canAcceptAndIsRequested(self):
from Globals import G if self.getGiverObject():
#loop through the objects to see if there is one that holds an Entity requesting for current object return self.getGiverObject().haveToDispose(self) and len(self.getActiveObjectQueue())<self.capacity
for obj in G.ObjList: else:
if len(obj.Res.activeQ)>0 and now()!=0:
activeEntity=obj.Res.activeQ[0]
if activeEntity.remainingRoute[0][0]==self.id:
self.previousStation=obj
return len(self.Res.activeQ)<self.capacity and self.previousStation.haveToDispose(self)
return False return False
#gets an entity from the predecessor that the predecessor index points to #gets an entity from the predecessor that the predecessor index points to
def getEntity(self): def getEntity(self):
activeObject=self.getActiveObject() activeObject=self.getActiveObject()
activeObjectQueue=self.getActiveObjectQueue() activeObjectQueue=self.getActiveObjectQueue()
giverObject=self.previousStation giverObject=self.getGiverObject()
giverObjectQueue=giverObject.Res.activeQ giverObjectQueue=self.getGiverObjectQueue()
activeEntity=giverObjectQueue[0] activeEntity=giverObjectQueue[0]
activeObjectQueue.append(giverObjectQueue[0]) #get the entity from the previous object
self.Res.activeQ.append(giverObjectQueue[0]) #get the entity from the previous object
#and put it in front of the activeQ #and put it in front of the activeQ
self.previousStation.removeEntity() #remove the entity from the previous object giverObject.removeEntity() #remove the entity from the previous object
activeEntity.remainingRoute[0][0]="" #remove data from the remaining route. activeEntity.remainingRoute[0][0]="" #remove data from the remaining route.
#This is needed so that the Queue will not request again for the Entity #This is needed so that the Queue will not request again for the Entity
self.outputTrace(activeEntity.name, "got into "+activeObject.objName) self.outputTrace(activeEntity.name, "got into "+activeObject.objName)
activeEntity.schedule.append([activeObject.id,now()]) #append the time to schedule so that it can be read in the result activeEntity.schedule.append([activeObject.id,now()]) #append the time to schedule so that it can be read in the result
#get the giver object in a getEntity transaction.
def getGiverObject(self):
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 now()!=0:
activeEntity=obj.getActiveObjectQueue()[0]
if activeEntity.remainingRoute[0][0]==self.id:
return obj
return None
\ No newline at end of file
...@@ -5,8 +5,8 @@ ...@@ -5,8 +5,8 @@
"id": "E1", "id": "E1",
"results": { "results": {
"throughput": 1, "throughput": 1,
"takt_time": 6, "takt_time": 6.0,
"lifespan": 6 "lifespan": 6.0
} }
}, },
{ {
...@@ -23,23 +23,23 @@ ...@@ -23,23 +23,23 @@
"stationId": "Q1" "stationId": "Q1"
}, },
"3": { "3": {
"entranceTime": 1, "entranceTime": 1.0,
"stationId": "M3" "stationId": "M3"
}, },
"2": { "2": {
"entranceTime": 1, "entranceTime": 1.0,
"stationId": "Q3" "stationId": "Q3"
}, },
"5": { "5": {
"entranceTime": 4, "entranceTime": 4.0,
"stationId": "M2" "stationId": "M2"
}, },
"4": { "4": {
"entranceTime": 4, "entranceTime": 4.0,
"stationId": "Q2" "stationId": "Q2"
}, },
"6": { "6": {
"entranceTime": 6, "entranceTime": 6.0,
"stationId": "E1" "stationId": "E1"
} }
} }
......
...@@ -5,8 +5,8 @@ ...@@ -5,8 +5,8 @@
"id": "E1", "id": "E1",
"results": { "results": {
"throughput": 2, "throughput": 2,
"takt_time": 6, "takt_time": 6.5,
"lifespan": 9 "lifespan": 9.5
} }
}, },
{ {
...@@ -23,23 +23,23 @@ ...@@ -23,23 +23,23 @@
"stationId": "Q1" "stationId": "Q1"
}, },
"3": { "3": {
"entranceTime": 1, "entranceTime": 1.0,
"stationId": "M3" "stationId": "M3"
}, },
"2": { "2": {
"entranceTime": 1, "entranceTime": 1.0,
"stationId": "Q3" "stationId": "Q3"
}, },
"5": { "5": {
"entranceTime": 4, "entranceTime": 4.0,
"stationId": "M2" "stationId": "M2"
}, },
"4": { "4": {
"entranceTime": 4, "entranceTime": 4.0,
"stationId": "Q2" "stationId": "Q2"
}, },
"6": { "6": {
"entranceTime": 6, "entranceTime": 6.0,
"stationId": "E1" "stationId": "E1"
} }
} }
...@@ -59,23 +59,23 @@ ...@@ -59,23 +59,23 @@
"stationId": "Q2" "stationId": "Q2"
}, },
"3": { "3": {
"entranceTime": 4, "entranceTime": 4.0,
"stationId": "M3" "stationId": "M3"
}, },
"2": { "2": {
"entranceTime": 3, "entranceTime": 3.0,
"stationId": "Q3" "stationId": "Q3"
}, },
"5": { "5": {
"entranceTime": 6, "entranceTime": 6.0,
"stationId": "M2" "stationId": "M2"
}, },
"4": { "4": {
"entranceTime": 5, "entranceTime": 5.0,
"stationId": "Q2" "stationId": "Q2"
}, },
"6": { "6": {
"entranceTime": 13, "entranceTime": 13.0,
"stationId": "E1" "stationId": "E1"
} }
} }
......
...@@ -5,8 +5,8 @@ ...@@ -5,8 +5,8 @@
"id": "E1", "id": "E1",
"results": { "results": {
"throughput": 4, "throughput": 4,
"takt_time": 5, "takt_time": 5.75,
"lifespan": 14 "lifespan": 14.75
} }
}, },
{ {
...@@ -23,23 +23,23 @@ ...@@ -23,23 +23,23 @@
"stationId": "Q1" "stationId": "Q1"
}, },
"3": { "3": {
"entranceTime": 1, "entranceTime": 1.0,
"stationId": "M3" "stationId": "M3"
}, },
"2": { "2": {
"entranceTime": 1, "entranceTime": 1.0,
"stationId": "Q3" "stationId": "Q3"
}, },
"5": { "5": {
"entranceTime": 19, "entranceTime": 19.0,
"stationId": "M2" "stationId": "M2"
}, },
"4": { "4": {
"entranceTime": 4, "entranceTime": 4.0,
"stationId": "Q2" "stationId": "Q2"
}, },
"6": { "6": {
"entranceTime": 23, "entranceTime": 23.0,
"stationId": "E1" "stationId": "E1"
} }
} }
...@@ -51,7 +51,7 @@ ...@@ -51,7 +51,7 @@
"results": { "results": {
"schedule": { "schedule": {
"1": { "1": {
"entranceTime": 2, "entranceTime": 2.0,
"stationId": "M2" "stationId": "M2"
}, },
"0": { "0": {
...@@ -59,23 +59,23 @@ ...@@ -59,23 +59,23 @@
"stationId": "Q2" "stationId": "Q2"
}, },
"3": { "3": {
"entranceTime": 5, "entranceTime": 5.0,
"stationId": "M3" "stationId": "M3"
}, },
"2": { "2": {
"entranceTime": 5, "entranceTime": 5.0,
"stationId": "Q3" "stationId": "Q3"
}, },
"5": { "5": {
"entranceTime": 12, "entranceTime": 12.0,
"stationId": "M2" "stationId": "M2"
}, },
"4": { "4": {
"entranceTime": 6, "entranceTime": 6.0,
"stationId": "Q2" "stationId": "Q2"
}, },
"6": { "6": {
"entranceTime": 19, "entranceTime": 19.0,
"stationId": "E1" "stationId": "E1"
} }
} }
...@@ -95,15 +95,15 @@ ...@@ -95,15 +95,15 @@
"stationId": "Q2" "stationId": "Q2"
}, },
"3": { "3": {
"entranceTime": 4, "entranceTime": 4.0,
"stationId": "M3" "stationId": "M3"
}, },
"2": { "2": {
"entranceTime": 2, "entranceTime": 2.0,
"stationId": "Q3" "stationId": "Q3"
}, },
"4": { "4": {
"entranceTime": 5, "entranceTime": 5.0,
"stationId": "E1" "stationId": "E1"
} }
} }
...@@ -115,7 +115,7 @@ ...@@ -115,7 +115,7 @@
"results": { "results": {
"schedule": { "schedule": {
"1": { "1": {
"entranceTime": 5, "entranceTime": 5.0,
"stationId": "M2" "stationId": "M2"
}, },
"0": { "0": {
...@@ -123,7 +123,7 @@ ...@@ -123,7 +123,7 @@
"stationId": "Q2" "stationId": "Q2"
}, },
"2": { "2": {
"entranceTime": 12, "entranceTime": 12.0,
"stationId": "E1" "stationId": "E1"
} }
} }
......
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