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.

Transportation Network Analysis with Graph Theory

Use graph theory with Python to optimize the road transportation network of a retail company.

Samir Saci
TDS Archive
Published in
9 min readJan 12, 2022

--

The image illustrates a road transportation network for a retail company, where stores are represented by circles and delivery trucks by icons. Different stores are color-coded and connected through delivery routes, visualizing how trucks transport goods between them. The graph highlights the network’s structure, offering a simplified way to explore route optimization strategies using graph theory concepts for transportation routing.
(Image by Author)

Road transportation is a significant cost and source of CO2 emissions for retailers.

Companies often conduct route planning optimization studies to reduce these costs and improve the efficiency of their network.

Animated map showing a transportation route network in China, with routes marked as lines between various cities. Each route is color-coded and labeled by specific delivery paths, representing real-world road transport activity. The map is overlaid with routes from different locations, illustrating the complexity of logistics and route planning across a broad geographic region.
Road Transportation Routing Visualization — (Image by Author)

In a previous article, we have developed a tool to visualize these routes and assess their efficiency.

As a data scientist, how can you use Python reduce these costs and improve transportation networks’ efficiency?

It requires collaboration between continuous improvement engineers and the transportation teams managing daily operations.

How can we improve collaboration? Bring visibility to operations.

In this article, we will use graph theory with Python to design visual representations of a transportation network and facilitate solution design.

SUMMARY
I. Distribution Network
Distribution centre of a retail company with 54 stores
II. Problem Statement
Optimization of the route planning to reduce transportation costs
1. Exploratory Data Analysis
1 year of deliveries to 50 stores
2. Multi-Store Delivery
Use dedicated trucks to deliver several stores
III. Solution using Graph Visualization
1. Visualization using the Graph Theory
What are the stores that are delivered together?
2. Challenge the current routing
Collaborate with the Transportation Planner to expand the routes
IV. Conclusion & Next Steps
1. Supply Chain Sustainability
Reduce the CO2 emissions of your transportation network
2. Automatically Generate PowerPoint Slides with Python
Create PowerPoint slides to communicate your results to managers

Optimize Retail Distribution with Transportation Network Optimization

Distribution Network Overview

Your colleague is a continuous improvement engineer at a retail company.

She is in charge of reengineering warehousing and transportation operations.

In the scope, a major Shanghai (China) distribution centre delivers 54 hypermarkets.

A transportation network diagram showing a warehouse with trucks departing to different regions. The regions are represented by four colored sections: Anhui (green), Jiangsu (blue), Shanghai (red), and Zhejiang (black). Each section contains icons of stores. The diagram highlights the structure of the distribution network with 84 trucks serving 54 stores across these four provinces.
Distribution Network of your Retail Company — (Image by Author)

How are the stores delivered?

Delivery by Truck

These stores, located in four different provinces, are delivered using 3rd party transportation service providers.

They provide trucks with three different capacities (3.5 Tons, 5 Tons, and 8 Tons).

A comparison between two transportation modes for a company’s fleet. On the left, “Full Truck Load” (FTL) is depicted with a truck fully loaded with pallets, representing dedicated trucks. On the right, “Less Than Truck Load” (LTL) shows a truck only partially filled, representing shared truck usage. Each mode includes invoicing models and optimization levers, emphasizing the limited optimization possible with LTL compared to FTL.
(Image by Author)

A dedicated truck is allocated to deliver stores based on the routing and loading plans designed by the transportation planners.

How do we define the routes?

Loading Plan Example

Let’s imagine a scenario with three stores in Shanghai that ordered 30 pallets (5 T).

  • The warehouse team prepares the orders and puts the cartons on pallets
  • The transport planner decides to deliver these three stores with a single 5T truck
  • Pallets are loaded into the truck
A visual representation of a dedicated truck load for delivery to three stores in Shanghai. The truck’s cargo is divided by store, with store YP1 receiving 12 pallets, store YP2 receiving 15 pallets, and store WGQ1 receiving 3 pallets. Each store’s name, pallet count, and total weight (in tons) are clearly displayed, emphasizing the distribution of goods across these stores.
(Image by Author)

The carrier invoices your company using a price per truck (Rmb/Truck) based on the first city delivered on the route.

Price per truck (Rmb/Truck) based on the first city delivered on the route. A bar chart comparing the loading capacities of trucks with different capacities — 3.5T, 5T, and 8T — across multiple months. Each bar represents the total volume loaded into trucks of these capacities, with the data showing the utilization of different truck sizes over time.
(Image by Author)
For the delivery of these three stores in Shanghai
Cost = 650 (Rmb)

