<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Linnart Felkl</title>
    <description>The latest articles on DEV Community by Linnart Felkl (@linnartsf).</description>
    <link>https://dev.to/linnartsf</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F957070%2Fdfd37523-4c28-4a62-ad98-5839494dd47a.png</url>
      <title>DEV Community: Linnart Felkl</title>
      <link>https://dev.to/linnartsf</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/linnartsf"/>
    <language>en</language>
    <item>
      <title>Assembly line simulation in Python</title>
      <dc:creator>Linnart Felkl</dc:creator>
      <pubDate>Sat, 17 Dec 2022 19:25:35 +0000</pubDate>
      <link>https://dev.to/linnartsf/assembly-line-simulation-in-python-3e8k</link>
      <guid>https://dev.to/linnartsf/assembly-line-simulation-in-python-3e8k</guid>
      <description>&lt;p&gt;In simulation engineering for production and supply chain planning I encounter many commercial simulation tools and commercial software licenses. But, as I have pointed out frequently, supply chain analysts and operationan excellence managers must not rely on commercial tools. This is especially true for smaller project scopes and simple animation requirements. &lt;/p&gt;

&lt;h2&gt;
  
  
  Exemplary assembly simulation tool
&lt;/h2&gt;

&lt;p&gt;Below is a screenshot from a assembly line simulation and animation that I implemented in Python using SimPy and Tkinter.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mD39PkXS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b3jrvdp43wa535rw0fkk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mD39PkXS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b3jrvdp43wa535rw0fkk.png" alt="Image description" width="880" height="495"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The upper manufacturing line operates at a higher throughput rate and shorter cycle time, operating nearly at twice the speed of the lower assembly line with integrated part manufacturing.&lt;/p&gt;

&lt;p&gt;Machine 24 produces parts that are then inspected in-line. Parts are then automatically collected in a container that, once full, is stored on a pallet. The pallet acts as a buffer since part manufacturing on machine 24 operates at a (significantly) shorter cycle time than part manufacturing on machine 57.&lt;/p&gt;

&lt;p&gt;Machine 57 produces base parts onto which parts produced by machine 24 are assembled. Some other smaller parts are assembled onto the base parts first, happening in line and without delaying the cycle time of machine 57. Parts used for assembly, manufactured at machine 24 are then assembled onto the base part. The assembly is then placed into the foil machine where it is foiled and subsequently packaged into boxes. These boxes are then stacked onto pallets and eventually shipped to the customer. When the buffer pallet at the end of machine line 24 is full, machine 24 is shut down and the parts buffered onto the pallet are now used for the assembly operation on the lower assembly line.&lt;/p&gt;

&lt;h2&gt;
  
  
  Technology stack used for assembly line simulation
&lt;/h2&gt;

&lt;p&gt;The assembly line simulator is a Python tool and developed as a Python framework that consumes existing Python frameworks for discrete-event simulation and animation. Most importantly, the framework developed consumes Tkinter and SimPy in Python. SQLite and MySQL databases can be integrated into the tool if desired by the user. For most applications this is however not necessary.&lt;/p&gt;

&lt;p&gt;You can learn more about this tool by reading the following publication: &lt;a href="https://www.supplychaindataanalytics.com/assembly-line-simulation-and-line-balancing/"&gt;SCDA assembly line simulation tool&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Related content
&lt;/h2&gt;

&lt;p&gt;If you are interested in using free tools in Python and R for discrete-event simulation modeling you might want to check out my poultry supply chain simulation example: &lt;a href="https://www.supplychaindataanalytics.com/end-to-end-poultry-supply-chain-simulation/"&gt;End-to-end poultry supply chain simulation&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Agent-based social segregation model</title>
      <dc:creator>Linnart Felkl</dc:creator>
      <pubDate>Sat, 29 Oct 2022 09:33:38 +0000</pubDate>
      <link>https://dev.to/linnartsf/agent-based-social-segregation-model-h27</link>
      <guid>https://dev.to/linnartsf/agent-based-social-segregation-model-h27</guid>
      <description>&lt;p&gt;In this post I will briefly present an agent-based simulation model that can be used for modeling e.g. social segregation. &lt;/p&gt;

&lt;h2&gt;
  
  
  Framework for agent-based models in Python
&lt;/h2&gt;

&lt;p&gt;The framework for modeling agent-based models in Python the abm_framework. I made this framework available on Github. The repository is here: &lt;a href="https://github.com/LinnartSF/abm_framework"&gt;abm_framework&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The repository contains a directory with demo models. The directory is located &lt;a href="https://github.com/LinnartSF/abm_framework/tree/main/demos"&gt;here&lt;/a&gt;. At the time of this post the directory contains a segregation example and a disease spread SIR model example.&lt;/p&gt;

&lt;h2&gt;
  
  
  Model logic and implementation
&lt;/h2&gt;

&lt;p&gt;The code for the model is available &lt;a href="https://github.com/LinnartSF/abm_framework/blob/main/demos/segregation.py"&gt;here&lt;/a&gt;. The model essentially implements the following workflow:&lt;/p&gt;

