TDS Archive

An archive of data science, data analytics, data engineering, machine learning, and artificial…

Robust Supply Chain Networks with Monte Carlo Simulation

Samir Saci
TDS Archive
Published in
8 min readFeb 12, 2022

--

Supply Chain Networks with Monte Carlo Simulation using Python. Learn how Monte Carlo simulation can help design a robust supply chain network considering demand fluctuations. Supply chain optimization uses data analytics to find the optimal combination of factories and distribution centers to meet customer demand. The challenge is maintaining robustness amid fluctuating demand.
(Image by Author)

Supply chain optimization uses data analytics to find an optimal combination of factories and distribution centres to meet customers' demands.

As a data scientist, how can you support Supply Chain Network Optimization with Python?

The core structure of many software and solutions in the market is a Linear Programming Model.

Some of these models find the proper allocation of factories to meet the demand and minimize the costs, assuming a constant demand.

What happens if the demand is fluctuating?

Your network may lose robustness, especially if the demand is seasonal (e-commerce, cosmetics, fast fashion).

In this article, we will develop a straightforward methodology for designing a Robust Supply Chain Network using Monte Carlo simulation with Python.

SUMMARY
I. Supply Chain Network Design
Find the right allocation of factories to meet a global demand
II. Problem Statement
What happens if your demand is fluctuating?
1. Limits of the initial solution
Understand the robustness of the initial solution
2. Methodology of simulation
Simulate 50 scenarios based on a normal distribution of the demand
3. Analyze the results
What are the different combinations of solutions?
4. Final Solution
The most robust combination?
III. Conclusion & Next Steps
1. Move Towards a Sustainable Supply Chain
Implement objective functions aiming to reduce carbon footprint
2. #GenAI: Improve the User Interface with GPT
A GPT agent that would answer questions using the simulation model
3. Automate PowerPoint Report Generation with Python
Share your insights in a slides generated automatically with Python

Methodology of Supply Chain Network Design

Global Supply Chain Network

As the Head of Supply Chain Management of an international manufacturing company, your boss wants to redefine the Supply Chain Network for the next five years.

Two world maps. The first map shows sales volumes per market, highlighting five regions (USA, Germany, Japan, India, Brazil) and their demand levels. The second map displays supplier locations in five countries with icons for factory capacity, fixed costs, and variable costs, helping visualize the global supply chain network.
Supply Chain Network Problem — (Image by Author)

How can you support her with data analytics?

Demand
It starts with the demand from your customers in 5 different markets (Brazil, USA, Germany, India and Japan).

A circular pie chart representing the distribution of demand across five markets for the supply chain network optimization problem. The largest segment is blue, representing the USA with 57.2% of total demand, followed by a green segment representing another market with 34.7%. Smaller slices represent other markets, each with a percentage below 5%.
Demand in Million Units/Month — (Image by Author)

US market is driving more than half of the demand.

Supply Capacity
You can open factories in the five markets. There is a choice between low and high-capacity facilities.

A grouped bar chart showing the number of low and high-capacity factories across five different regionsfor the supply chain network optimization problem. Each region is represented by a pair of bars: one blue bar for low capacity and one red bar for high capacity. The high-capacity factories consistently have taller bars, indicating a greater number compared to the low-capacity factories.
(Image by Author)

Example: Low Capacity factories in the USA can produce 500,000 units/month.

Fixed Costs
If you open a facility you have fixed costs to add to your budget (Electricity, Real Estate, CAPEX, …).

A bar chart showing the fixed costs for low and high-capacity factories in different regionsfor the supply chain network optimization problem. Orange bars represent high-capacity factories, while red bars represent low-capacity factories. High-capacity factories in some regions have significantly higher fixed costs compared to low-capacity ones.
(Image by Author)

High-capacity plants in India have lower fixed costs than low-capacity plants in the USA.

Variable Costs

A bar chart displaying variable costs associated with production in different regions for the supply chain network optimization problem. Each bar represents a region, with varying heights indicating different levels of variable costs, from the highest to the lowest across the regions.
(Image by Author)

Fixed Costs + Variable Costs = Total Costs of Production

Freight Costs
Costs to ship a container from Country XXX to Country YYY.

A table showing the freight costs of shipping containers between different countries. The rows and columns are labeled with country names: USA, Germany, Japan, Brazil, and India. The cells display the freight cost from the row country to the column country. For example, the cost to ship from the USA to Brazil is 16,100, while the cost from Germany to Brazil is 20,244. Diagonal cells are marked with 0, indicating no cost for shipping within the same country.
Freight Costs ($/Container) — (Image by Author)

