The world’s leading publication for data science, AI, and ML professionals.

Road Transportation Network Visualization with Python

Build Visualizations of your FTL Network Performance: deliveries/route, cost per ton and trucks size

Road Transportation Network Visualization with Python - (Image by Author)
Road Transportation Network Visualization with Python – (Image by Author)

Road transportation is critical to supply chain operations, representing a significant company cost.

With diesel prices increasing and the ongoing pressure to reduce CO2 emissions, there is a growing need for transportation optimization.

As a data scientist, how can you leverage descriptive analytics with python to support this optimisation effort?

Logistics systems (WMS, TMS) generate a large amount of transactional data, which requires advanced tools to process and exploit.

Supply Chain Systems - (Image by Author)
Supply Chain Systems – (Image by Author)

In this article, we will explore how to build visualizations of road transportation network performance using Python.

  • Process and analyze transportation records
  • Improve visibility into current routing and truck loading rates
  • Simulate multiple routing scenarios to estimate the impact on the average cost per ton
Summary
I. Build a Transport Plan with Python
  1. Problem Statement
  2. Objective: Reduce the Cost per Ton
II. Understand the Situation with Python Visualization
  1. Import Datasets
  2. Listing of stores delivered by each route
  3. Add cities covered by each route
III. Automate the visualization of Transport Plans
  1. Transportation Plan Visualisation
  2. Geographical Visualization of Store Deliveries
IV. Next Steps
  1. Generative AI - Transportation Control Tower Powered by GPT
  2. Measure the Environmental Impact
  3. Routing Optimization: Graph Theory
  4. Do you want to generate animated graphs?

Build a Transport Plan with Python

Building on our series on Warehousing Operations Optimization, we now turn our focus to enhancing Road Transportation efficiency.

How can we use Python to manage transportation networks using visualization?

We will apply a similar approach by:

  • Processing Data: Extracting and structuring transportation records to create an optimization model.
  • Improving Visibility: Leveraging Python visualization libraries to clarify routing and truck loading rates.
  • Simulating Scenarios: Developing a model to test various routing scenarios and assess their impact on average cost per ton."
Transportation Routes for two trucks covering five stores in 2 routes - (Image by Author)
Transportation Routes for two trucks covering five stores in 2 routes – (Image by Author)

What do we want to achieve? Minimize the cost per ton.

Problem Statement

Retail Stores Distribution with Full Truck Load (FTL)

  • 1 Warehouse delivering stores by using three types of Trucks (3.5T, 5T, 8T)

  • 49 Stores delivered
  • 12 Months of Historical Data with 10,000 Deliveries
  • 7 days a week of Operations
  • 23 Cities
  • 84 Trucks in your fleet

How can we achieve this? Shipment consolidation.

Maximizing shipment consolidation is crucial for reducing costs in route transportation.

We are using 3rd party carriers that charge full trucks per destination:

By optimizing the number of stores covered per route, we can fully utilize larger trucks to lower the cost per ton and enhance overall efficiency.

The table above shows rates applied by carriers for each city delivered for each type of truck.

Examples of transportation tariffs - (Image by Author)
Examples of transportation tariffs – (Image by Author)

Observing that costs per ton are lower for larger trucks, we want to cover the maximum number of stores per route.


Understand the Situation with Python Visualization

Import Datasets

Before considering the optimization model, your priority is understanding the current situation.

What data is available for us?

Starting with unstructured data from several sources, we must build a set of data frames to model our network.

Records of Deliveries per Store

Store Address

Transportation Costs

Listing of stores delivered by each route

Let us process the initial data frame to list all stores delivered for each route.

1 Route = 1 Truck ID + 1 Date

Add cities covered by each route.

Let us now calculate Transportation Costs invoiced by carriers

Visualization: % Deliveries per Truck Size

(%) of Route per Truck Size (3.5T, 5T, 8T) - (Image by Author)
(%) of Route per Truck Size (3.5T, 5T, 8T) – (Image by Author)
Impact of Average Truck Size (Ton) on Overall Cost per Ton (Rmb/Ton) - (Image by Author)
Impact of Average Truck Size (Ton) on Overall Cost per Ton (Rmb/Ton) – (Image by Author)

