Bus simulator 2015 pc kickass
Environment create the SimPy environment env.Įnvironment env. I hope you found this tutorial useful! Thoughtlets on software, maths, science and society. While this is still not entirely realistic, it is a bit better than the very first simple bus example.
We can see from the information printed out that the drive times and boarding times have been randomized. There we go! Our first bus simulation completes its stop round in minutes! Admittedly, the logic is a bit borked and unrealistic, but we will work on that shortly. There is no extra logic that needs to be executed. For example, in our simple simulation, from the bus processes perspective boarding commuters is simply an action that takes 10 minutes. The key here, in my opinion, is not to think of the process as being idle ie not doing anything when it is suspended, but to think about it as being in a state where the process itself need not execute any extra logic to complete the event. It might be a bit strange to think about the bus process as suspended when the bus is actually driving or boarding commuters.
Bus simulator 2015 pc kickass generator#
The Process the bus generator function resumes executing once the event has been finished. When a SimPy Process yields an event, the Environment in which the process is running suspends the Process for the duration of the event. Second, notice that we are yielding two timeout events. This is a SimPy Environment object that is in charge of scheduling, starting and suspending SimPy processes the meaning of this will become clear in a moment. There are a few interesting things going on in the bus method. I will show the whole generator function below and then explain how the individual parts of the function work in the context of the SimPy simulation.
Thus to begin our simulation, we will construct a simple Python generator function to represent our bus.
In this blog post series, I am going to give you some introductory examples to help you get started with your own simulations. SimPy offers you an easy way to build these kinds of simulations. For example, you may want to investigate how the number of available checkout machines influences the length of the customer queue at your local supermarket or how the number of bus stops in a crowded neighbourhood affect your morning commute. SimPy is a Python library that allows you to simulate a variety of discrete-event scenarios.