Job shop simulation with salabim in Python

Following my recent article on job shop simulation in Python with SimPy I was asked to also publish an example covering salabim in Python. SimPy and salabim have similar syntax, with some differences. Both are used for discrete-event simulation (DES) model implementation. SimPy has certainly a larger user base and more third party packages. On the other hand salabim offers so much more functionality out of the box. This means that with salabim there is less need for extra tooling. The functionality provided by salabim includes animation. Animation is very helpful for model verification and validation.

Job shop simulation and animation with salabim

The code below implements the job shop simulation that I recently implemented with SimPy. The code below uses salabim in Python instead. Compare this code with the SimPy example documented here:

The job shop has 2 machines and the production schedule contains 10 jobs. Both machines can be used for processing all jobs, but only one machine can process one job at the time, and a job can only be processed by one machine at the time. Once a job has been processed by one of the machines it is complete.

import salabim as sim

SEED = 42
MACHINES = 2     # amount of machines
INTERVAL = 10.0  # mean time between two jobs
DURATION = 5.0   # mean processing time of a job
JOBS = 10        # number of jobs that have to be completed

class Product(sim.Component):
    def process(self):
        yield self.request(machines)
        print(f"{} started at time {}")
        yield self.hold(DURATION)
        print(f"{} completed at time {}")

env = sim.Environment(random_seed=SEED)
machines = sim.Resource("machines", capacity=MACHINES)
sim.ComponentGenerator(Product, iat=sim.Exponential(INTERVAL), number=JOBS)
machines.claimers().animate(x=500, y=100, title="work in progress")
machines.requesters().animate(x=200, y=100, title="work waiting")

The salabim program documented above not only simulates job execution but also animates work in progress and job queues. Here is the animation created with salabim in Python:

salabim in Python job shop simulation

This completes today’s salabim example.

Other articles related to DES and salabim in Python

Discrete-event simulation (DES) is a method used for e.g. supply chain optimization, factory design, production planning and process improvement in complex systems. Complex systems are e.g. systems with highly dynamic and interdependent behaviour. Simulation is used when analytical methods cannot be applied.

Read the following SCDA articles to learn more about simulation in SCM and production planning, DES, and simulation in Python:

You May Also Like

Leave a Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.