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

MachinePreemptive code moved to Machine and MachineJobShop

parent c9e1450a
......@@ -44,6 +44,11 @@ class CoreObject(Process):
self.Working=[]
self.Blockage=[]
self.Waiting=[]
#default attributes set so that the CoreObject has them
self.isPreemptive=False
self.resetOnPreemption=False
def initialize(self):
......@@ -178,8 +183,8 @@ class CoreObject(Process):
# perform preemption when required
# if the object is not Exit
if activeObject.receiver:
# if the obtained Entity is critical
if activeEntity.isCritical:
# if the obtained Entity is critical and the receiver is preemptive
if activeEntity.isCritical and activeObject.receiver.isPreemptive:
#if the receiver is not empty
if len(self.receiver.getActiveObjectQueue())>0:
#if the receiver does not hold an Entity that is also critical
......@@ -376,3 +381,11 @@ class CoreObject(Process):
# =======================================================================
def interruptionActions(self):
pass
# =======================================================================
# method to execute preemption
# =======================================================================
def preempt(self):
#ToDO make a generic method
pass
......@@ -20,15 +20,17 @@
"failures": {}
},
"M2": {
"_class": "Dream.MachinePreemptive",
"_class": "Dream.MachineJobShop",
"id": "M2",
"name": "Machine2",
"processingTime": {
"distributionType": "Fixed",
"mean": "1.5"
},
"failures": {},
"resetOnPreemption":"0"
"preemption": {
"isPreemptive": "1",
"resetOnPreemption": "0"
}
},
"Q1": {
"_class": "Dream.QueueJobShop",
......
......@@ -20,15 +20,17 @@
"failures": {}
},
"M2": {
"_class": "Dream.MachinePreemptive",
"_class": "Dream.MachineJobShop",
"id": "M2",
"name": "Machine2",
"processingTime": {
"distributionType": "Fixed",
"mean": "1.5"
},
"failures": {},
"resetOnPreemption":"1"
"preemption": {
"isPreemptive": "1",
"resetOnPreemption": "1"
}
},
"Q1": {
"_class": "Dream.QueueJobShop",
......
......@@ -286,6 +286,11 @@ def createObjects():
loadStdev = float(loadTime.get('loadStdev', '0'))
loadMin=float(loadTime.get('loadMin', '0'))
loadMax=float(loadTime.get('loadMax', '0'))
preemption=element.get('preemption',{})
isPreemptive=resetOnPreemption=False
if len(preemption)>0:
isPreemptive=bool(int(preemption.get('isPreemptive', 0)))
resetOnPreemption=bool(int(preemption.get('isPreemptive', 0)))
if len(G.OperatorPoolsList)>0:
for operatorPool in G.OperatorPoolsList: # find the operatorPool assigned to the machine
......@@ -314,7 +319,7 @@ def createObjects():
loadDistribution=loadDistribution, setupDistribution=setupDistribution,
setupMean=setupMean,setupStdev=setupStdev,setupMin=setupMin,setupMax=setupMax,
loadMean=loadMean,loadStdev=loadStdev,loadMin=loadMin,loadMax=loadMax,
repairman=r)
repairman=r, isPreemptive=isPreemptive, resetOnPreemption=resetOnPreemption)
M.nextIds=getSuccessorList(id) # update the nextIDs list of the machine
G.MachineList.append(M) # add machine to global MachineList
if M.operatorPool!="None":
......@@ -418,6 +423,11 @@ def createObjects():
loadStdev = float(loadTime.get('loadStdev', '0'))
loadMin=float(loadTime.get('loadMin', '0'))
loadMax=float(loadTime.get('loadMax', '0'))
preemption=element.get('preemption',{})
isPreemptive=resetOnPreemption=False
if len(preemption)>0:
isPreemptive=bool(int(preemption.get('isPreemptive', 0)))
resetOnPreemption=bool(int(preemption.get('resetOnPreemption', 0)))
if len(G.OperatorPoolsList)>0:
for operatorPool in G.OperatorPoolsList: # find the operatorPool assigned to the machine
......@@ -447,7 +457,7 @@ def createObjects():
loadDistribution=loadDistribution, setupDistribution=setupDistribution,
setupMean=setupMean,setupStdev=setupStdev,setupMin=setupMin,setupMax=setupMax,
loadMean=loadMean,loadStdev=loadStdev,loadMin=loadMin,loadMax=loadMax,
repairman=r)
repairman=r, isPreemptive=isPreemptive, resetOnPreemption=resetOnPreemption)
M.nextIds=getSuccessorList(id)
G.MachineJobShopList.append(M)
G.MachineList.append(M)
......
......@@ -48,7 +48,8 @@ class Machine(CoreObject):
failureDistribution='No', MTTF=0, MTTR=0, availability=0, repairman='None',\
operatorPool='None',operationType='None',\
loadDistribution="No",loadMean=0, loadStdev=0, loadMin=0, loadMax=10,
setupDistribution="No",setupMean=0, setupStdev=0, setupMin=0, setupMax=10):
setupDistribution="No",setupMean=0, setupStdev=0, setupMin=0, setupMax=10,
isPreemptive=False, resetOnPreemption=False):
CoreObject.__init__(self)
# hold the id, name, and type of the Machine instance
self.id=id
......@@ -123,6 +124,9 @@ class Machine(CoreObject):
self.WaitingForLoadOperator=[]
self.Loading = []
self.SettingUp =[]
self.isPreemptive=isPreemptive
self.resetOnPreemption=resetOnPreemption
# =======================================================================
# initialize the machine
......
......@@ -26,7 +26,7 @@ extends the machine object so that it can act as a jobshop station. It reads the
'''
from SimPy.Simulation import Process, Resource
from SimPy.Simulation import activate, passivate, waituntil, now, hold
from SimPy.Simulation import activate, passivate, waituntil, now, hold, reactivate
from Machine import Machine
# ===========================================================================
......@@ -136,6 +136,37 @@ class MachineJobShop(Machine):
and activeObject.waitToDispose\
and activeObject.Up\
and (thecaller is self.receiver)
# =======================================================================
# method to execute preemption
# =======================================================================
def preempt(self):
activeObject=self.getActiveObject()
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, {'stationIdsList':[str(self.id)],\
'processingTime':\
{'distributionType':'Fixed',\
'mean':str(remainingProcessingTime)}})
# activeEntity.remainingRoute.insert(0, [self.id, remainingProcessingTime])
activeEntity.remainingRoute.insert(0, {'stationIdsList':[str(self.lastGiver.id)],\
'processingTime':\
{'distributionType':'Fixed',\
'mean':'0'}})
# 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.next=[self.receiver]
self.waitToDispose=True #set that I have to dispose
self.receiver.timeLastEntityEnded=now() #required to count blockage correctly in the preemptied station
reactivate(self)
\ 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