Supply Planning using Linear Programming with Python
Where must you allocate your stock to meet customers' demands and reduce transportation costs?
Supply planning is managing the inventory produced by manufacturing to fulfil the requirements created from the demand plan.
Your target is to balance supply and demand to ensure the best service level at the lowest cost.
In this article, we will present a simple methodology to use Integer Linear Programming with Python to answer a complex Supply Planning Problem considering:
- Inbound Transportation Costs from the Plants to the Distribution Centers (DC) ($/Carton)
- Outbound Transportation Costs from the DCs to the final customer ($/Carton)
- Customer Demand (Carton)
💌 New articles straight in your inbox for free: Newsletter
📘 Your complete guide for Supply Chain Analytics: Analytics Cheat Sheet
SUMMARY
I. Scenario
As a Supply Planning manager you need to optimize inventory allocation to reduce transportation costs.
II. Build your Model
1. Declare your decision variables
What are you trying to decide?
2. Declare your objective function
What do you want to minimize?
3. Define the constraints
What are the limits in resources?
4. Solve the model and prepare the results
What are the results of your simulation?
III. Conclusion
1. Generative AI: Supply Planning GPT Agent
2. Next Steps
I. How do you optimize Supply Planning with Python?
As a Supply Planning manager of a mid-size manufacturing company, you received feedback that the distribution costs are too high.
Based on the analysis of the Transportation Manager, this is mainly due to the stock allocation rules.
Sometimes, your customers are not shipped from the closest distribution centre, which impacts your freight costs.
Your Distribution Network
- 2 plants producing products with infinite capacity
Note: We’ll see later how we can improve this assumption easily - 2 distribution centres that receive finished goods from the two plants and deliver them to the final customers
Note: We will consider that these warehouses operate X-Docking to avoid considering the concept of stock capacity in our model - 200 stores (delivery points)
To simplify the comprehension, let’s introduce some notations
Store Demand
What is the demand per store?
You can download the dataset here.
Transportation Costs
Our main goal is to reduce the total transportation costs, including inbound shipments (from the plants to the DCs) and outbound shipments (from the DCs to the stores).
Question
Which Plant i and Distribution n should I chose to produce and deliver 100 units to Store p at the lowest cost?
Comment
We can see on the box plot above that the D1 distribution of Unit Cost has a median value lower than D2. We can expect that the model will direct a major part of the flow through D1.
💡 Follow me on Medium for more articles related to 🏭 Supply Chain Analytics, 🌳 Sustainability and 🕜 Productivity.
You can find the full code in this Github repository: Link.
II. Build your Model
We will be using the PuLP library of Python.
PuLP is a modelling framework for Linear (LP) and Integer Programming (IP) problems written in Python and maintained by COIN-OR Foundation (Computational Infrastructure for Operations Research).
1. Declare your decision variables
What are you trying to decide?
We want to decide the quantity of Inbound and Outbound transportation.
2. Declare your objective function
What do you want to minimize?
We want to decide to minimize the inbound and outbound transportation costs.
3. Define the constraints
What are the limits in resources that will determine your feasible region?
The Supply from DCs needs to meet the demand per store.
We don’t build any stock in the X-Docking platforms.
Include Sustainability Constraints
The demand for transparency in sustainable development from investors and customers has grown.
They emphasise the business's sustainability more when assessing an organisation's value and resiliency.
A great way to support your company's green transformation is to include the environmental impact in your optimization problem.
- Automate the reporting of environmental impacts along the value chain
- Optimize processes and flows to minimize these impacts
💡 For more details on how to link analytics with sustainability,
- Supply Chain Sustainability Reporting with Python, Samir Saci, Towards Data Science
- Data Analytics for Supply Chain Sustainability, Samir Saci, Towards Data Science
- What is Life Cycle Assessment?, Samir Saci, Towards Data Science
4. Solve the model and prepare the results
What are the results of your simulation?
Result
The model takes the cheapest route for Inbound by linking P2 with D1 (resp. P1 with D2).
As expected, more than 90% of the outbound flow goes through D1 to minimize Outbound Costs.
163 stores are delivered by D1
0 store is delivered by the two warehouses together
💡 Follow me on Medium for more articles related to 🏭 Supply Chain Analytics, 🌳 Sustainability and 🕜 Productivity.
III. Conclusion
Using linear programming with Python can help supply planning managers optimize their distribution network and reduce transportation costs.
By modelling the transportation and demand constraints, decision-makers can make informed decisions that improve service levels and lower costs.
Generative AI: Machine Learning x GPT
Following the trend of Generative AI with large language models (LLMs), I shared to experiment with their usage with this prototype of LangChain Agent, powered by GPT and connected to a TMS.
This agent’s performance is impressive; it can answer operational questions autonomously by querying a database and extracting the results.
What if we create a super agent for Supply Chain Optimization?
The idea would be to equip a GPT agent with
- Advanced optimization models are written in Python in a core module
- Documentation, articles and context to understand how to use them
So, we have an agent that can interact with the users to get data, understand the constraints and explain the solution.
For more details,
Next Steps
The model presented here can be easily improved by adding operational constraints:
- Production Costs in Plants ($/Case)
- Maximal X-Docking Capacity in Distribution Centers (Cartons)
But also by improving the cost structure by adding
- Fixed/Variable Costs Structures in Distribution Centers ($)
- Fixed + Variable Transportation Costs Structure y = (Ax +b)
The only limit you will find is the linearity of the constraints and the objective functions.
YOU CAN’T
- Implement a non-linear production costs rule = f(Cases) to simulate the economies of scale during production.
- Implement a non-linear (by range) transportation costs rule of total shipment size.
When you try to touch the linearity of the objective function or the constraints, you leave the beautiful world of linear programming and face the pain of non-linear optimization.
Simulate different scenarios with a Digital Twin
A digital twin is a digital replica of a physical object or system.
A Supply Chain digital twin is a computer model representing various components and processes involved in the supply chain, such as warehouses, transportation networks, and production facilities.
Simulate several scenarios for cost reductions or decarbonisation of your logistics network.
Scenario 1: You want to set up a local warehouse to reduce the last-mile delivery distance
- What would be the impact on the service level?
- What would be the impact of warehousing costs (with more locations)?
- How much CO2 emissions reduction can we reach?
Scenario 2: You want to set up additional factories to produce locally for all markets
- What would be the impact on the production costs?
- What would be the impact of transportation costs (with factories close to the warehouse locations)?
- How much CO2 emissions reduction can we reach?
For each scenario, you can manipulate the parameter linked to the initiative and see how much your overall performance will decrease.
Then, you can adapt the other metric (warehouse capacity and locations, replenishment lead time, etc.) until you reach the initial target.
This will show you the improvements in your supply chain to make it robust enough to adapt to these new green initiatives.
For more details, have a look at this article
- What is a Supply Chain Digital Twin?, Samir Saci, Towards Data Science
Example of Digital Twin Model: Green Inventory Management
Green inventory management can be defined as managing inventory in an environmentally sustainable way.
For a distribution network, this can involve a set of processes and rules that aim to reduce the environmental impact of order transmission, preparation and delivery.
What would be the impact on CO2e emissions if we reduce the frequency of store replenishments?
Use data analytics to simulate the variation of store replenishment frequency, including several supply planning strategies, and measure the impact on the overall environmental impact and costs.
About Me
Let’s connect on Linkedin and Twitter; I am a Supply Chain Engineer using data analytics to improve logistics operations and reduce costs.
If you are interested in Data Analytics and Supply Chain, have a look at my website.
References
- Computational Infrastructure for Operations Research, Optimization with PuLP (Documentation), Link
- “Supply Chain Optimization with Python”, Towards Data Science, Samir Saci
- “What Is a Supply Chain Digital Twin?”, Towards Data Science, Samir Saci
- “Green Inventory Management — Case Study”, Towards Data Science, Samir Saci