Insights

  • Average Truck Size: a large majority of small trucks
  • Cost per ton: the inverse proportion of cost per ton and average truck size

Find more inspiration for smart visualizations in this tutorial,


Automate the visualization of Transport Plans

Transportation Plan Visualisation

We want a simple visualisation of all deliveries per day with a focus on the number of different routes.

Transportation Plan: January 2017 - (Image by Author)
Transportation Plan: January 2017 – (Image by Author)

Solution: Python’s Matplotlib grid function

  • Columns: 1 Column = 1 Store
  • Rows: 1 Row = 1 Day
  • Colour = White: 0 Delivery
  • Colours: 1 Color = 1 Route (1 Truck)

Visual Insights

  • Delivery Frequency: n deliveries per week
  • Number of Routes: How many different colours do you have daily?
  • Colour = White: no delivery
  • Routes: do we have the same stores grouped from one day to another?

12 Months Overview

12 Months Overview - (Image by Author)
12 Months Overview – (Image by Author)

After optimization, this chart will help us to visualize the impact of new routing easily.

A better routing means fewer daily routes, so you’ll have fewer colours per line.

Geographical Visualization of Store Deliveries

Let us generate a visualisation of geographical locations delivered in the same route.

All Stores Locations (blue points) - (Image by Author)
All Stores Locations (blue points) – (Image by Author)

Visualization of the different routes covered per day

Visualisation of the different routes covered (1 colour = 1 route) - (Image by Author)
Visualisation of the different routes covered (1 colour = 1 route) – (Image by Author)

Next Steps

Transportation management teams can use these visualizations to pilot their operations and challenge the status quo.

Can we develop prescriptive solutions to support the transportation operational teams?

As we have extracted and formatted data from multiple systems, we can exploit this source of insights using advanced analytics solutions.

Transportation Control Tower Powered by GPT

In November 2022, OpenAI released the first version of ChatGPT.

Generative AI has become an opportunity to improve the user experience of any analytics product using large language models.

Supply Chain Control Tower Agent with LangChain SQL Agent [Article Link] - (Image by Author)
Supply Chain Control Tower Agent with LangChain SQL Agent [Article Link] – (Image by Author)

I shared my explorative journey of LLMs used to boost Supply Chain Analytics in a simple case study.

The idea was to use LangChain to design a smart agent connected to a TMS database to answer operational questions.

For more details,

Leveraging LLMs with LangChain for Supply Chain Analytics – A Control Tower Powered by GPT

What about the CO2 emissions of our Transportation network?

Measure the Environmental Impact

In addition to cost reduction, you can also target CO2 Emission reductions by optimizing your transportation network.

Formula using Emission Factor - (Image by Author)
Formula using Emission Factor – (Image by Author)

Your organization invests resources to build capabilities for sustainability **** reporting and footprint reduction.

CO2 emissions calculation - (Image by Author)
CO2 emissions calculation – (Image by Author)

How can we measure our contribution to the sustainability roadmap?

I have implemented a simple methodology to report the CO2 emissions of your Distribution Network using Python and PowerBI.

More details in this article,

Supply Chain Sustainability Reporting with Python

How can we support the implementation of improvement plans?

Collaboration with Graph Visualization

The aim is to improve the transportation plan to increase the average size of trucks by delivering more stores per route.

How can we support the change management?

Because of operational limitations, you are limited by road restrictions

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

Therefore, you cannot perform this optimization exercise alone.

Example of Graph Theory - (Image by Author)
Example of Graph Theory – (Image by Author)

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

As data scientists, how can we improve communication with operations? Visualization.

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

For more details,

Transportation Network Analysis with Graph Theory

Do you want to generate the animated graphs shared in the previous section?

Generate Animated Graphs using Pillow.

An animated map showing the different delivery routes can be generated to help transportation teams compare their solutions.

You can animate your map using Python’s library Pillow to create results like this one.

The idea is to generate each frame and generate a GIF using Pillow.

For more details, have a look at this article.

Animate your Python Graphs with Pillow

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.

Samir Saci | Data Science & Productivity

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


Related Articles