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.

Supply Chain Optimization with Python

Find the optimal locations of your manufacturing facilities to meet customers’ demands and reduce production costs.

Samir Saci
TDS Archive
Published in
7 min readMay 13, 2021

--

Supply Chain Network Optimization with Python: Find the optimal locations of your manufacturing facilities to meet the demand and reduce production costs. A world map highlights the locations of factories and stores connected by shipping routes. The image depicts an optimization scenario with dashed lines representing transportation paths between stores and factories.
Supply Chain Network Optimization Problem — (Image by Author)

Supply chain optimization best uses data analytics to find an optimal combination of factories and distribution centres to match supply and demand.

Because of the current surge in shipping costs, companies are starting to challenge their current footprint to adapt to the post-COVID “New Normal.”

How to use python to automate this analysis?

In this article, we will present a simple methodology using Linear Programming for Supply Chain Optimization, considering

  • Fixed production costs of your facilities ($/Month)
  • Variable production costs per unit produced ($/Unit)
  • Shipping costs ($)
  • Customer’s demand (Units)

Should we keep outsourcing with shipping costs that have tripled in the last 12 months?

Summary
I. How do you design a supply chain network with Python?
1. Problem Statement
II. Results
1. Scenario 1: Initial Scenario
2. Scenario 2: Outsourcing to low costs regions
3. Scenario 3: surging shipping costs due to container shortage
III. Build your Model
1. Declare your variables, parameters and model
2. Define the objective and add constraints
3. Solve your model and analyze the results
IV. Conclusion
1. Generative AI: GPT x Supply Chain Optimization
2. Implement Sustainable Sourcing
3. Go Beyond

Design a supply chain network with Python

Problem Statement

As the Head of Supply Chain Management of an international manufacturing company, you want to redefine the Supply Chain Network for the next five years

It would be best to consider the recent increase in shipping costs and the forecasts of customers’ demand.

A world map showing the locations of several factories across different continents, including North America, South America, Europe, and Asia. Blue icons represent the factories in key strategic locations for supply chain optimization with Python.
Map of your Supply Chain Network — (Image by Author)

Your Supply Chain Network

  • 5 markets in Brazil, USA, India, Japan, Germany
  • 2 types of manufacturing facilities: low-capacity and high-capacity sites
  • Shipping costs ($/container)
  • Customer’s demand (Units/year)

What about the costs of producing and delivering?

Manufacturing Facility Fixed Costs

  • Capital Expenditure for the Equipment (Machines, Storage, ..)
  • Utilities (Electricity, Water, ..)
  • Factory management, administrative staff
  • Space Rental

These costs depend on the country and the type of plant.

A table presenting the fixed costs per month (in k$) for manufacturing facilities in various countries. The table shows a range for each country, with the USA having the highest cost (6,500–9,500 k$/month) and India having the lowest cost (2,110–3,080 k$/month). This table will be used as parameters for our Supply Chain Network optimization problem.
Manufacturing Site Fixed Costs — (Image by Author)

Production Variable Costs

  • Production lines operators
  • Raw materials
A table displaying the variable costs per unit (in $) for producing goods in different countries. The table compares the costs of producing goods in countries such as the USA, Germany, Japan, Brazil, and India, with India having the lowest variable costs ($5/unit) and Germany the highest ($13/unit). This table will be used as parameters for our Supply Chain Network optimization problem.
Manufacturing Site Fixed Costs — (Image by Author)

For instance, the variable cost of a unit produced in Germany is 13$/Unit.

Does that mean we should always outsource to overseas?
No, check the transportation costs.

Shipping Variable Costs

  • Cost per container ($/Container)
  • Assumption: 1 container can contain 1000 units
A table showing the freight costs (in $ per container) for shipping goods between different countries. It highlights the costs for shipping containers from countries like the USA, Germany, Japan, Brazil, and India. Freight costs vary depending on the origin and destination, with the USA-to-Germany route costing 1,750 $/container, while the India-to-Brazil route costs 4,200 $/container. This table will also be used as parameters for our Supply Chain Network optimization problem.
Sea Freight Shipping Costs ($/Container) — (Image by Author)

