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

Just some clean-up and comments in the new parts of code

parent ec709da7
......@@ -47,19 +47,19 @@ class Assembly(Process):
def initialize(self):
Process.__init__(self)
self.waitToDispose=False #flag that shows if the Assembly waits to dispose an entity
self.waitToDispose=False #flag that shows if the object waits to dispose an entity
self.Up=True #Boolean that shows if the machine is in failure ("Down") or not ("up")
self.Up=True #Boolean that shows if the object 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
self.timeLastFailure=0 #holds the time that the last failure of the object started
self.timeLastFailureEnded=0 #holds the time that the last failure of the object Ended
self.downTimeProcessingCurrentEntity=0 #holds the time that the object was down while processing the current entity
self.downTimeInTryingToReleaseCurrentEntity=0 #holds the time that the object 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.downTimeInCurrentEntity=0 #holds the total time that the object was down while holding current entity
self.timeLastEntityLeft=0 #holds the last time that an entity left the object
self.processingTimeOfCurrentEntity=0 #holds the total processing time that the current entity required
......@@ -70,12 +70,12 @@ class Assembly(Process):
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 Assembly
self.timeLastEntityEntered=0 #holds the last time that an entity ended processing in the Assembly
self.timeLastEntityEnded=0 #holds the last time that an entity ended processing in the object
self.timeLastEntityEntered=0 #holds the last time that an entity ended processing in the object
self.timeLastFrameWasFull=0 #holds the time that the last frame was full, ie that assembly process started
self.nameLastFrameWasFull="" #holds the name of the last frame that was full, ie that assembly process started
self.nameLastEntityEntered="" #holds the name of the last frame that entered processing in the Assembly
self.nameLastEntityEnded="" #holds the name of the last frame that ended processing in the Assembly
self.nameLastEntityEntered="" #holds the name of the last frame that entered processing in the object
self.nameLastEntityEnded="" #holds the name of the last frame that ended processing in the object
self.Res=Resource(1)
self.Res.activeQ=[]
self.Res.waitQ=[]
......
......@@ -35,7 +35,7 @@ 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.Up=True #Boolean that shows if the object is in failure ("Down") or not ("up")
self.currentEntity=None
self.totalBlockageTime=0 #holds the total blockage time
......@@ -44,21 +44,21 @@ class Exit(Process):
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
self.timeLastEntityEnded=0 #holds the last time that an entity ended processing in the object
self.nameLastEntityEnded="" #holds the name of the last entity that ended processing in the object
self.timeLastEntityEntered=0 #holds the last time that an entity entered in the object
self.nameLastEntityEntered="" #holds the name of the last entity that entered in the object
self.timeLastFailure=0 #holds the time that the last failure of the object started
self.timeLastFailureEnded=0 #holds the time that the last failure of the object Ended
self.downTimeProcessingCurrentEntity=0 #holds the time that the object was down while processing the current entity
self.downTimeInTryingToReleaseCurrentEntity=0 #holds the time that the object 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.downTimeInCurrentEntity=0 #holds the total time that the object was down while holding current entity
self.timeLastEntityLeft=0 #holds the last time that an entity left the object
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
self.waitToDispose=False #shows if the object waits to dispose an entity
def run(self):
while 1:
......
......@@ -26,7 +26,7 @@ import json
from random import Random
import sys
#read general simulation inputs
#reads general simulation inputs
def readGeneralInput():
general=G.JSONData['general']
G.numberOfReplications=int(general.get('numberOfReplications', 'not found'))
......@@ -34,7 +34,7 @@ def readGeneralInput():
G.trace=general.get('trace', 'not found')
G.confidenceLevel=float(general.get('confidenceLevel', 'not found'))
#create the simulation objects
#creates the simulation objects
def createObjects():
#Read the json data
coreObject=G.JSONData['coreObject']
......@@ -147,7 +147,7 @@ def createObjects():
G.AssemblyList.append(A)
G.ObjList.append(A)
#reads the topology and defines it for the objects
#defines the topology (predecessors and successors for all the objects)
def setTopology():
#loop through all the objects
......@@ -164,10 +164,13 @@ def setTopology():
if G.ObjList[q].id==G.ObjList[i].nextIds[j]:
next.append(G.ObjList[q])
if G.ObjList[i].type=="Source":
G.ObjList[i].defineRouting(next)
elif G.ObjList[i].type=="Exit":
G.ObjList[i].defineRouting(previous)
#Assembly should be changed to identify what the entity that it receives is.
#previousPart and previousFrame will become problematic
elif G.ObjList[i].type=="Assembly":
previousPart=[]
previousFrame=[]
......@@ -204,10 +207,11 @@ def activateObjects():
#the main script that is ran
def main():
#topologyId=raw_input("give the topology id\n")
#create an empty list to store all the objects in
G.ObjList=[]
#user inputs the id of the JSON file
topologyId=raw_input("give the topology id\n")
try:
G.JSONFile=open('JSONInputs/Topology'+str(topologyId)+'.JSON', "r")
......@@ -216,13 +220,15 @@ def main():
sys.exit()
start=time.time() #start counting execution time
#read the input from the JSON file and create the line
G.InputData=G.JSONFile.read()
G.JSONData=json.loads(G.InputData)
#print G.JSONData
readGeneralInput()
createObjects()
setTopology()
#run the experiment (replications)
for i in range(G.numberOfReplications):
print "start run number "+str(i+1)
G.seed+=1
......
......@@ -67,23 +67,23 @@ class Machine(Process):
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.timeLastEntityEnded=0 #holds the last time that an entity ended processing in the object
self.nameLastEntityEnded="" #holds the name of the last entity that ended processing in the object
self.timeLastEntityEntered=0 #holds the last time that an entity entered in the object
self.nameLastEntityEntered="" #holds the name of the last entity that entered in the object
self.timeLastFailure=0 #holds the time that the last failure of the object started
self.timeLastFailureEnded=0 #holds the time that the last failure of the object 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
self.downTimeInTryingToReleaseCurrentEntity=0 #holds the time that the object 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.downTimeInCurrentEntity=0 #holds the total time that the object was down while holding current entity
self.timeLastEntityLeft=0 #holds the last time that an entity left the object
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
self.waitToDispose=False #shows if the object waits to dispose an entity
#if the failure distribution for the machine is fixed, activate the failure
#if the failure distribution for the object is fixed, activate the failure
if(self.failureDistType=="Fixed" or self.failureDistType=="Availability"):
MFailure=Failure(self, self.failureDistType, self.MTTF, self.MTTR, self.availability, self.id, self.repairman)
activate(MFailure,MFailure.run())
......@@ -98,7 +98,6 @@ class Machine(Process):
#and one predecessor requests it
self.getEntity() #get the entity from the predecessor
#self.previous[0].removeEntity()
self.outputTrace("got into "+self.objName)
self.currentEntity=self.Res.activeQ[0] #entity is the current entity processed in Machine
......@@ -192,9 +191,11 @@ class Machine(Process):
#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):
if(len(self.previous)==1):
#if we have only one predecessor just check if there is a place and the machine is up
if(len(self.previous)==1):
return self.Up and len(self.Res.activeQ)==0
#if the machine is busy return False immediately
if len(self.Res.activeQ)==self.capacity:
return False
......@@ -216,23 +217,24 @@ class Machine(Process):
#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):
#if we have only one predecessor just check if there is a place, the machine is up and the predecessor has an entity to dispose
if(len(self.previous)==1):
return self.Up and len(self.Res.activeQ)==0 and self.previous[0].haveToDispose()
isRequested=False
maxTimeWaiting=0
#loop through the predecessors to see which have to dispose and which is the one blocked for longer
for i in range(len(self.previous)):
if(self.previous[i].haveToDispose()):
isRequested=True
#timeWaiting=now()-(self.previous[i].timeLastEntityEnded+self.previous[i].downTimeInTryingToReleaseCurrentEntity)
isRequested=True
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):
if(timeWaiting>=maxTimeWaiting):
self.predecessorIndex=i
maxTimeWaiting=timeWaiting
return len(self.Res.activeQ)<self.capacity and isRequested
......@@ -244,6 +246,7 @@ class Machine(Process):
#checks if the Machine can dispose an entity to the following object
def haveToDispose(self):
#if we have only one successor just check if machine waits to dispose and also is up
if(len(self.next)==1):
return len(self.Res.activeQ)>0 and self.waitToDispose and self.Up
......@@ -278,22 +281,14 @@ class Machine(Process):
#removes an entity from the Machine
def removeEntity(self):
#the time of blockage is derived from the whole time in the machine minus the processing time and the failure time
#self.totalBlockageTime+=(now()-self.timeLastEntityEntered)-(self.processingTimeOfCurrentEntity+self.downTimeInCurrentEntity)
#print (now()-self.timeLastEntityEntered)-(self.processingTimeOfCurrentEntity+self.downTimeInCurrentEntity)
#print self.downTimeInCurrentEntity
self.timeLastEntityLeft=now()
self.outputTrace("releases "+self.objName)
self.waitToDispose=False
self.Res.activeQ.pop(0)
self.downTimeInTryingToReleaseCurrentEntity=0
#self.outputTrace("got blocked in M"+str(self.id)+" for "
# +str(self.totalBlockageTime))
#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[self.predecessorIndex].Res.activeQ[0]) #get the entity from the predecessor
self.previous[self.predecessorIndex].removeEntity()
......
......@@ -21,8 +21,8 @@ class Queue(Process):
self.id=id
self.objName=name
self.capacity=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.nameLastEntityEntered="" #keeps the name of the last entity that entered in the object
self.timeLastEntityEntered=0 #keeps the time of the last entity that entered in the object
self.next=[] #list with the next objects in the flow
self.previous=[] #list with the previous objects in the flow
......@@ -34,7 +34,7 @@ class Queue(Process):
def initialize(self):
Process.__init__(self)
self.Res=Resource(self.capacity)
self.Up=True #Boolean that shows if the machine is in failure ("Down") or not ("up")
self.Up=True #Boolean that shows if the object is in failure ("Down") or not ("up")
self.currentEntity=None
self.totalBlockageTime=0 #holds the total blockage time
......@@ -43,21 +43,21 @@ class Queue(Process):
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.timeLastEntityEnded=0 #holds the last time that an entity ended processing in the object
self.nameLastEntityEnded="" #holds the name of the last entity that ended processing in the object
self.timeLastEntityEntered=0 #holds the last time that an entity entered in the object
self.nameLastEntityEntered="" #holds the name of the last entity that entered in the object
self.timeLastFailure=0 #holds the time that the last failure of the object started
self.timeLastFailureEnded=0 #holds the time that the last failure of the object 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
self.downTimeInTryingToReleaseCurrentEntity=0 #holds the time that the object 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.downTimeInCurrentEntity=0 #holds the total time that the object was down while holding current entity
self.timeLastEntityLeft=0 #holds the last time that an entity left the object
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
self.waitToDispose=False #shows if the object waits to dispose an entity
def run(self):
while 1:
......@@ -81,6 +81,7 @@ class Queue(Process):
#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.
def canAccept(self):
#if we have only one predecessor just check if there is a place available
if(len(self.previous)==1):
return len(self.Res.activeQ)<self.capacity
......@@ -106,6 +107,7 @@ class Queue(Process):
#it checks also who called it and returns TRUE only to the successor that will give the entity.
#this is kind of slow I think got to check
def haveToDispose(self):
#if we have only one successor just check if the Queue holds one or more entities
if(len(self.next)==1):
return len(self.Res.activeQ)>0
......@@ -141,23 +143,24 @@ class Queue(Process):
#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 we have only one predecessor just check if there is a place available and the predecessor has an entity to dispose
if(len(self.previous)==1):
return len(self.Res.activeQ)<self.capacity and self.previous[0].haveToDispose()
isRequested=False
maxTimeWaiting=0
#loop through the predecessors to see which have to dispose and which is the one blocked for longer
for i in range(len(self.previous)):
if(self.previous[i].haveToDispose()):
isRequested=True
#timeWaiting=now()-(self.previous[i].timeLastEntityEnded+self.previous[i].downTimeInTryingToReleaseCurrentEntity)
isRequested=True
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):
if(timeWaiting>=maxTimeWaiting):
self.predecessorIndex=i
maxTimeWaiting=timeWaiting
return len(self.Res.activeQ)<self.capacity and isRequested
......
......@@ -40,7 +40,7 @@ class Source(Process):
self.Res.activeQ=[]
self.Res.waitQ=[]
self.Up=True #Boolean that shows if the machine is in failure ("Down") or not ("up")
self.Up=True #Boolean that shows if the object is in failure ("Down") or not ("up")
self.currentEntity=None
self.totalBlockageTime=0 #holds the total blockage time
......@@ -49,21 +49,21 @@ class Source(Process):
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
self.timeLastEntityEnded=0 #holds the last time that an entity ended processing in the object
self.nameLastEntityEnded="" #holds the name of the last entity that ended processing in the object
self.timeLastEntityEntered=0 #holds the last time that an entity entered in the object
self.nameLastEntityEntered="" #holds the name of the last entity that entered in the object
self.timeLastFailure=0 #holds the time that the last failure of the object started
self.timeLastFailureEnded=0 #holds the time that the last failure of the object Ended
self.downTimeProcessingCurrentEntity=0 #holds the time that the object was down while processing the current entity
self.downTimeInTryingToReleaseCurrentEntity=0 #holds the time that the object 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.downTimeInCurrentEntity=0 #holds the total time that the object was down while holding current entity
self.timeLastEntityLeft=0 #holds the last time that an entity left the object
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
self.waitToDispose=False #shows if the object 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