The role of your transportation planning team is to design routes to ensure that your trucks are full when they leave the warehouse.

How can we avoid sending half empty trucks?

A diagram contrasting inefficient and efficient multi-store deliveries. On the left, three trucks are sent to individual stores, represented as three separate routes. On the right, a single truck serves all three stores on a combined route, visually illustrating the benefit of consolidating deliveries to improve efficiency and reduce costs.
(Image by Author)

Therefore, they avoid as many single-store routes as possible to maximize the filling rate.

If you want to know more about the FTL Transportation

(Video by Author)

🏫 Discover 70+ case studies using data analytics for supply chain optimization 🚚 and business optimization 🏪 in this: Cheat Sheet

Problem Statement

Now that we understand the job of a transportation planner, let us find out how to support our colleagues.

Objective

The objective is to reduce the total cost of transportation.

The continuous improvement engineer has been mandated to redesign the routes to bring cost savings.

How do we start? Follow the money!

Insights: Cost per Ton
A significant lever of optimization is the size of trucks.

The chart compares costs per ton across different truck sizes (3.5T, 5T, and 8T) for four months. Each bar represents the cost associated with delivering goods using the specified truck size. The data suggests that increasing the size of the trucks generally leads to a reduction in overall cost per ton, supporting the analysis that larger trucks are more cost-effective for transportation routes.
(Image by Author)

If you increase the average size of the trucks, you reduce the overall cost per ton.

The method is to deliver more stores per route.

How do we do that?

Analyzing Shipment Data

Let us have a look at the data to get more context.

You have 12 months of shipments to understand the current routing.

The donut chart shows the distribution of shipments across different categories. Each color represents a different province or region, with percentages displayed on the outer ring. The largest portion, 39.8%, belongs to one area, followed by others with smaller percentages. The chart emphasizes how the majority of shipments come from one location, indicating a potential focus area for transportation optimization.
(Image by Author)

Number of shipments per store
Most of the deliveries are in Shanghai and the neighbouring province of Jiangsu.

The treemap visualizes the number of shipments per store, with each box representing a store within a specific province. Larger boxes correspond to stores with more shipments, and provinces are color-coded. Shanghai stores (marked in blue) dominate in terms of shipment volume, while other provinces like Jiangsu, Anhui, and Zhejiang have more balanced shipment levels across their stores.
(Image by Author)

Trucks size
Except in Shanghai, where large hypermarkets drive a large part of the demand, the other provinces have stores of relatively the same size.

This chart shows the frequency of truck usage across different sizes (3.5T, 5T, and 8T) by month. Each stack represents the total number of routes completed using a particular truck size. The blue sections (3.5T trucks) are dominant, especially outside peak seasons, while the use of larger trucks (8T) increases during peak demand, such as around the Chinese New Year in January.
(Image by Author)

Number of routes per truck size
Except in January, the peak season before the Chinese New Year, most routes are delivered using small trucks.

Thanks to this simple exploratory data analysis, you can understand each province's specificity and the seasonality of the demand.

What about the routes?

Can we get better visualizations?

Solution using Graph Visualization

The objective is to design a new transportation plan to increase the average size of trucks by delivering more stores per route.

It’s easy, so let’s deliver to all stores with a single truck?!

The problem is more complex as we have operational constraints.

Constraints

Because of operational limitations, we need to consider

  • Delivery Time Window: Stores can receive products only at a particular time of the day
  • Road Restrictions: Large trucks are forbidden on some roads
  • Unloading Conditions: Some stores need to be delivered first

That means we need the input and approval of transportation planning teams while redesigning the routes.

How can we collaborate efficiently?

Solution: Graph Theory

Because of these operational constraints, you cannot perform this analysis alone.

It is key to collaborate with the transportation teams that have experience in managing route planning daily.

A graph is a structure that contains nodes (stores), and each related pair of nodes is called an edge.

A network visualization shows stores and delivery trucks as interconnected nodes. Stores are represented in different colors, likely indicating different regions. Each store connects to another based on previous deliveries. The network highlights which stores are frequently delivered together, with each line representing a delivery route. This graph can help optimize delivery routes by clustering stores together to increase efficiency.
(Image by Author)

An edge of two stores means that these stores have been delivered together at least once.

For instance, store 2 has been delivered with store 3, store 5 and store 1.

With the current routing, which stores are delivered together?

Challenge the current routing

