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

first working versions of Machine/Queue preemptive. Test34 and 35 added and verified

parent e2575aac
......@@ -99,14 +99,11 @@ def setWIP(entityList):
object=entity.currentStation #identify the object
object.getActiveObjectQueue().append(entity) #append the entity to its Queue
entity.schedule.append([object,now()]) #append the time to schedule so that it can be read in the result
elif entity.type=='Job':
elif entity.type=='Job' or 'OrderComponent':
object=findObjectById(entity.remainingRoute[0][0]) # find the object in the 'G.ObjList
object.getActiveObjectQueue().append(entity) # append the entity to its Queue
object.receiver=findObjectById(entity.remainingRoute[1][0])
entity.remainingRoute.pop(0) # remove data from the remaining route.
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
entity.currentStation=object # update the current station of the entity
{
"_class": "Dream.Simulation",
"edges": {},
"general": {
"_class": "Dream.Configuration",
"numberOfReplications": "1",
"maxSimTime": "-1",
"trace": "Yes",
"confidenceLevel": "0.95"
},
"nodes": {
"M1": {
"_class": "Dream.MachineJobShop",
"id": "M1",
"name": "Machine1",
"processingTime": {
"distributionType": "Fixed",
"mean": "0.25"
},
"failures": {}
},
"M2": {
"_class": "Dream.MachinePreemptive",
"id": "M2",
"name": "Machine2",
"processingTime": {
"distributionType": "Fixed",
"mean": "1.5"
},
"failures": {},
"resetOnPreemption":"0"
},
"Q1": {
"_class": "Dream.QueueJobShop",
"id": "Q1",
"name": "Queue1",
"isDummy": "0",
"capacity": "-1",
"wip": [
{
"_class": "Dream.OrderComponent",
"id": "C1",
"name": "Component1",
"isCritical": "1",
"route": [
{
"stepNumber": "0",
"stationId": "Q1",
"processingTime": {
"distributionType": "Fixed",
"mean": "0"
}
},
{
"stepNumber": "1",
"stationId": "M1",
"processingTime": {
"distributionType": "Fixed",
"mean": "0.25"
}
},
{
"stepNumber": "2",
"stationId": "Q2",
"processingTime": {
"distributionType": "Fixed",
"mean": "0"
}
},
{
"stepNumber": "3",
"stationId": "M2",
"processingTime": {
"distributionType": "Fixed",
"mean": "1"
}
}
]
}
]
},
"Q2": {
"_class": "Dream.QueuePreemptive",
"id": "Q2",
"name": "Queue2",
"isDummy": "0",
"capacity": "-1",
"wip": [
{
"_class": "Dream.OrderComponent",
"id": "C2",
"name": "Component2",
"isCritical": "0",
"route": [
{
"stepNumber": "0",
"stationId": "Q2",
"processingTime": {
"distributionType": "Fixed",
"mean": "0"
}
},
{
"stepNumber": "1",
"stationId": "M2",
"processingTime": {
"distributionType": "Fixed",
"mean": "1"
}
}
]
}
]
},
"E1": {
"_class": "Dream.ExitJobShop",
"id": "E1",
"name": "Stock"
}
}
}
\ No newline at end of file
{
"_class": "Dream.Simulation",
"edges": {},
"general": {
"_class": "Dream.Configuration",
"numberOfReplications": "1",
"maxSimTime": "-1",
"trace": "Yes",
"confidenceLevel": "0.95"
},
"nodes": {
"M1": {
"_class": "Dream.MachineJobShop",
"id": "M1",
"name": "Machine1",
"processingTime": {
"distributionType": "Fixed",
"mean": "0.25"
},
"failures": {}
},
"M2": {
"_class": "Dream.MachinePreemptive",
"id": "M2",
"name": "Machine2",
"processingTime": {
"distributionType": "Fixed",
"mean": "1.5"
},
"failures": {},
"resetOnPreemption":"1"
},
"Q1": {
"_class": "Dream.QueueJobShop",
"id": "Q1",
"name": "Queue1",
"isDummy": "0",
"capacity": "-1",
"wip": [
{
"_class": "Dream.OrderComponent",
"id": "C1",
"name": "Component1",
"isCritical": "1",
"route": [
{
"stepNumber": "0",
"stationId": "Q1",
"processingTime": {
"distributionType": "Fixed",
"mean": "0"
}
},
{
"stepNumber": "1",
"stationId": "M1",
"processingTime": {
"distributionType": "Fixed",
"mean": "0.25"
}
},
{
"stepNumber": "2",
"stationId": "Q2",
"processingTime": {
"distributionType": "Fixed",
"mean": "0"
}
},
{
"stepNumber": "3",
"stationId": "M2",
"processingTime": {
"distributionType": "Fixed",
"mean": "1"
}
}
]
}
]
},
"Q2": {
"_class": "Dream.QueuePreemptive",
"id": "Q2",
"name": "Queue2",
"isDummy": "0",
"capacity": "-1",
"wip": [
{
"_class": "Dream.OrderComponent",
"id": "C2",
"name": "Component2",
"isCritical": "0",
"route": [
{
"stepNumber": "0",
"stationId": "Q2",
"processingTime": {
"distributionType": "Fixed",
"mean": "0"
}
},
{
"stepNumber": "1",
"stationId": "M2",
"processingTime": {
"distributionType": "Fixed",
"mean": "1"
}
}
]
}
]
},
"E1": {
"_class": "Dream.ExitJobShop",
"id": "E1",
"name": "Stock"
}
}
}
\ No newline at end of file
......@@ -84,7 +84,7 @@ from OperatedPoolBroker import Broker
from OperatedMachine import OperatedMachine
from BatchDecompositionStartTime import BatchDecompositionStartTime
from M3 import M3
from OrderComponent import OrderComponent
import ExcelHandler
import time
......@@ -756,6 +756,7 @@ def createWIP():
G.WipList=[]
G.EntityList=[]
G.PartList=[]
G.OrderComponentList=[]
json_data = G.JSONData
#Read the json data
......@@ -770,7 +771,60 @@ def createWIP():
except IndexError:
continue
if entityClass=='Dream.Job':
if entityClass=='Dream.OrderComponent':
id=entity.get('id', 'not found')
name=entity.get('name', 'not found')
priority=int(entity.get('priority', '0'))
dueDate=float(entity.get('dueDate', '0'))
orderDate=float(entity.get('orderDate', '0'))
isCritical=bool(int(entity.get('isCritical', '0')))
JSONRoute=entity.get('route', []) # dummy variable that holds the routes of the jobs
# the route from the JSON file
# is a sequence of dictionaries
route = [None for i in range(len(JSONRoute))] # variable that holds the argument used in the Job initiation
# hold None for each entry in the 'route' list
for routeentity in JSONRoute: # for each 'step' dictionary in the JSONRoute
stepNumber=int(routeentity.get('stepNumber', '0')) # get the stepNumber
nextId=routeentity.get('stationId', 'not found') # the stationId
processingTime=routeentity['processingTime'] # and the 'processingTime' dictionary
distributionType=processingTime.get('distributionType', 'not found')# and from that dictionary
# get the 'mean'
mean=float(processingTime.get('mean', 'not found'))
route[stepNumber]=[nextId, mean] # finally add the 'nextId' and 'mean'
# to the job route
# keep a reference of all extra properties passed to the job
extraPropertyDict = {}
for key, value in entity.items():
if key not in ('_class', 'id'):
extraPropertyDict[key] = value
#Below it is to assign an exit if it was not assigned in JSON
#have to talk about it with NEX
exitAssigned=False
for element in route:
elementId=element[0]
for obj in G.ObjList:
if obj.id==elementId and obj.type=='Exit':
exitAssigned=True
if not exitAssigned:
exitId=None
for obj in G.ObjList:
if obj.type=='Exit':
exitId=obj.id
break
if exitId:
route.append([exitId, 0])
# initiate the job
OC=OrderComponent(id, name, route, priority=priority, dueDate=dueDate,
orderDate=orderDate, extraPropertyDict=extraPropertyDict, isCritical=isCritical)
G.OrderComponentList.append(OC)
G.JobList.append(OC)
G.WipList.append(OC)
G.EntityList.append(OC)
elif entityClass=='Dream.Job':
id=entity.get('id', 'not found')
name=entity.get('name', 'not found')
priority=int(entity.get('priority', '0'))
......@@ -819,7 +873,9 @@ def createWIP():
orderDate=orderDate, extraPropertyDict=extraPropertyDict)
G.JobList.append(J)
G.WipList.append(J)
G.EntityList.append(J)
G.EntityList.append(J)
elif entityClass=='Dream.Part':
id=entity.get('id', 'not found')
name=entity.get('name', 'not found')
......
......@@ -115,12 +115,15 @@ class Machine(CoreObject):
# processingEndedFlag and exit loop,
# else (if interrupted()) set interruption flag to true (only if tinM==0),
# and recalculate the processing time left tinM,
# passivate while waiting for repair.
# passivate while waiting for repair.
yield hold,self,tinM # getting processed for remaining processing time tinM
if self.interrupted(): # if a failure occurs while processing the machine is interrupted.
self.interruptionActions() # execute interruption actions
# output to trace that the Machine (self.objName) got interrupted
self.outputTrace(self.getActiveObjectQueue()[0].name, "Interrupted at "+self.objName)
#self.interruptionActions() # execute interruption actions
# output to trace that the Machine (self.objName) got interrupted
try:
self.outputTrace(self.getActiveObjectQueue()[0].name, "Interrupted at "+self.objName)
except IndexError:
pass
# recalculate the processing time left tinM
tinM=tinM-(now()-timeRestartingProcessing)
if(tinM==0): # sometimes the failure may happen exactly at the time that the processing would finish
......@@ -150,16 +153,22 @@ class Machine(CoreObject):
#if during the interruption the object became empty continue
if (len(self.getActiveObjectQueue())==0 and self.shouldPreempt):
self.shouldPreempt=False
continue
self.totalWorkingTime+=now()-(self.timeLastEntityEntered)
continue
# output to trace that the processing in the Machine self.objName ended
self.outputTrace(self.getActiveObjectQueue()[0].name,"ended processing in "+self.objName)
try:
self.outputTrace(self.getActiveObjectQueue()[0].name,"ended processing in "+self.objName)
except IndexError:
pass
# set the variable that flags an Entity is ready to be disposed
self.waitToDispose=True
# update the total working time
self.totalWorkingTime+=self.totalProcessingTimeInCurrentEntity # the total processing time for this entity
# is what the distribution initially gave
# update the variables keeping track of Entity related attributes of the machine
self.timeLastEntityEnded=now() # this holds the time that the last entity ended processing in Machine
self.nameLastEntityEnded=self.currentEntity.name # this holds the name of the last entity that ended processing in Machine
......@@ -175,7 +184,7 @@ class Machine(CoreObject):
# if M1 had failure, we want to wait until it is fixed and also count the failure time.
else:
failTime=now() # dummy variable holding the time failure happened
self.interruptionActions() # execute interruption actions
#self.interruptionActions() # execute interruption actions
# passivate until machine is up
yield waituntil, self, self.checkIfMachineIsUp
self.failureTimeInCurrentEntity+=now()-failTime # count the failure while on current entity time with failureTime variable
......
......@@ -24,7 +24,8 @@ Created on 20 Dec 2012
'''
inherits from MachineJobShop it can preempt the currently processed Entity if need be
'''
from MachinePreemptive import MachinePreemptive
from MachineJobShop import MachineJobShop
from SimPy.Simulation import reactivate, now
#the MachineJobShop object
class MachinePreemptive(MachineJobShop):
......@@ -39,13 +40,31 @@ class MachinePreemptive(MachineJobShop):
def initilize(self):
MachineJobShop.initialize(self)
self.shouldPreempt=False
#when interrupted call the preempt method
def interruptionAction(self):
self.preempt()
self.lastGiver=self.previous[0]
def getEntity(self):
activeEntity=MachineJobShop.getEntity(self)
self.lastGiver=self.giver
return activeEntity
#method to execute the preemption
def preempt(self):
print 'in'
activeEntity=self.getActiveObjectQueue()[0] #get the active Entity
#calculate the remaining processing time
#if it is reset then set it as the original processing time
if self.resetOnPreemption:
remainingProcessingTime=self.procTime
#else subtract the time that passed since the entity entered
#(may need also failure time if there was. TO BE MELIORATED)
else:
remainingProcessingTime=self.procTime-(now()-self.timeLastEntityEntered)
#update the remaining route of activeEntity
activeEntity.remainingRoute.insert(0, [self.id, remainingProcessingTime])
activeEntity.remainingRoute.insert(0, [self.lastGiver.id, 0])
#set the receiver as the object where the active entity was preempted from
self.receiver=self.lastGiver
self.waitToDispose=True #set that I have to dispose
reactivate(self)
......@@ -26,6 +26,7 @@ Inherits from QueueJobShop. If it gets an isCritical Entity it can interrupt the
'''
from QueueJobShop import QueueJobShop
from SimPy.Simulation import now
#the QueuePreemptive object
class QueuePreemptive(QueueJobShop):
......@@ -36,11 +37,12 @@ class QueuePreemptive(QueueJobShop):
#if the obtained Entity is critical
if activeEntity.isCritical:
#if the receiver is not empty
if len(receiver.getActiveObjectQueue())>0:
if len(self.receiver.getActiveObjectQueue())>0:
#if the receiver does not hold an Entity that is also critical
if not receiver.getActiveObjectQueue()[0].isCritical:
receiver.shouldPreempt=True
receiver.interrupt() #interrupt the receiver
if not self.receiver.getActiveObjectQueue()[0].isCritical:
self.receiver.shouldPreempt=True
self.receiver.preempt()
self.receiver.timeLastEntityEnded=now() #required to count blockage correctly in the preemptied station
#for future use
def sortEntities(self):
......
{
"elementList": [
{
"extraPropertyDict": {
"isCritical": "1",
"route": [
{
"processingTime": {
"distributionType": "Fixed",
"mean": "0"
},
"stationId": "Q1",
"stepNumber": "0"
},
{
"processingTime": {
"distributionType": "Fixed",
"mean": "0.25"
},
"stationId": "M1",
"stepNumber": "1"
},
{
"processingTime": {
"distributionType": "Fixed",
"mean": "0"
},
"stationId": "Q2",
"stepNumber": "2"
},
{
"processingTime": {
"distributionType": "Fixed",
"mean": "1"
},
"stationId": "M2",
"stepNumber": "3"
}
],
"name": "Component1"
},
"_class": "Dream.Job",
"id": "C1",
"results": {
"completionTime": 1.25,
"schedule": [
{
"entranceTime": 0,
"stationId": "Q1",
"stepNumber": 0
},
{
"entranceTime": 0,
"stationId": "M1",
"stepNumber": 1
},
{
"entranceTime": 0.25,
"stationId": "Q2",
"stepNumber": 2
},
{
"entranceTime": 0.25,
"stationId": "M2",
"stepNumber": 3
},
{
"entranceTime": 1.25,
"stationId": "E1",
"stepNumber": 4
}
]
}
},
{
"extraPropertyDict": {
"isCritical": "0",
"route": [
{
"processingTime": {
"distributionType": "Fixed",
"mean": "0"
},
"stationId": "Q2",
"stepNumber": "0"
},
{
"processingTime": {
"distributionType": "Fixed",
"mean": "1"
},
"stationId": "M2",
"stepNumber": "1"
}
],
"name": "Component2"
},
"_class": "Dream.Job",
"id": "C2",
"results": {
"completionTime": 2.0,
"schedule": [
{
"entranceTime": 0,
"stationId": "Q2",
"stepNumber": 0
},
{
"entranceTime": 0,
"stationId": "M2",
"stepNumber": 1
},
{
"entranceTime": 0.25,
"stationId": "Q2",
"stepNumber": 2
},
{
"entranceTime": 1.25,
"stationId": "M2",
"stepNumber": 3
},
{
"entranceTime": 2.0,
"stationId": "E1",
"stepNumber": 4
}
]
}
},
{
"_class": "Dream.Exit",
"id": "E1",
"results": {
"throughput": 2,
"takt_time": 1.0,
"lifespan": 1.625
}
},
{
"_class": "Dream.Machine",
"id": "M1",
"results": {
"working_ratio": 12.5,
"blockage_ratio": 0.0,
"failure_ratio": 0.0,
"waiting_ratio": 87.5
}
},
{
"_class": "Dream.Machine",
"id": "M2",
"results": {
"working_ratio": 100.0,
"blockage_ratio": 0.0,
"failure_ratio": 0.0,
"waiting_ratio": 0.0
}
}
],
"_class": "Dream.Simulation",
"general": {
"_class": "Dream.Configuration"
}
}
\ No newline at end of file
{
"elementList": [
{
"extraPropertyDict": {
"isCritical": "1",
"route": [
{
"processingTime": {
"distributionType": "Fixed",
"mean": "0"
},
"stationId": "Q1",
"stepNumber": "0"
},
{
"processingTime": {
"distributionType": "Fixed",
"mean": "0.25"
},
"stationId": "M1",
"stepNumber": "1"
},
{
"processingTime": {
"distributionType": "Fixed",
"mean": "0"
},
"stationId": "Q2",
"stepNumber": "2"
},
{
"processingTime": {
"distributionType": "Fixed",
"mean": "1"
},
"stationId": "M2",
"stepNumber": "3"
}
],
"name": "Component1"
},
"_class": "Dream.Job",
"id": "C1",
"results": {
"completionTime": 1.25,
"schedule": [
{
"entranceTime": 0,
"stationId": "Q1",
"stepNumber": 0
},
{
"entranceTime": 0,
"stationId": "M1",
"stepNumber": 1
},
{
"entranceTime": 0.25,
"stationId": "Q2",
"stepNumber": 2
},
{
"entranceTime": 0.25,
"stationId": "M2",
"stepNumber": 3
},
{
"entranceTime": 1.25,
"stationId": "E1",
"stepNumber": 4
}
]
}
},
{
"extraPropertyDict": {
"isCritical": "0",
"route": [
{
"processingTime": {
"distributionType": "Fixed",
"mean": "0"
},
"stationId": "Q2",
"stepNumber": "0"
},
{
"processingTime": {
"distributionType": "Fixed",
"mean": "1"
},
"stationId": "M2",
"stepNumber": "1"
}
],
"name": "Component2"
},
"_class": "Dream.Job",
"id": "C2",
"results": {
"completionTime": 2.25,
"schedule": [
{
"entranceTime": 0,
"stationId": "Q2",
"stepNumber": 0
},
{
"entranceTime": 0,
"stationId": "M2",
"stepNumber": 1
},
{
"entranceTime": 0.25,
"stationId": "Q2",
"stepNumber": 2
},
{
"entranceTime": 1.25,
"stationId": "M2",
"stepNumber": 3
},
{
"entranceTime": 2.25,
"stationId": "E1",
"stepNumber": 4
}
]
}
},
{
"_class": "Dream.Exit",
"id": "E1",
"results": {
"throughput": 2,
"takt_time": 1.125,
"lifespan": 1.75
}
},
{
"_class": "Dream.Machine",
"id": "M1",
"results": {
"working_ratio": 11.11111111111111,
"blockage_ratio": 0.0,
"failure_ratio": 0.0,
"waiting_ratio": 88.88888888888889
}
},
{
"_class": "Dream.Machine",
"id": "M2",
"results": {
"working_ratio": 100.0,
"blockage_ratio": 0.0,
"failure_ratio": 0.0,
"waiting_ratio": 0.0
}
}
],
"_class": "Dream.Simulation",
"general": {
"_class": "Dream.Configuration"
}
}
\ 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