In this example we will see how to create a model of ManPy objects.
Our model has the following structure:
The first implementation of the model is deterministic.
As values we have the following:First we have to import the appropriate ManPy components:
from dream.simulation.imports import Source, Queue, Machine, Exit
from dream.simulation.Globals import runSimulation
Then, declare the instances of the model
#define the objects of the model
S=Source('S1','Source',interarrivalTime={'distributionType':'Fixed','mean':0.5}, entity='Dream.Part')
Q=Queue('Q1','Queue', capacity=1)
M=Machine('M1','Machine', processingTime={'distributionType':'Fixed','mean':0.25})
E=Exit('E1','Exit')
Note that ManPy time units are decimals. So 30 and 15 seconds have been translated to 0.5 and 0.25 minutes respectively.
Next, we need to define the relationships of the objects, i.e. how they are connected in the model. We do this using the CoreObject.defineRouting method:
#define predecessors and successors for the objects
S.defineRouting(successorList=[Q])
Q.defineRouting(predecessorList=[S],successorList=[M])
M.defineRouting(predecessorList=[Q],successorList=[E])
E.defineRouting(predecessorList=[M])
defineRouting in most CoreObjects gets two lists as arguments (perdecessorList, successorList) with this sequence. In special cases like the Source and the Exit only one list is required.
Now we are ready to run the simulation:
# call the runSimulation giving the objects and the length of the experiment
runSimulation(objectList=[S,Q,M,E], maxSimTime=1440.0)
runSimulation is invoked with tow arguments. A list with all the ManPy simulation objects and the length of the experiment. There are other optional arguments as we will see in other examples.
After the simulation run, we may want to perform calculations on metrics:
# calculate metrics
working_ratio = (M.totalWorkingTime/1440.0)*100
We used the Machine.totalWorkingTime attribute.
Finally, we output the results of the simulation run:
#print the results
print "the system produced", E.numOfExits, "parts"
print "the total working ratio of the Machine is", working_ratio, "%"
Given the simplicity and the deterministic nature of the model, we can establish that the results are valid.
In order to turn the result into stochastic, we will change the declaration of the objects.
Let's say that:#define the objects of the model
S=Source('S1','Source',interarrivalTime={'distributionType':'Exp','mean':0.5}, entity='Dream.Part')
Q=Queue('Q1','Queue', capacity=1)
M=Machine('M1','Machine', processingTime={'distributionType':'Normal','mean':0.25,'stdev':0.5,'min':0,'max':3})
E=Exit('E1','Exit')
The routing will remain the same:
#define predecessors and successors for the objects
S.defineRouting(successorList=[Q])
Q.defineRouting(predecessorList=[S],successorList=[M])
M.defineRouting(predecessorList=[Q],successorList=[E])
E.defineRouting(predecessorList=[M])
Now we can run the simulation. Note that we give the extra argument numberOfReplications=5 (default is 1 replication).
# call the runSimulation giving the objects and the length of the experiment
runSimulation(objectList=[S,Q,M,E], maxSimTime=1440.0, numberOfReplications=5)
Now we print the E.Exits attribute that is a list of the number of exits pre replication.
#print the results
print "Exits per experiment", E.Exits
This result can be used for statistical interference, e.g. calculation of Confidence Intervals.
below is the full code of the examples, so that the user can easier manipulate them.
from dream.simulation.imports import Source, Queue, Machine, Exit
from dream.simulation.Globals import runSimulation
#define the objects of the model
S=Source('S1','Source',interarrivalTime={'distributionType':'Fixed','mean':0.5}, entity='Dream.Part')
Q=Queue('Q1','Queue', capacity=1)
M=Machine('M1','Machine', processingTime={'distributionType':'Fixed','mean':0.25})
E=Exit('E1','Exit')
#define predecessors and successors for the objects
S.defineRouting(successorList=[Q])
Q.defineRouting(predecessorList=[S],successorList=[M])
M.defineRouting(predecessorList=[Q],successorList=[E])
E.defineRouting(predecessorList=[M])
# call the runSimulation giving the objects and the length of the experiment
runSimulation(objectList=[S,Q,M,E], maxSimTime=1440.0)
# calculate metrics
working_ratio = (M.totalWorkingTime/1440.0)*100
#print the results
print "the system produced", E.numOfExits, "parts"
print "the total working ratio of the Machine is", working_ratio, "%"
from dream.simulation.imports import Source, Queue, Machine, Exit
from dream.simulation.Globals import runSimulation
#define the objects of the model
S=Source('S1','Source',interarrivalTime={'distributionType':'Exp','mean':0.5}, entity='Dream.Part')
Q=Queue('Q1','Queue', capacity=1)
M=Machine('M1','Machine', processingTime={'distributionType':'Normal','mean':0.25,'stdev':0.5,'min':0,'max':3})
E=Exit('E1','Exit')
#define predecessors and successors for the objects
S.defineRouting(successorList=[Q])
Q.defineRouting(predecessorList=[S],successorList=[M])
M.defineRouting(predecessorList=[Q],successorList=[E])
E.defineRouting(predecessorList=[M])
# call the runSimulation giving the objects and the length of the experiment
runSimulation(objectList=[S,Q,M,E], maxSimTime=1440.0, numberOfReplications=5)
#print the results
print "Exits per experiment", E.Exits