&lt;p&gt;1) For each iteration one random agent is selected&lt;br&gt;
2) The agent's neighbourhood is collected&lt;br&gt;
3) For every agent of same type the agent's utility increases&lt;br&gt;
4) For every agent that is not of same type utility decreases&lt;br&gt;
5) Up to 10 random empty cells in the grid are collected&lt;br&gt;
6) If the agent's utility would be higher in one of the cells, the first cell with higher utility is assigned as the agent's location (relocation)&lt;/p&gt;

&lt;h2&gt;
  
  
  Simulation results
&lt;/h2&gt;

&lt;p&gt;Below is an animation of the simulation run, showing the segregation process.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--kmW3zRDr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xt611s356jtv92igwkcs.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kmW3zRDr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xt611s356jtv92igwkcs.gif" alt="Image description" width="640" height="480"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Another animation, shown below, shows agent utility density distribution.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--aHi_FOpj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bs13yqg1di6p36defjzq.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--aHi_FOpj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bs13yqg1di6p36defjzq.gif" alt="Image description" width="640" height="480"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  References to related agent-based simulation content
&lt;/h2&gt;

&lt;p&gt;If you are interested in agent-based modeling and simulation you can also look at some other simple examples that I have published:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.supplychaindataanalytics.com/agent-based-sir-model-python-example/"&gt;Agent-based SIR model in Python&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.supplychaindataanalytics.com/agent-based-segregation-model-python/"&gt;Agent-based segregation model in Python&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    <item>
      <title>Agent-based disease spread model in Python</title>
      <dc:creator>Linnart Felkl</dc:creator>
      <pubDate>Fri, 28 Oct 2022 22:51:27 +0000</pubDate>
      <link>https://dev.to/linnartsf/agent-based-disease-spread-model-in-python-8gm</link>
      <guid>https://dev.to/linnartsf/agent-based-disease-spread-model-in-python-8gm</guid>
      <description>&lt;p&gt;In this article I will demonstrate how agent-based modeling can be used to model and investigate disease spread. I will use the &lt;a href="https://github.com/LinnartSF/abm_framework"&gt;abm_framework &lt;/a&gt; in Python to implement an agent-based SIR model in Python. This application was first published here: &lt;a href="https://www.supplychaindataanalytics.com/agent-based-sir-model-python-example/"&gt;Agent-based SIR model (Python)&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Introducing the SIR model
&lt;/h2&gt;

&lt;p&gt;The SIR modeling framework is a popular framework for modeling disease spread. SIR stands for Susceptible, Infected, Recovered. Below figure illustrates the SIR model.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BEW5AVop--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uxcg1z0gtfsz95r92r0w.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BEW5AVop--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uxcg1z0gtfsz95r92r0w.PNG" alt="Image description" width="608" height="224"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For example, anyone in the susceptible state can be infected. Once you are infected you can infect anyone in the susceptible state. The risk of infection can be modelled to be between 0% and 100%. &lt;/p&gt;

&lt;p&gt;Anyone infected will recover with a certain probability. Once you are recovered, you are either resistant or you can fall back in to susceptible mode. Every state transition is described with probability ratios.&lt;/p&gt;

&lt;h2&gt;
  
  
  Introducing agent-based modeling in Python
&lt;/h2&gt;

&lt;p&gt;Agent-based modeling is a popular simulation technique, next to discrete-event simulation, monte-carlo simulation and system dynamics modeling.&lt;/p&gt;

&lt;p&gt;Agent-based models describe agents and their inner attributes and dynamics, as well as the interaction between agents. From this one hopes to study and understand the emergence of complex macroscopic system behaviour.&lt;/p&gt;

&lt;p&gt;I use the abm_framework in Python for implementing agent-based simulation models. Its setup is illustrated in below figure.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zEaHeC5r--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xrj2dc0b0p3v59e6glya.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zEaHeC5r--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xrj2dc0b0p3v59e6glya.PNG" alt="Image description" width="611" height="354"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;model.py&lt;/strong&gt; is the application specific model. It consumes the modules provided by the abm_framework. I implemented the SIR model in Python that way. You can find the code &lt;a href="https://www.supplychaindataanalytics.com/agent-based-sir-model-python-example/"&gt;here&lt;/a&gt;. The model has the following specifications: 5% initial infection, 7% infection risk, 3% recovery chance. Agents interact with a defined neighbourhood, with a fix radius. Infected agents can infect other agents within their limits of that neighbourhood.&lt;/p&gt;

&lt;h2&gt;
  
  
  Simulation results
&lt;/h2&gt;

&lt;p&gt;Below chart summarizes a simulation run with the parameter settings described in previous section.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Rd_dub7J--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2nku102djnxrus905cwo.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Rd_dub7J--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2nku102djnxrus905cwo.PNG" alt="Image description" width="638" height="478"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Recovery and social distancing (limited infection radius) end disease spread. Only 12% of all agents are infected.&lt;/p&gt;

</description>
      <category>python</category>
      <category>simulation</category>
      <category>agentbased</category>
      <category>datascience</category>
    </item>
  </channel>
</rss>
