#!/usr/bin/env python # coding: utf-8 # **SimPy** is a process-based discrete-event simulation framework based on standard Python. Its event dispatcher is based on the time of events and the processes it contains. It provides the modeller with components of a simulation model, including processes, for active components like vehicles or customers, and resources, for passive components like servers or counters. SimPy also provides monitors to aid in understanding the model. # **Features of SimPy:** # - Processes: SimPy has a built-in concept of processes, which are the active components of a simulation. They can be used to model active entities like customers, vehicles, or messages. # - Events: SimPy uses events to schedule processes. Events are triggered at a specific time and can be used to model interactions between processes. # - Resources: SimPy provides resources, which are used to model passive components like servers, counters, or channels. Resources can be used by processes and can be limited in their capacity. # - Monitors: SimPy provides monitors, which are used to observe and analyze the simulation. Monitors can be used to collect data on processes, resources, and events. # - Randomness: SimPy has built-in support for randomness, which is essential for simulation models. It uses the Mersenne Twister random number generator. # - Easy to Learn: SimPy is built on top of Python and uses a syntax that is easy to learn, even for those without prior experience with simulation or Python. # - Fast: SimPy is fast and can handle large simulations with millions of events. # - Extensive Libraries: SimPy has extensive libraries for various domains like manufacturing, healthcare, and logistics. # - Visualization: SimPy provides tools for visualization, which can be used to visualize the simulation and insights. # # **To install:** # > pip intall simpy # In[3]: import simpy # In[4]: print('simpy version: ' + simpy.__version__) # In[7]: class Car(object): ''' stop and drive the car ''' def __init__(self, env): # reference to current simulation environment self.env = env # Start the park_and_drive process everytime an instance is created self.action = env.process(self.park_and_drive()) def park_and_drive(self): while True: print('Start parking at %d' % self.env.now) parking_duration = 5 yield self.env.timeout(parking_duration) print('Start driving at %d' % self.env.now) trip_duration = 2 yield self.env.timeout(trip_duration) # create an environment env = simpy.Environment() # create an instance of the Car class # add car process to the environment car = Car(env) # start simulation # run for 15 seconds (note the number could mean anything, i.e. seconds/hours/days/years/etc.) env.run(until=15) # # Resources # # * [SimPY Tutorial](https://simpy.readthedocs.io/en/latest/simpy_intro/basic_concepts.html) #

This tutorial was created by HEDARO