Commit 00b79844 authored by Georgios Dagkakis's avatar Georgios Dagkakis Committed by Sebastien Robin

documentation updated with examples. also code refined in some places and older documents removed

parent 73cfd6a0
No preview for this file type
......@@ -37,17 +37,17 @@ from CoreObject import CoreObject
class Assembly(CoreObject):
#initialize the object
def __init__(self, id, name, dist, time):
def __init__(self, id, name, distribution='Fixed', mean=1, stdev=0.1, min=0, max=5):
Process.__init__(self)
self.id=id
self.objName=name
self.type="Assembly" #String that shows the type of object
self.distType=dist #the distribution that the procTime follows
self.distType=distribution #the distribution that the procTime follows
self.rng=RandomNumberGenerator(self, self.distType)
self.rng.avg=time[0]
self.rng.stdev=time[1]
self.rng.min=time[2]
self.rng.max=time[3]
self.rng.avg=mean
self.rng.stdev=stdev
self.rng.min=min
self.rng.max=max
self.next=[] #list with the next objects in the flow
self.previous=[] #list with the previous objects in the flow
self.previousPart=[] #list with the previous objects that send parts
......@@ -107,7 +107,7 @@ class Assembly(CoreObject):
#and one "frame" predecessor requests it
self.getEntity("Frame") #get the Frame
for i in range(self.Res.activeQ[0].numOfParts): #this loop will be carried until the Frame is full with the parts
for i in range(self.Res.activeQ[0].capacity): #this loop will be carried until the Frame is full with the parts
yield waituntil, self, self.isRequestedFromPart #wait until a part is requesting for the assembly
self.getEntity("Part")
......
......@@ -38,16 +38,16 @@ from CoreObject import CoreObject
class Dismantle(CoreObject):
#initialize the object
def __init__(self, id, name, dist, time):
def __init__(self, id, name, distribution='Fixed', mean=1, stdev=0.1, min=0, max=5):
self.id=id
self.objName=name
self.type="Dismantle" #String that shows the type of object
self.distType=dist #the distribution that the procTime follows
self.distType=distribution #the distribution that the procTime follows
self.rng=RandomNumberGenerator(self, self.distType)
self.rng.avg=time[0]
self.rng.stdev=time[1]
self.rng.min=time[2]
self.rng.max=time[3]
self.rng.avg=mean
self.rng.stdev=stdev
self.rng.min=min
self.rng.max=max
self.previous=[] #list with the previous objects in the flow
self.previousIds=[] #list with the ids of the previous objects in the flow
self.nextPart=[] #list with the next objects that receive parts
......@@ -164,8 +164,7 @@ class Dismantle(CoreObject):
self.Res.activeQ.append(self.previous[0].Res.activeQ[0]) #get the frame from the predecessor
self.previous[0].removeEntity()
#append also the parts in the res so that they can be popped
for i in range(self.Res.activeQ[0].numOfParts):
#self.Res.activeQ.append(self.Res.activeQ[0].Res.activeQ[self.Res.activeQ[0].numOfParts-1-i])
for i in range(self.Res.activeQ[0].capacity):
self.Res.activeQ.append(self.Res.activeQ[0].Res.activeQ[i])
self.Res.activeQ[0].Res.activeQ=[]
self.Res.activeQ.append(self.Res.activeQ[0])
......
from SimPy.Simulation import simulate, activate, initialize
from simulation.Machine import Machine
from simulation.Source import Source
from simulation.Exit import Exit
from simulation.Part import Part
from simulation.Frame import Frame
from simulation.Assembly import Assembly
from simulation.Globals import G
#define the objects of the model
Frame.capacity=4
Sp=Source('SP','Parts', mean=0.5, item=Part)
Sf=Source('SF','Frames', mean=2, item=Frame)
M=Machine('M','Machine', mean=0.25, failureDistribution='Fixed', MTTF=60, MTTR=5)
A=Assembly('A','Assembly', mean=2)
E=Exit('E1','Exit')
G.ObjList=[Sp,Sf,M,A,E] #add all the objects in G.ObjList so that they can be easier accessed later
#define predecessors and successors for the objects
Sp.defineRouting([A])
Sf.defineRouting([A])
A.defineRouting([Sp,Sf],[M])
M.defineRouting([A],[E])
E.defineRouting([M])
initialize() #initialize the simulation (SimPy method)
#initialize all the objects
for object in G.ObjList:
object.initialize()
#activate all the objects
for object in G.ObjList:
activate(object, object.run())
G.maxSimTime=1440.0 #set G.maxSimTime 1440.0 minutes (1 day)
simulate(until=G.maxSimTime) #run the simulation
#carry on the post processing operations for every object in the topology
for object in G.ObjList:
object.postProcessing(G.maxSimTime)
#print the results
print "the system produced", E.numOfExits, "frames"
print "the working ratio of", A.objName, "is", (A.totalWorkingTime/G.maxSimTime)*100, "%"
from SimPy.Simulation import simulate, activate, initialize, infinity
from simulation.Machine import Machine
from simulation.Queue import Queue
from simulation.Source import Source
from simulation.Exit import Exit
from simulation.Part import Part
from simulation.Globals import G
#define the objects of the model
S=Source('S','Source', mean=0.5, item=Part)
Q=Queue('Q','Queue', capacity=infinity)
M1=Machine('M1','Milling1', mean=0.25, failureDistribution='Fixed', MTTF=60, MTTR=5)
M2=Machine('M2','Milling2', mean=0.25)
E=Exit('E1','Exit')
G.ObjList=[S,Q,M1,M2,E] #add all the objects in G.ObjList so that they can be easier accessed later
#define predecessors and successors for the objects
S.defineRouting([Q])
Q.defineRouting([S],[M1,M2])
M1.defineRouting([Q],[E])
M2.defineRouting([Q],[E])
E.defineRouting([M1,M2])
initialize() #initialize the simulation (SimPy method)
#initialize all the objects
for object in G.ObjList:
object.initialize()
#activate all the objects
for object in G.ObjList:
activate(object, object.run())
G.maxSimTime=1440.0 #set G.maxSimTime 1440.0 minutes (1 day)
simulate(until=G.maxSimTime) #run the simulation
#carry on the post processing operations for every object in the topology
for object in G.ObjList:
object.postProcessing(G.maxSimTime)
#print the results
print "the system produced", E.numOfExits, "parts"
print "the working ratio of", M1.objName, "is", (M1.totalWorkingTime/G.maxSimTime)*100, "%"
print "the working ratio of", M2.objName, "is", (M2.totalWorkingTime/G.maxSimTime)*100, "%"
from SimPy.Simulation import simulate, activate, initialize, infinity
from simulation.Machine import Machine
from simulation.Queue import Queue
from simulation.Source import Source
from simulation.Exit import Exit
from simulation.Part import Part
from simulation.Globals import G
#the custom queue
class SelectiveQueue(Queue):
def haveToDispose(self,callerObject=None):
caller=callerObject
#if the caller is Milling1 then we return true if there are parts queued
if caller.id=='M1':
return len(self.getActiveObjectQueue())>0
#if the caller is Milling2 then we have to check Milling1's condition.
#we return true if there are parts queued AND Milling1 cannot accept them
self.M1=None
if caller.id=='M2':
#loop through the objects to identify Milling1
for object in G.ObjList:
if object.id=='M1':
self.M1=object
#check Queue's status and also if Milling1 can accept
return len(self.getActiveObjectQueue())>0 and (not (self.M1.canAccept()))
#define the objects of the model
S=Source('S','Source', mean=0.5, item=Part)
Q=SelectiveQueue('Q','Queue', capacity=infinity) #Q is now of type SelectiveQueue
M1=Machine('M1','Milling1', mean=0.25, failureDistribution='Fixed', MTTF=60, MTTR=5)
M2=Machine('M2','Milling2', mean=0.25)
E=Exit('E1','Exit')
G.ObjList=[S,Q,M1,M2,E] #add all the objects in G.ObjList so that they can be easier accessed later
#define predecessors and successors for the objects
S.defineRouting([Q])
Q.defineRouting([S],[M1,M2])
M1.defineRouting([Q],[E])
M2.defineRouting([Q],[E])
E.defineRouting([M1,M2])
initialize() #initialize the simulation (SimPy method)
#initialize all the objects
for object in G.ObjList:
object.initialize()
#activate all the objects
for object in G.ObjList:
activate(object, object.run())
G.maxSimTime=1440.0 #set G.maxSimTime 1440.0 minutes (1 day)
simulate(until=G.maxSimTime) #run the simulation
#carry on the post processing operations for every object in the topology
for object in G.ObjList:
object.postProcessing(G.maxSimTime)
#print the results
print "the system produced", E.numOfExits, "parts"
print "the working ratio of", M1.objName, "is", (M1.totalWorkingTime/G.maxSimTime)*100, "%"
print "the working ratio of", M2.objName, "is", (M2.totalWorkingTime/G.maxSimTime)*100, "%"
from SimPy.Simulation import simulate, activate, initialize, infinity, now
from simulation.Machine import Machine
from simulation.Queue import Queue
from simulation.Source import Source
from simulation.Exit import Exit
from simulation.Part import Part
from simulation.Globals import G
#the custom queue
class SelectiveQueue(Queue):
def haveToDispose(self,callerObject=None):
caller=callerObject
if caller.id=='M1':
return len(self.getActiveObjectQueue())>0
self.M1=None
if caller.id=='M2':
for object in G.ObjList:
if object.id=='M1':
self.M1=object
return len(self.getActiveObjectQueue())>0 and (not (self.M1.canAccept()))
#the custom machine
class Milling(Machine):
def getEntity(self):
Machine.getEntity(self) #call the parent method to get the entity
part=self.getActiveObjectQueue()[0] #retrieve the obtained part
part.machineId=self.id #create an attribute to the obtained part and give it the value of the object's id
#the custom exit
class CountingExit(Exit):
def getEntity(self):
part=self.getGiverObjectQueue()[0] #find the part to be obtained
Exit.getEntity(self) #call the parent method to get the entity
#check the attribute and update the counters accordingly
if part.machineId=='M1':
G.NumM1+=1
elif part.machineId=='M2':
G.NumM2+=1
#define the objects of the model
S=Source('S','Source', mean=0.5, item=Part)
Q=SelectiveQueue('Q','Queue', capacity=infinity)
M1=Milling('M1','Milling1', mean=0.25, failureDistribution='Fixed', MTTF=60, MTTR=5)
M2=Milling('M2','Milling2', mean=0.25)
E=CountingExit('E1','Exit')
G.ObjList=[S,Q,M1,M2,E] #add all the objects in G.ObjList so that they can be easier accessed later
#create the global variables
G.NumM1=0
G.NumM2=0
#define predecessors and successors for the objects
S.defineRouting([Q])
Q.defineRouting([S],[M1,M2])
M1.defineRouting([Q],[E])
M2.defineRouting([Q],[E])
E.defineRouting([M1,M2])
initialize() #initialize the simulation (SimPy method)
#initialize all the objects
for object in G.ObjList:
object.initialize()
#activate all the objects
for object in G.ObjList:
activate(object, object.run())
G.maxSimTime=1440.0 #set G.maxSimTime 1440.0 minutes (1 day)
simulate(until=G.maxSimTime) #run the simulation
#carry on the post processing operations for every object in the topology
for object in G.ObjList:
object.postProcessing(G.maxSimTime)
#print the results
print "the system produced", E.numOfExits, "parts"
print "the working ratio of", M1.objName, "is", (M1.totalWorkingTime/G.maxSimTime)*100, "%"
print "the working ratio of", M2.objName, "is", (M2.totalWorkingTime/G.maxSimTime)*100, "%"
print M1.objName, "produced", G.NumM1, "parts"
print M2.objName, "produced", G.NumM2, "parts"
'''
Created on 14 Oct 2013
@author: George
'''
from SimPy.Simulation import simulate, activate, initialize
from dream.simulation.Machine import Machine
from dream.simulation.Source import Source
from dream.simulation.Exit import Exit
from dream.simulation.Part import Part
from dream.simulation.Globals import G
from dream.simulation.Entity import Entity
from dream.simulation.CoreObject import CoreObject
from random import Random
from simulation.Machine import Machine
from simulation.Source import Source
from simulation.Exit import Exit
from simulation.Part import Part
from simulation.Globals import G
#define the objects of the model
S=Source('S1','Source',distribution='Fixed', mean=0.5, item=Part)
M=Machine('M1','Machine',distribution='Fixed', mean=0.25)
M=Machine('M1','Machine', mean=0.25)
E=Exit('E1','Exit')
G.ObjList=[S,M,E] #add all the objects in G.ObjList so that they can be easier accessed later
......@@ -46,4 +37,4 @@ for object in G.ObjList:
#print the results
print "the system produced", E.numOfExits, "parts"
print "the total working ration of the Machine is", (M.totalWorkingTime/G.maxSimTime)*100, "%"
print "the total working ratio of the Machine is", (M.totalWorkingTime/G.maxSimTime)*100, "%"
from SimPy.Simulation import simulate, activate, initialize
from simulation.Machine import Machine
from simulation.Source import Source
from simulation.Exit import Exit
from simulation.Part import Part
from simulation.Repairman import Repairman
from simulation.Queue import Queue
from simulation.Globals import G
#define the objects of the model
R=Repairman('R1', 'Bob')
S=Source('S1','Source', mean=0.5, item=Part)
M1=Machine('M1','Machine1', mean=0.25, failureDistribution='Fixed', MTTF=60, MTTR=5, repairman=R)
Q=Queue('Q1','Queue')
M2=Machine('M2','Machine2', mean=1.5, failureDistribution='Fixed', MTTF=40, MTTR=10,repairman=R)
E=Exit('E1','Exit')
G.ObjList=[S,M1,M2,E,Q] #add all the objects in G.ObjList so that they can be easier accessed later
#define predecessors and successors for the objects
S.defineRouting([M1])
M1.defineRouting([S],[Q])
Q.defineRouting([M1],[M2])
M2.defineRouting([Q],[E])
E.defineRouting([M2])
initialize() #initialize the simulation (SimPy method)
#initialize all the objects
R.initialize()
for object in G.ObjList:
object.initialize()
#activate all the objects
for object in G.ObjList:
activate(object, object.run())
G.maxSimTime=1440.0 #set G.maxSimTime 1440.0 minutes (1 day)
simulate(until=G.maxSimTime) #run the simulation
#carry on the post processing operations for every object in the topology
for object in G.ObjList:
object.postProcessing(G.maxSimTime)
R.postProcessing(G.maxSimTime)
#print the results
print "the system produced", E.numOfExits, "parts"
print "the blockage ratio of", M1.objName, "is", (M1.totalBlockageTime/G.maxSimTime)*100, "%"
print "the working ratio of", R.objName,"is", (R.totalWorkingTime/G.maxSimTime)*100, "%"
\ No newline at end of file
from SimPy.Simulation import simulate, activate, initialize
from simulation.Machine import Machine
from simulation.Source import Source
from simulation.Exit import Exit
from simulation.Part import Part
from simulation.Repairman import Repairman
from simulation.Queue import Queue
from simulation.Globals import G
#define the objects of the model
R=Repairman('R1', 'Bob')
S=Source('S1','Source', mean=0.5, item=Part)
M1=Machine('M1','Machine1', distribution='Normal', mean=0.25, stdev=0.1, min=0.1, max=1, failureDistribution='Fixed', MTTF=60, MTTR=5, repairman=R)
Q=Queue('Q1','Queue')
M2=Machine('M2','Machine2', distribution='Normal', mean=1.5, stdev=0.3, min=0.5, max=5, failureDistribution='Fixed', MTTF=40, MTTR=10,repairman=R)
E=Exit('E1','Exit')
G.ObjList=[S,M1,M2,E,Q] #add all the objects in G.ObjList so that they can be easier accessed later
#define predecessors and successors for the objects
S.defineRouting([M1])
M1.defineRouting([S],[Q])
Q.defineRouting([M1],[M2])
M2.defineRouting([Q],[E])
E.defineRouting([M2])
G.maxSimTime=1440.0 #set G.maxSimTime 1440.0 minutes (1 day)
G.numberOfReplications=10 #set 10 replications
G.confidenceLevel=0.99 #set the confidence level. 0.99=99%
#run the replications
for i in range(G.numberOfReplications):
G.seed+=1 #increment the seed so that we get different random numbers in each run.
initialize() #initialize the simulation (SimPy method)
#initialize all the objects
R.initialize()
for object in G.ObjList:
object.initialize()
#activate all the objects
for object in G.ObjList:
activate(object, object.run())
simulate(until=G.maxSimTime) #run the simulation
#carry on the post processing operations for every object in the topology
for object in G.ObjList:
object.postProcessing(G.maxSimTime)
R.postProcessing(G.maxSimTime)
#output data to excel for every object
for object in G.ObjList:
object.outputResultsXL(G.maxSimTime)
R.outputResultsXL(G.maxSimTime)
G.outputFile.save("output.xls")
......@@ -33,12 +33,12 @@ from Entity import Entity
#The entity object
class Frame(Entity):
type="Frame"
numOfParts=4 #the number of parts that the frame can take
capacity=4 #the number of parts that the frame can take
def __init__(self, name):
Entity.__init__(self, name)
self.Res=Resource(self.numOfParts)
self.Res=Resource(self.capacity)
#dimension data
self.width=2.0
self.height=2.0
......
......@@ -260,7 +260,7 @@ def createObjects():
stdev=float(processingTime.get('stdev', '0'))
min=float(processingTime.get('min', '0'))
max=float(processingTime.get('max', '0'))
A=Assembly(id, name, distributionType, [mean,stdev,min,max])
A=Assembly(id, name, distribution=distributionType, mean=mean,stdev=stdev,min=min,max=max)
A.nextIds=getSuccessorList(id)
G.AssemblyList.append(A)
G.ObjList.append(A)
......@@ -274,7 +274,7 @@ def createObjects():
stdev=float(processingTime.get('stdev', '0'))
min=float(processingTime.get('min', '0'))
max=float(processingTime.get('max', '0'))
D=Dismantle(id, name, distributionType, [mean,stdev,min,max])
D=Dismantle(id, name, distribution=distributionType, mean=mean,stdev=stdev,min=min,max=max)
D.nextPartIds=getSuccessorList(id, lambda source, destination, edge_data: edge_data.get('entity') == 'Part')
D.nextFrameIds=getSuccessorList(id, lambda source, destination, edge_data: edge_data.get('entity') == 'Frame')
D.nextIds=getSuccessorList(id)
......
......@@ -38,7 +38,7 @@ import scipy.stats as stat
class Machine(CoreObject):
#initialize the id the capacity, of the resource and the distribution
def __init__(self, id, name, capacity=1, distribution='Fixed', mean=1, stdev=0, min=0, max=10, failureDistribution='No', MTTF=0, MTTR=0, availability=0, repairman=None):
def __init__(self, id, name, capacity=1, distribution='Fixed', mean=1, stdev=0, min=0, max=10, failureDistribution='No', MTTF=0, MTTR=0, availability=0, repairman='None'):
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
......
......@@ -34,7 +34,7 @@ from ObjectResource import ObjectResource
#the resource that repairs the machines
class Repairman(ObjectResource):
def __init__(self, id, name, capacity):
def __init__(self, id, name, capacity=1):
self.id=id
self.objName=name
self.capacity=capacity #repairman is an instance of resource
......
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