Total Cost

A flowchart illustrating the production and freight costs from two countries (USA and India) to the USA market. It shows fixed and variable production costs and variable sea freight costs, emphasizing the cost of delivering 2.5 million units per month to the USA.
(Image by Author)

The total cost to produce and ship products to the market.

Based on the demand of the markets, where do I need to open factories?

Linear Programming Model

This classic linear programming problem has objective functions, constraints, and parameters.

Diagram depicting the linear programming model used to optimize supply chain costs. The objective is to minimize costs related to factory fixed and variable production costs as well as freight costs. Constraints such as market demand and production capacity are illustrated, and the product flow is mapped globally from different production facilities to target markets. The diagram also shows the manufacturing footprint, distinguishing between low and high-capacity factories in different regions.
(Image by Author)

Manufacturing Footprint
Where do I need to open locations?

Bar chart showing fixed costs for various production capacities in five different markets: USA, Germany, Japan, Brazil, and India. The data indicates that the high-capacity plants in India have lower fixed costs compared to other countries.
(Image by Author)

You must open four locations in Brazil, the USA, Japan and India. Except in Brazil, all these locations are high-capacity plants.

Products Flows
How many units are produced by factory YYY for Market XXX?

Sankey diagram illustrating the flow of products from factories to different markets, showing how fluctuations in demand impact the allocation of production between countries like the USA, Japan, Brazil, and India.
(Image by Author)

Japan's factories produce only for the local market, while Brazil and India are mainly driven by export demand.

🏫 Discover 70+ case studies using analytics for supply chain optimization 🏭, sustainability🌳and business optimization 🏪 in this: Cheat Sheet

Problem Statement

This solution has been implemented assuming a constant demand in the markets.

Limits of the initial solution

What could be the impact if we have +10% in Japan and +20% in the US?

Bar chart comparing production and capacity across three different factories in the supply chain network, illustrating that production is near or at full capacity (99% for two factories and 92% for one factory). The chart reflects the limits of the initial solution in response to potential demand fluctuations.
(Image by Author)

By looking at the utilization rates, you can easily guess that your current footprint will not be able to adapt to this surge of demand.

Methodology of Simulation

We cannot rely on a single solution and expect our network to absorb the demand throughout the year.

Usually, these parameters are calculated based on the yearly sales average.

A diagram outlining the Monte Carlo simulation methodology for robust supply chain network design. It includes three stages: Generating 50 demand fluctuation scenarios using a normal distribution to simulate variability. Running the optimization model to find the optimal solution for each scenario. Analyzing the results to identify the most frequent and robust factory combination solution. Visuals include charts representing demand fluctuations, optimization outputs and pie charts solutions.
(Image by Author)

Let’s simulate this demand variability and see the impact on the network design.

Generate 50 scenarios

We will assume that the demand is following a normal distribution with a coefficient of variation CV = 0.5. (You can adapt the distribution to your needs)

Five line charts showing demand fluctuations over 50 simulated scenarios for five different markets: USA (green), Germany (red), Japan (black), Brazil (blue), and India (orange). Each chart depicts demand variability across the scenarios, with dashed lines representing the average demand for each market and solid lines tracking the simulated values that will be used to generate scenarios for the supply chain network optimization exercice.
(Image by Author)

You now have a matrix of 50 columns representing your 50 different scenarios.

Optimal Solution for Each Scenario
What is the optimal combination for each scenario?

Description: A matrix of dark and light blue squares, representing 50 scenarios on the horizontal axis. Each square represents the open or closed status of a factory in each scenario. The matrix is binary with blue for active/open and white for inactive/closed for each scenario of the supply chain network optimization exercice.
Boolean Plot of the results by scenario — [Create Boolean Plot with Python: Tutorial]
  • India always has at least 1 facility open
  • Scenario 16 needs all facilities to be open because of a peak in the US demand
  • Scenario 12 only needs 2 LOW capacity facilities in Brazil and India

Distribution of the optimal combinations
Do we have combinations that appear more frequently than others?

After removing duplicates, we have 16 unique combinations

Another matrix similar to the first, but with a different pattern of blue and white squares, indicating different scenarios where certain factories are active or closed. The scenario structure is similar, with blue marking open factories and white marking closed ones.
Boolean Plot of the results by scenario — [Create Boolean Plot with Python: Tutorial]

Which combination seems the most robust?

