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"{self.name()} started at time {env.now()}")
yield self.hold(DURATION)
print(f"{self.name()} completed at time {env.now()}")
env = sim.Environment(random_seed=SEED)
machines = sim.Resource("machines", capacity=MACHINES)
sim.ComponentGenerator(Product, iat=sim.Exponential(INTERVAL), number=JOBS)
env.animate(True)
machines.claimers().animate(x=500, y=100, title="work in progress")
machines.requesters().animate(x=200, y=100, title="work waiting")
env.run(100.0)
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:
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:
- Link: Discrete-event simulation (DES) use cases
- Link: Discrete-event simulation software list
- Link: Discrete-event simulation procedure model
- Link: Machine learning and discrete-event simulation
- Link: Parking lot simulator with simmer in R
- Link: Open-cast mine simulation for better planning
- Link: Visualizing SimPy job shop simulation
- Link: Receival inspection simulation with simmer
- Link: Assembly line simulation and line balancing
- Link: simmer in R for discrete-event simulation
Data scientist focusing on simulation, optimization and modeling in R, SQL, VBA and Python
Leave a Reply