Commit 591ad0e5 authored by Georgios Dagkakis's avatar Georgios Dagkakis Committed by Sebastien Robin

Machine object updated to receive multiple predecessors/successors

parent 1fa101ea
*.pyc
\ No newline at end of file
......@@ -49,6 +49,21 @@ class Assembly(Process):
Process.__init__(self)
self.waitToDispose=False #flag that shows if the Assembly waits to dispose an entity
self.Up=True #Boolean that shows if the machine is in failure ("Down") or not ("up")
self.currentEntity=None
self.totalFailureTime=0 #holds the total failure time
self.timeLastFailure=0 #holds the time that the last failure of the machine started
self.timeLastFailureEnded=0 #holds the time that the last failure of the machine Ended
self.downTimeProcessingCurrentEntity=0 #holds the time that the machine was down while processing the current entity
self.downTimeInTryingToReleaseCurrentEntity=0 #holds the time that the machine was down while trying
#to release the current entity
self.downTimeInCurrentEntity=0 #holds the total time that the machine was down while holding current entity
self.timeLastEntityLeft=0 #holds the last time that an entity left the machine
self.processingTimeOfCurrentEntity=0 #holds the total processing time that the current entity required
self.totalBlockageTime=0 #holds the total blockage time
self.totalWaitingTime=0 #holds the total waiting time
......
......@@ -35,6 +35,31 @@ class Exit(Process):
self.numOfExits=0
self.totalLifespan=0
self.Up=True #Boolean that shows if the machine is in failure ("Down") or not ("up")
self.currentEntity=None
self.totalBlockageTime=0 #holds the total blockage time
self.totalFailureTime=0 #holds the total failure time
self.totalWaitingTime=0 #holds the total waiting time
self.totalWorkingTime=0 #holds the total working time
self.completedJobs=0 #holds the number of completed jobs
self.timeLastEntityEnded=0 #holds the last time that an entity ended processing in the machine
self.nameLastEntityEnded="" #holds the name of the last entity that ended processing in the machine
self.timeLastEntityEntered=0 #holds the last time that an entity entered in the machine
self.nameLastEntityEntered="" #holds the name of the last entity that entered in the machine
self.timeLastFailure=0 #holds the time that the last failure of the machine started
self.timeLastFailureEnded=0 #holds the time that the last failure of the machine Ended
self.downTimeProcessingCurrentEntity=0 #holds the time that the machine was down while processing the current entity
self.downTimeInTryingToReleaseCurrentEntity=0 #holds the time that the machine was down while trying
#to release the current entity
self.downTimeInCurrentEntity=0 #holds the total time that the machine was down while holding current entity
self.timeLastEntityLeft=0 #holds the last time that an entity left the machine
self.processingTimeOfCurrentEntity=0 #holds the total processing time that the current entity required
self.waitToDispose=False #shows if the machine waits to dispose an entity
def Run(self):
while 1:
yield waituntil, self, self.canAcceptAndIsRequested #wait until the Queue can accept an entity
......
{
"_class": "Dream.Simulation",
"general": {
"_class": "Dream.Configuration",
"numberOfReplications": "1",
"maxSimTime": "1440",
"trace": "Yes",
"confidenceLevel": "0.95"
},
"modelResource": [
{
"_class": "Dream.Repairman",
"id": "W1",
"name": "W1",
"capacity": "1"
}
],
"coreObject": [
{
"_class": "Dream.Source",
"id": "S1",
"name": "Raw Material",
"interarrivalTime": {
"distributionType": "Fixed",
"mean": "0.5"
},
"entity": "Part",
"successorList": ["DummyQ"]
},
{
"_class": "Dream.Machine",
"id": "M1",
"name": "Machine1",
"processingTime": {
"distributionType": "Fixed",
"mean": "1.5"
},
"failures": {
"failureDistribution": "No",
"MTTF": "60",
"MTTR": "5",
"repairman": "W1"
},
"predecessorList": ["Q1"],
"successorList": ["M3"]
},
{
"_class": "Dream.Machine",
"id": "M2",
"name": "Machine2",
"processingTime": {
"distributionType": "Fixed",
"mean": "1.5"
},
"failures": {
"failureDistribution": "No",
"MTTF": "40",
"MTTR": "10",
"repairman": "W1"
},
"predecessorList": ["Q1"],
"successorList": ["M3"]
},
{
"_class": "Dream.Machine",
"id": "M3",
"name": "Machine3",
"processingTime": {
"distributionType": "Fixed",
"mean": "2"
},
"failures": {
"failureDistribution": "No"
},
"predecessorList": ["M1","M2"],
"successorList": ["E1"]
},
{
"_class": "Dream.Queue",
"id": "DummyQ",
"name": "DummyQ",
"isDummy": "True",
"capacity": "1",
"predecessorList": ["S1"],
"successorList": ["Q1"]
},
{
"_class": "Dream.Queue",
"id": "Q1",
"name": "Q1",
"isDummy": "False",
"capacity": "1",
"predecessorList": ["DummyQ"],
"successorList": ["M1","M2"]
},
{
"_class": "Dream.Exit",
"id": "E1",
"name": "Stock",
"predecessorList": ["M3"]
}
]
}
{
"_class": "Dream.Simulation",
"general": {
"_class": "Dream.Configuration",
"numberOfReplications": "1",
"maxSimTime": "1440",
"trace": "Yes",
"confidenceLevel": "0.95"
},
"modelResource": [
{
"_class": "Dream.Repairman",
"id": "W1",
"name": "W1",
"capacity": "1"
}
],
"coreObject": [
{
"_class": "Dream.Source",
"id": "S1",
"name": "Raw Material",
"interarrivalTime": {
"distributionType": "Fixed",
"mean": "0.5"
},
"entity": "Part",
"successorList": ["DummyQ"]
},
{
"_class": "Dream.Machine",
"id": "M1",
"name": "Machine1",
"processingTime": {
"distributionType": "Fixed",
"mean": "1.5"
},
"failures": {
"failureDistribution": "No",
"MTTF": "60",
"MTTR": "5",
"repairman": "W1"
},
"predecessorList": ["Q1"],
"successorList": ["M3","M4"]
},
{
"_class": "Dream.Machine",
"id": "M2",
"name": "Machine2",
"processingTime": {
"distributionType": "Fixed",
"mean": "1.5"
},
"failures": {
"failureDistribution": "No",
"MTTF": "40",
"MTTR": "10",
"repairman": "W1"
},
"predecessorList": ["Q1"],
"successorList": ["M3","M4"]
},
{
"_class": "Dream.Machine",
"id": "M3",
"name": "Machine3",
"processingTime": {
"distributionType": "Fixed",
"mean": "2"
},
"failures": {
"failureDistribution": "No"
},
"predecessorList": ["M1","M2"],
"successorList": ["E1"]
},
{
"_class": "Dream.Machine",
"id": "M4",
"name": "Machine4",
"processingTime": {
"distributionType": "Fixed",
"mean": "2"
},
"failures": {
"failureDistribution": "No"
},
"predecessorList": ["M1","M2"],
"successorList": ["E1"]
},
{
"_class": "Dream.Queue",
"id": "DummyQ",
"name": "DummyQ",
"isDummy": "True",
"capacity": "1",
"predecessorList": ["S1"],
"successorList": ["Q1"]
},
{
"_class": "Dream.Queue",
"id": "Q1",
"name": "Q1",
"isDummy": "False",
"capacity": "1",
"predecessorList": ["DummyQ"],
"successorList": ["M1","M2"]
},
{
"_class": "Dream.Exit",
"id": "E1",
"name": "Stock",
"predecessorList": ["M3","M4"]
}
]
}
......@@ -230,8 +230,8 @@ def main():
initialize() #initialize the simulation
initializeObjects()
activateObjects()
activateObjects()
simulate(until=G.maxSimTime) #start the simulation
#carry on the post processing operations for every object in the topology
......@@ -255,6 +255,6 @@ def main():
G.ObjList[j].outputResultsXL(G.maxSimTime)
G.outputFile.save("output.xls")
print "execution time="+str(time.time()-start)
print "execution time="+str(time.time()-start)
if __name__ == '__main__': main()
\ No newline at end of file
......@@ -20,6 +20,8 @@ class Machine(Process):
#initialize the id the capacity, of the resource and the distribution
def __init__(self, id, name, capacity, dist, time, fDist, MTTF, MTTR, availability, repairman):
Process.__init__(self)
self.predecessorIndex=0 #holds the index of the predecessor from which the Machine will take an entity next
self.successorIndex=0 #holds the index of the successor where the Machine will dispose an entity next
self.id=id
self.objName=name
self.capacity=capacity
......@@ -187,13 +189,53 @@ class Machine(Process):
def checkIfMachineIsUp(self):
return self.Up
#checks if the machine can accept an entity
#checks if the Machine can accept an entity
#it checks also who called it and returns TRUE only to the predecessor that will give the entity.
def canAccept(self):
return self.Up and len(self.Res.activeQ)==0
if(len(self.previous)==1):
return self.Up and len(self.Res.activeQ)==0
if len(self.Res.activeQ)==self.capacity:
return False
#identify the caller method
frame = sys._getframe(1)
arguments = frame.f_code.co_argcount
if arguments == 0:
print "Not called from a method"
return
caller_calls_self = frame.f_code.co_varnames[0]
thecaller = frame.f_locals[caller_calls_self]
#return true only to the predecessor from which the queue will take
flag=False
if thecaller is self.previous[self.predecessorIndex]:
flag=True
return len(self.Res.activeQ)<self.capacity and flag
#checks if the machine can accept an entity and there is an entity waiting for it
#checks if the Machine 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):
return self.Up and len(self.Res.activeQ)==0 and self.previous[0].haveToDispose()
if(len(self.previous)==1):
return self.Up and len(self.Res.activeQ)==0 and self.previous[0].haveToDispose()
isRequested=False
maxTimeWaiting=0
for i in range(len(self.previous)):
if(self.previous[i].haveToDispose()):
isRequested=True
#timeWaiting=now()-(self.previous[i].timeLastEntityEnded+self.previous[i].downTimeInTryingToReleaseCurrentEntity)
if(self.previous[i].downTimeInTryingToReleaseCurrentEntity>0):
timeWaiting=now()-self.previous[i].timeLastFailureEnded
else:
timeWaiting=now()-self.previous[i].timeLastEntityEnded
#if more than one predecessor have to dispose take the part from the one that is blocked longer
if(timeWaiting>=maxTimeWaiting): #or maxTimeWaiting==0):
self.predecessorIndex=i
maxTimeWaiting=timeWaiting
return len(self.Res.activeQ)<self.capacity and isRequested
#checks if the machine down or it can dispose the object
def ifCanDisposeOrHaveFailure(self):
......@@ -202,7 +244,37 @@ class Machine(Process):
#checks if the Machine can dispose an entity to the following object
def haveToDispose(self):
return len(self.Res.activeQ)>0 and self.waitToDispose and self.Up
if(len(self.next)==1):
return len(self.Res.activeQ)>0 and self.waitToDispose and self.Up
#if the Machine is empty it returns false right away
if(len(self.Res.activeQ)==0):
return False
#identify the caller method
frame = sys._getframe(1)
arguments = frame.f_code.co_argcount
if arguments == 0:
print "Not called from a method"
return
caller_calls_self = frame.f_code.co_varnames[0]
thecaller = frame.f_locals[caller_calls_self]
#give the entity to the successor that is waiting for the most time.
#plant does not do this in every occasion!
maxTimeWaiting=0
for i in range(len(self.next)):
if(self.next[i].canAccept()):
timeWaiting=now()-self.next[i].timeLastEntityLeft
if(timeWaiting>maxTimeWaiting or maxTimeWaiting==0):
maxTimeWaiting=timeWaiting
self.successorIndex=i
#return true only to the predecessor from which the queue will take
flag=False
if thecaller is self.next[self.successorIndex]:
flag=True
return len(self.Res.activeQ)>0 and self.waitToDispose and self.Up and flag
#removes an entity from the Machine
def removeEntity(self):
......@@ -218,10 +290,12 @@ class Machine(Process):
#self.outputTrace("got blocked in M"+str(self.id)+" for "
# +str(self.totalBlockageTime))
#gets an entity from the predecessor
#gets an entity from the predecessor that the predecessor index points to
def getEntity(self):
self.Res.activeQ.append(self.previous[0].Res.activeQ[0]) #get the entity from the predecessor
self.previous[0].removeEntity()
#self.Res.activeQ.append(self.previous[0].Res.activeQ[0]) #get the entity from the predecessor
#self.previous[0].removeEntity()
self.Res.activeQ.append(self.previous[self.predecessorIndex].Res.activeQ[0]) #get the entity from the predecessor
self.previous[self.predecessorIndex].removeEntity()
#actions to be taken after the simulation ends
......@@ -280,6 +354,7 @@ class Machine(Process):
G.traceSheet.write(G.traceIndex,1,self.Res.activeQ[0].name)
G.traceSheet.write(G.traceIndex,2,message)
G.traceIndex+=1 #increment the row
#if we reach row 65536 we need to create a new sheet (excel limitation)
if(G.traceIndex==65536):
G.traceIndex=0
......
......@@ -34,8 +34,30 @@ class Queue(Process):
def initialize(self):
Process.__init__(self)
self.Res=Resource(self.capacity)
self.nameLastEntityEntered="" #keeps the name of the last entity that entered in the queue
self.timeLastEntityEntered=0 #keeps the time of the last entity that entered in the queue
self.Up=True #Boolean that shows if the machine is in failure ("Down") or not ("up")
self.currentEntity=None
self.totalBlockageTime=0 #holds the total blockage time
self.totalFailureTime=0 #holds the total failure time
self.totalWaitingTime=0 #holds the total waiting time
self.totalWorkingTime=0 #holds the total working time
self.completedJobs=0 #holds the number of completed jobs
self.timeLastEntityEnded=0 #holds the last time that an entity ended processing in the machine
self.nameLastEntityEnded="" #holds the name of the last entity that ended processing in the machine
self.timeLastEntityEntered=0 #holds the last time that an entity entered in the machine
self.nameLastEntityEntered="" #holds the name of the last entity that entered in the machine
self.timeLastFailure=0 #holds the time that the last failure of the machine started
self.timeLastFailureEnded=0 #holds the time that the last failure of the machine Ended
self.downTimeProcessingCurrentEntity=0 #holds the time that the machine was down while processing the current entity
self.downTimeInTryingToReleaseCurrentEntity=0 #holds the time that the machine was down while trying
#to release the current entity
self.downTimeInCurrentEntity=0 #holds the total time that the machine was down while holding current entity
self.timeLastEntityLeft=0 #holds the last time that an entity left the machine
self.processingTimeOfCurrentEntity=0 #holds the total processing time that the current entity required
self.waitToDispose=False #shows if the machine waits to dispose an entity
def Run(self):
while 1:
......@@ -57,8 +79,7 @@ class Queue(Process):
return len(self.Q.activeQ)<self.capacity
#checks if the Queue can accept an entity
#it checks also who called it and returns TRUE only to the predecessor that will give the entity.
#this is kind of slow I think got to check
#it checks also who called it and returns TRUE only to the predecessor that will give the entity.
def canAccept(self):
if(len(self.previous)==1):
return len(self.Res.activeQ)<self.capacity
......@@ -110,7 +131,7 @@ class Queue(Process):
if(timeWaiting>maxTimeWaiting or maxTimeWaiting==0):
maxTimeWaiting=timeWaiting
self.successorIndex=i
#return true only to the predecessor from which the queue will take
flag=False
if thecaller is self.next[self.successorIndex]:
......
......@@ -38,7 +38,32 @@ class Source(Process):
Process.__init__(self)
self.Res=Resource(capacity=infinity)
self.Res.activeQ=[]
self.Res.waitQ=[]
self.Res.waitQ=[]
self.Up=True #Boolean that shows if the machine is in failure ("Down") or not ("up")
self.currentEntity=None
self.totalBlockageTime=0 #holds the total blockage time
self.totalFailureTime=0 #holds the total failure time
self.totalWaitingTime=0 #holds the total waiting time
self.totalWorkingTime=0 #holds the total working time
self.completedJobs=0 #holds the number of completed jobs
self.timeLastEntityEnded=0 #holds the last time that an entity ended processing in the machine
self.nameLastEntityEnded="" #holds the name of the last entity that ended processing in the machine
self.timeLastEntityEntered=0 #holds the last time that an entity entered in the machine
self.nameLastEntityEntered="" #holds the name of the last entity that entered in the machine
self.timeLastFailure=0 #holds the time that the last failure of the machine started
self.timeLastFailureEnded=0 #holds the time that the last failure of the machine Ended
self.downTimeProcessingCurrentEntity=0 #holds the time that the machine was down while processing the current entity
self.downTimeInTryingToReleaseCurrentEntity=0 #holds the time that the machine was down while trying
#to release the current entity
self.downTimeInCurrentEntity=0 #holds the total time that the machine was down while holding current entity
self.timeLastEntityLeft=0 #holds the last time that an entity left the machine
self.processingTimeOfCurrentEntity=0 #holds the total processing time that the current entity required
self.waitToDispose=False #shows if the machine waits to dispose an entity
def Run(self):
i=0
......
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