A colorful doughnut chart showing the distribution of unique combinations of supply chain optimization solutions, with different segments of the doughnut representing the frequency of each unique combination. Colors are used to differentiate the combinations, and the percentages are marked inside the segments.
Donut Plot of the occurrence by solution — [Create Donut Plot with Python: Tutorial]

The combination C2 (High/Low plants in India and Brazil + 1 High plant in Japan) appears the most. C2, C6 and C10 closely follow this combination.

Final Solutions

It is challenging to draft a clear conclusion, but if we choose the safe solution, we must take the C2 combination.

As it maximizes the footprint in countries with low production costs, we will meet the demand for most scenarios.

You can find the source code with dummy data on my GitHub

If you prefer to watch, have a look at the video of this article

Next Steps

There is no perfect solution for this problem, as we must balance securing the supply and reducing costs.

What if we want to reduce costs and minimize CO2 emissions?

As the demand for transparency in sustainable development increases, including environmental parameters in our model is no longer an option.

The diagram shows a map with two objectives: minimizing costs (left in red) and minimizing emissions (on the right in green). The upper section shows product flows between factories and markets using blue arrows. The lower section highlights factory capacities, with labels for “low capacity” and “high capacity” factories. Constraints and objectives are shown with icons, such as market demand and production capacity. The left side focuses on minimizing costs, and the right side on CO2 emissions.
Sustainable Supply Chain Optimization Problem — (Image by Author)

Sustainable supply chain optimization is an approach to network design that combines cost-effectiveness with environmental responsibility.

This topic is increasingly relevant as organizations are pressured to reduce their carbon footprint by reshaping their supply chain networks.

As a data scientist, how can I support my company?

Have a look at these operational cases to understand more,

Have you heard about Generative AI?

Improve the User Interface with GPT

We can use large language models to enhance the user experience by creating an agent who interacts, answers questions, and challenges assumptions.

Icons representing a workflow for using AI in supply chain optimization, starting with questions, using machine learning models and SQL databases, and ending with user interaction.
Supply Chain Control Tower Agent with LangChain SQL Agent [Article Link] — (Image by Author)

In this first article, I share my explorative journey of LLMs by showing how I designed a LangChain SQL agent connected to a database.

This automated “supply chain control tower” was able to answer basic and advanced questions by querying the database:

  • How many shipments have been delivered in the first week?
  • How many are delayed? What are the reasons?
Diagram of a Supply Chain Control Tower architecture with a central core module script interacting with a user and a database, showing a flow from initial prompts to generating output with analysis and feedback from the user.
Simple Architecture of the Solution — (Image by Author)

This solution can drive discussions around the target for stock service level and production costs.

Now that we have a set of candidates for the potential BEST solution, we can ask the agent to test them on our 50 scenarios.

  • What is the total cost for each scenario?
  • What is the percentage of demand produced by our facilities?

Users can adjust assumptions and parameters using natural languages and conduct interactive brainstorming sessions with the agent.

To learn more about the prototypes of GPT-powered agents I designed, have a look at these two articles.

How will you share the insights?

Automate PowerPoint Slide Creation with Python

If we assume that you are in the corporate world, you will probably prepare PowerPoint presentations to present the conclusion of your study.

Can we automate this boring manual task?

Yes! You’re lucky.

In another article, I shared a simple approach to generate PowerPoint slides using the Python-pptx library automatically.

Automate PowerPoint Slides Creation with Python — (Image by Author)

This example is based on a distribution planning report I had to generate in my previous position.

  • Generate graphs and comments using data extracted and processed from multiple sources.
  • Create PowerPoint slides with Python-pptx
  • Include the graphs and comments in the slides

This workflow can be easily adapted to the Supply Chain Network optimisation algorithm presented here.

If you want to include it in your workflow, check the article below 👇

About Me

Let’s connect on Linkedin and Twitter. I am a Supply Chain Engineer who uses data analytics to improve logistics operations and reduce costs.

For consulting or advice on analytics and sustainable supply chain transformation, feel free to contact me via Logigreen Consulting.

If you are interested in Data Analytics and Supply Chain, look at my website.

💌 New articles straight in your inbox for free: Newsletter
📘 Your complete guide for Supply Chain Analytics: Analytics Cheat Sheet

--

--

Published in TDS Archive

An archive of data science, data analytics, data engineering, machine learning, and artificial intelligence writing from the former Towards Data Science Medium publication.

Written by Samir Saci

Top Supply Chain Analytics Writer — Case studies using Data Science for Supply Chain Sustainability 🌳 and Productivity: https://bit.ly/supply-chain-cheat