Let’s have a look at the results with the current routing.

Full-year Shipment Analysis

A larger-scale graph visualizes store clusters from four different regions, color-coded to represent specific provinces or locations. The graph highlights three areas: a dense cluster of stores in the first region (Shanghai), an intermediary group, and a looser grouping in the third region. This layout emphasizes store proximity and how regional clusters can be optimized to reduce transportation costs.
(Image by Author)

You can find different types of clusters

  • Type 1: stores are all interconnected and usually represent a single route (it is good to group several stores in one route)
  • Type 2: stores are sequentially connected, creating a chain
  • Type 3: 1 store is connected to all the other stores

This visual can support discussions with the transportation team

  • Why do we have two isolated stores in Zhejiang?
  • Can we increase the average truck size if we group the two isolated pairs of Shanghai?
  • Can we have more type 1 clusters?

What is the impact of truck size?

Analysis of Small Truck Fleet

Our main issue is the high proportion of small trucks in our fleet.

Network Graph of 3.5T trucks

Three separate graphs display the clustering patterns of stores across different months and truck sizes (3.5T trucks). Each store is represented as a node with connecting edges based on their shared delivery routes. The graphs show differences in clustering across time and truck size, highlighting opportunities for optimizing route planning and truck utilization by considering seasonal demand and store geography.
(Image by Author)

There are fewer interconnections for these routes. There are no major clusters of interconnected nodes.

Average Truck Size
The average number of deliveries per route for each truck size confirms the observation.

A bar chart compares deliveries across different months using three truck sizes: 3.5T, 5T, and 8T. The chart illustrates the number of deliveries per truck type, highlighting that larger trucks (8T) generally handle more deliveries per route. Seasonal peaks are visible, particularly during the Chinese New Year period. The visual supports decisions on fleet optimization by emphasizing the efficiency of larger trucks for deliveries.
(Image by Author)

Large trucks make more deliveries per route except during the Chinese New Year peak period.

What is the difference between the lowest vs. highest ratio of stores per route?

Two graphs compare different truck networks. On the left, an 8T truck network shows interconnected nodes with multiple store connections, indicating high efficiency in route planning. On the right, a fragmented network for smaller 3.5T trucks reveals fewer interconnections, leading to less efficient routes. This comparison underscores the benefit of larger trucks in creating more interconnected, efficient routes.
(Image by Author)

For the best scenario (left), stores are highly interconnected (up to 4 connections).

The contrast is evident with the other network, which is highly fragmented.

You can find the source code with dummy data in my Github 👇

💡 Follow me on Medium for more articles related to 🏭 Supply Chain Analytics, 🌳 Sustainability and 🕜 Productivity.

Conclusion

This tool visually represents the distribution network to support collaborative work between you and the transportation teams.

Sitting at the same table to find a solution ensures a smooth implementation as the planning teams have been involved in the design.

You can assess planners’ ideas, and they can challenge yours.

Based on your analysis, you can propose potential improvements that will assess the operational feasibility of the teams.

You reduced transportation costs. What’s next?

Beyond Profit, Reduce the Environmental Footprint

The initial objective was to improve the truck loading rate to reduce the transportation cost per ton.

However, the positive side effect of improving the efficiency of your planning is the reduction of CO2 emissions.

CO2 Emissions by Transportation Mode — (Image by Author)

As investor's and customers' demand for transparency in emissions reductions has grown over the years, quantifying the savings from emissions cuts is essential.

Are you familiar with ESG scoring? It can be more expensive than half-empty trucks.

There are analytics tools that can help you quantify your initiative’s contribution to your company’s green transformation.

The route optimizing reduced the emissions by XX kTons of CO2eq.

If you want to educate yourself on the topic, have a look at 👇

  • Green Inventory Management — Case Study, Samir Saci

How do you plan to present the results?

There is a high chance that your manager or colleagues will ask for PowerPoint slides to understand your results.

Automate PowerPoint Slide Creation with Python

Let us assume you are PowerPoint-phobic or don’t want to spend more time manually creating slides than building the model.

What can you do?

I have a solution for you: a completely automated workflow!

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

In this article, I share my approach to automating this tedious manual task, using a weekly report for a fashion retailer's distribution planning team as an example.

Example of slides automatically generated with Python — (Image by Author)

Using the Python library Python-pptx, you can generate slides like the one above with the visuals created in this article.

If you want to replicate this tool for your reporting, have a look at the article linked 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

References

  • Networkx, Network Analysis with Python, 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)