Writing your first ChiPy model - JelleLa/ChiPy GitHub Wiki

This tutorial is based on a TESTING build of ChiPy! Some features used here might not be present in the most recent release!

Model Description

In this ChiPy model, we are going to simulate two workstations linked in series for a certain amount of time, each having a unique process time.

Step 1: Make a project directory

First, we have to make a directory in which we want to place our project. In this example, we call this directory ChiPy.

Step 2: Move the ChiPy package in the project directory

After we made a project directory, the package can be added. Download the latest release from this repository, extract the files and copy over the chipy folder to the project directory.

Step 3: Make a new Python script

Make a new Python script inside the project's directory. In this case, we called it model.py.

Step 4: Import ChiPy in the model

Once we have a script, we can import the package using import. Here, it is chosen to import ChiPy as cp to save some time with typing.

#! usr/bin/python3
# imports
import chipy as cp

Step 5: Initiating the Environment

We need an environment that keeps track of and advances time. We call it env.

# environment
env = cp.environment()

Step 6: Assigning variables

Now we are going to set up the simulation variables. The simulation time is called t, which we set to 60 time units. Next, we assign the process times to the variables te_1 and te_2, both being lambda-functions as required by the chipy.Station class. The same accounts for the inverse of the arrival rate ta.

# variables
t	= 60
te_1 	= lambda: 4
te_2 	= lambda: 2
ta	= lambda: 5

Step 7: Making a stations dictionary

Since we have set all model variables, we can now initiate stations inside a dictionary.

stations = {
"S1": cp.Station(env, te = te_1),
"S2": cp.Station(env, te = te_2)}

Step 8: Writing a Run Environment

The stations in the stations dictionary have to be placed in the desired order in a Run Environment. In this model, the Run Environment is called prodline ("Production Line").

# run environment
def prodline(env, lot, stations) -> None:
	yield env.process(stations["S1"].proc(lot = lot))
	yield env.process(stations["S2"].proc(lot = lot))

Step 9: Initiating a Generator

Now we have a Run Environment to sends lots in, we can make a generator G1 that generates these lots according to the rate of arrival.

# generator
G1 = cp.Generator(env, ta, prodline, stations)

Step 10: Calling the simulation

Note: in release, 20210620, this data IS NOT returned by the cp.simulate method (this is planned for a next release, but is proven to work flawlessly in test builds), but has to be determined manually in the run environment, as done in the thesis.

All parts of the model are written. Now it is time to call the simulation for a time t. The cp.simulate method returns an array of entry times, exit times and lots. Our model saves these as t_in, t_out and lots.

# simulate
t_in, t_out, lots = cp.simulate(env,G1,"Time",t)

Step 11: Post Process the results

After the simulation is done, the data t_in, t_out and lots can be processed with the cp.stats method, to print a simulation summary after simulation. Adding this concludes the model. The script can be saved now.

# print
cp.stats(lots, t_in, t_out, t)

Step 12: Run the simulation

Now the script is saved to the computer's storage, we can call it with python3. Open a terminal in the project directory and run:

python3 model.py

This outputs: