Building a discrete-event model with SimPy
1. Building a discrete-event model with SimPy
We've learned the different methods available in SimPy to create a model and add processes and resources. Now, let's examine the entire model development process and identify the key steps needed to build any type of SimPy model.2. Before we build our model
Before developing a SimPy model, we must understand the dynamic system we want to simulate. This includes clearly defining the objectives of the model and identifying the different processes involved, which can run in parallel or sequence. Once such processes are defined, it is critical to identify the resources that may limit the speed and output of such processes. We learned that the SimPy resources available are resource, container, and store. Once all of these different aspects of the model have been characterized, it is time to define the architecture of the model, identifying the state variables, model workflow and generators required.3. The dynamic system and objectives of the model
In understanding the system we want to model, it is important to identify the critical aspects that modulate its behavior because those are the ones we'll need to include in the model to mimic the real-world system. This also includes identifying the key processes that define the response of the system. A parallel exercise we need to do is around the definition of the objectives of the study, as this will affect how the model is built to respond to them. Discrete-event models are usually used to optimize systems, so we need to identify the aspects we want to optimize, such as perhaps increasing the number of clients, speeding up the production line, or managing resources to optimize resources. Based on the objectives defined for the study, it is important to identify the state variables of the model that are of interest.4. Identify the appropriate SimPy resources
Regarding the identification of the relevant resources to include in a particular application, it is important to recall that SimPy provides different types of resources. Probably the most commonly used is the shared resource with a limited capacity. This is a type of resource that is shared between processes, and it is applicable to represent, for example, tables at a restaurant, machines in a factory, seats in a theatre, and cashiers in a shop. We also have containers for when we need to represent resources that behave like a tank or basket. We can add and remove quantity from containers. Examples of applications of containers include fuel reserves in a gas station and coal reserves in a coal-fired power plant.5. Identify the appropriate SimPy resources
Then we have stores that can be used when there is a resource that behaves like a storage room with multiple items. It has an unlimited capacity for storing new, arbitrary objects. Items in the store will be consumed and produced, and examples include shops selling multiple items, storage rooms of a company, workshops and households.6. Concatenate events using bitwise operators
Finally, SimPy uses bitwise operators to concatenate events. We will not cover all aspects of bitwise operators, only those relevant to SimPy. Python has different types of operators: arithmetic, logical, and comparison operators. Bitwise operators perform bitwise calculations on integers. In other words, they first convert integers into binary before performing operations. They typically expect two operands. In SimPy, this generates a condition event with two events, allowing waiting for both or one of the processes. Relevant for SimPy are bitwise-and and bitwise-or. The first waits for both processes, while the second waits for one of the processes only.7. Let's practice!
Now that we have summarized all the steps and considerations needed to build a SimPy model from scratch, it's time to practice!Create Your Free Account
or
By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.