For instance, shipping a container from Germany to Japan will cost 1,231 ($/Container).

Can we produce only the optimal locations?
No, we have limited capacities.

Manufacturing Capacity by Site

A table showing the manufacturing capacity per site (in kUnits/month) for different countries, with both low and high capacity values. Each country has the same capacity range, from 500 to 1,500 kUnits per month for its manufacturing facilities. This table will also be used for the constraints of our Supply Chain Network optimization problem.
Manufacturing Site Capacity — (Image by Author)

For instance, a high-capacity factory in Brazil can produce 1,500,000 (Units/month).

Customers' demand per market

A table listing the demand (in Units/month) for products in different countries, with the USA having the highest demand (2,800,000 units/month) and Germany having the lowest demand (90,000 units/month). This table will also be used for the constraints of our Supply Chain Network optimization problem.
Manufacturing Site Capacity — (Image by Author)

The supply should meet the demand.

🏫 Discover 70+ case studies using data science for supply chain optimization 🚚, sustainability🌳and business optimization 🏪 in this Cheat Sheet

Results

Let us try three scenarios

  • Scenario 1: initial parameters
  • Scenario 2: we increase the production capacity of India (x2)
  • Scenario 3: surging shipping costs due to container shortage

Let set up the baseline.

Scenario 1: Initial Scenario

  • Brazil plant is producing for the local market and the USA
Facilities: 1 high capacity plant
('Brazil','Brazil') = 145,000 (Units/Month)
('Brazil','USA') = 1,250,000 (Units/Month)
  • India plants produce for all countries except Brazil
Facilities: 1 high capacity plant and 1 low capacity plant
('India','Germany') = 90,000 (Units/Month)
('India','India') = 160,000 (Units/Month)
('India','Japan') = 200,000 (Units/Month)
('India','USA') = 1,550,000 (Units/Month)
  • Japan needs to produce locally because of the limited capacity of India
Facilities: 1 high capacity plant
('Japan','Japan') = 1,500,000 (Units/Month)
  • Final Costs
Total Costs = 62,038,000 ($/Month)

What if we want to minimize the costs by increasing India capacity?

Scenario 2: Outsourcing to low costs regions

Let us try to double the size of the India High Capacity plant, assuming that it will double the fixed costs.

  • Brazil plant is still producing for the local market and the USA
Facilities: 1 high capacity plant
('Brazil','Brazil') = 145,000 (Units/Month)
('Brazil','USA') = 1,250,000 (Units/Month)
  • India plants produce for all countries except Brazil
Facilities: 2 high capacity and 1 low capacity plants
('India','Germany') = 90,000 (Units/Month)
('India','India') = 160,000 (Units/Month)
('India','Japan') = 1,700,000 (Units/Month)
('India','USA') = 1,550,000 (Units/Month)
  • Japan does not produce locally anymore.

Final Costs

-19.4(%) vs. Scenario 1
Total Costs = 51,352,000 ($/Month)

COVID arrived 👉 shipping costs increased.
What happens?

Scenario 3: surging shipping costs due to container shortage

What if we have container costs multiplied by 5?

  • Brazil is producing for the local market only
Facilities: 1 low capacity plant
('Brazil','Brazil') = 145,000 (Units/Month)
  • The USA started to produce for the local market, and Japan
Facilities: 1 high capacity plant
('USA','Japan') = 200,000 (Units/Month)
('USA','USA') = 1,300,000 (Units/Month)
  • India closed its low-capacity factory
Facilities: 1 high capacity plant
('India','Germany') = 90,000 (Units/Month)
('India','India') = 160,000 (Units/Month)
('India','USA') = 1,500,000 (Units/Month)
  • Japan starts to produce for its local market
Facilities: 1 high capacity plant
('Japan','Japan') = 1,500,000 (Units/Month)

Because of their limited production capacity, Japan and the USA still rely on the Indian plant.

Final Costs

