{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "**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. \n", "\r", "**Features of SimPy:**\n", "- 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.\n", "- Events: SimPy uses events to schedule processes. Events are triggered at a specific time and can be used to model interactions between processes.\n", "- 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.\n", "- 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.\n", "- Randomness: SimPy has built-in support for randomness, which is essential for simulation models. It uses the Mersenne Twister random number generator.\n", "- 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.\n", "- Fast: SimPy is fast and can handle large simulations with millions of events.\n", "- Extensive Libraries: SimPy has extensive libraries for various domains like manufacturing, healthcare, and logistics.\n", "- Visualization: SimPy provides tools for visualization, which can be used to visualize the simulation and insights.\n", "\n", "**To install:** \n", "> pip intall simpy" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "import simpy" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "simpy version: 4.1.1\n" ] } ], "source": [ "print('simpy version: ' + simpy.__version__)" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": false, "jupyter": { "outputs_hidden": false } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Start parking at 0\n", "Start driving at 5\n", "Start parking at 7\n", "Start driving at 12\n", "Start parking at 14\n" ] } ], "source": [ "class Car(object):\n", " ''' stop and drive the car '''\n", " def __init__(self, env):\n", " # reference to current simulation environment\n", " self.env = env\n", " \n", " # Start the park_and_drive process everytime an instance is created\n", " self.action = env.process(self.park_and_drive())\n", " \n", " def park_and_drive(self):\n", " while True:\n", " print('Start parking at %d' % self.env.now)\n", " parking_duration = 5\n", " yield self.env.timeout(parking_duration)\n", "\n", " print('Start driving at %d' % self.env.now)\n", " trip_duration = 2\n", " yield self.env.timeout(trip_duration) \n", " \n", "# create an environment \n", "env = simpy.Environment()\n", "\n", "# create an instance of the Car class\n", "# add car process to the environment\n", "car = Car(env)\n", "\n", "# start simulation\n", "# run for 15 seconds (note the number could mean anything, i.e. seconds/hours/days/years/etc.)\n", "env.run(until=15) " ] }, { "cell_type": "markdown", "metadata": { "collapsed": true, "jupyter": { "outputs_hidden": true } }, "source": [ "# Resources \n", "\n", "* [SimPY Tutorial](https://simpy.readthedocs.io/en/latest/simpy_intro/basic_concepts.html)" ] }, { "cell_type": "markdown", "metadata": { "collapsed": true, "jupyter": { "outputs_hidden": true } }, "source": [ "

This tutorial was created by HEDARO

" ] } ], "metadata": { "anaconda-cloud": {}, "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.7" } }, "nbformat": 4, "nbformat_minor": 4 }