Total Costs = 92,981,000 ($/Month)

Do you want to try it yourself?

This model has been implemented in a web application,

Sustainable Supply Chain Optimization [Link]

Access it here, 👇

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

Build your Model

We will be using the Python PuLP library.

PuLP is a Python modelling framework for linear (LP) and Integer Programming (IP) problems maintained by the COIN-OR Foundation (Computational Infrastructure for Operations Research).

Declare your variables, parameters and model

  • LpMinimize: Your objective is to minimize your costs
  • lowBound =0: You cannot have negative values of units produced

What do we want to achieve?

Define the objective and add constraints

How do we get the results?

Solve your model and analyze the results

The results are now available and can be printed.

You can find the full code in this Github repository 👇

Conclusion

This model allows you to simulate several scenarios influencing operational and commercial parameters.

  • What if the demand explodes in India?
  • What if we have to close our plant in Brazil?
  • What if we triple the production capacity in Japan?

Scenario 3 is an example of a shipping cost surge that could lead companies to adopt a more local footprint.

This simple model can help you get the potential of linear optimization for supply chain network optimization.

What about the environmental footprint of your supply chain?

Implement Sustainable Sourcing

A similar approach can be used to select your suppliers, considering an objective function that will minimize the environmental impact.

A comparison chart evaluating three manufacturing factories based on three environmental factors: water usage, pollution, and CO2 emissions. Each factory is rated using stars for each factor. The first factory has moderate ratings, the second factory has high ratings, and the third factory performs the best with the highest star ratings across all environmental metrics used for sustainable sourcing with python.
Assessment of Suppliers based on Environmental Factors — (Image by Author)

Sustainable sourcing is the process of integrating social, ethical and environmental performance factors when selecting suppliers.

Use data analytics to automatically select the best supplier with a mix of economic and environmental constraints

A visual representation of the life cycle assessment of a product in a supply chain. It begins with raw materials and flows through the manufacturing process, shipping via cargo, and finally to the warehouse. Each step is annotated with the environmental impact in terms of CO2 emissions (CO2eq), energy consumption (MJ), and water usage (L), illustrating how each stage contributes to the total environmental footprint used for sustainable sourcing with Python.
Life Cycle Assessment of your product — (Image by Author)

This article will explore using data analytics to design an optimal Supply Chain Network that minimizes costs and environmental impacts.

Have you heard about Generative AI?

Generative AI: GPT x Supply Chain Optimization

Following the trend of Generative AI with large language models (LLMs), I shared to experiment with their usage with this prototype

Generative AI Supply Chain Optimization with Python: Icons representing different stages from question input to final analysis output. Key stages include an initial prompt asking ‘How to start?’, processing a sample file with core module ‘SCRIPT.PY’, and generating outputs such as instructions, a script template, or complete analysis with comments and charts. User interactions include asking how to start, using a sample file, or requesting a full analysis.
Supply Chain Control Tower Agent with LangChain SQL Agent [Article Link] — (Image by Author)

This LangChain Agent, powered by GPT and connected to a TMS, can answer operational questions autonomously by querying a database.

What if we create a super agent for Supply Chain Optimization?

A LangChain-based Supply Chain Optimization framework. The process starts with a user prompt for a supply chain analysis, the core module ‘SCRIPT.PY’ processes the sample data file, and GPT generates instructions, initial outputs, or comprehensive analysis. The AI-powered supply chain control tower autonomously queries databases to deliver operational answers, aiming to optimize supply chain decisions with an integrated LangChain SQL agent.
Example of Architecture [Test the GPT: Link]

The idea would be to equip a GPT agent with

  • Advanced optimization models in Python in a core module
  • Documentation, articles and context to understand how to use them

Let us imagine agents who can interact with the users to obtain data, understand the constraints, and run the solution to analyse the results.

For more details,

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 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

References

[1] Computational Infrastructure for Operations Research, Optimization with PuLP (Documentation), Link

--

--

TDS Archive
TDS Archive

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.

Samir Saci
Samir Saci

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

Responses (1)