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.

Road Transportation Network Visualization with Python

Build visualizations of your FTL network performance, including deliveries/routes, cost per ton, and truck size.

Samir Saci
TDS Archive
Published in
7 min readSep 9, 2020

--

A geographic map displaying a road transportation network in China with nodes connected by lines representing Full Truck Load (FTL) routes. The visualization includes route paths with metrics like delivery count, cost per ton, and truck size generated with Python. The map helps assess performance across different routes and locations. This visualization is useful for optimizing transportation efficiency and cost.
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.

A flow diagram illustrating the relationship between a factory, warehouse, and store in the supply chain. It includes steps such as production planning, replenishment order, and delivery order, showing how sales data is processed to initiate warehouse and store deliveries. The green and orange color scheme represents various components and their interactions, enhancing visibility into the supply chain system flow from factory to end customer.
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.”
A schematic diagram showing a transportation route for a single truck delivering goods to five stores. The truck starts from a central warehouse and moves to various store locations. Each store is represented as a small building icon with dashed lines indicating the routes between them. At the bottom of the diagram, a table shows example data including dates, store names, truck IDs, and volume in tons (Vol(T)). This visual represents a planned delivery schedule to multiple stores using trucks
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.

A grouped bar chart generated with Python comparing the volume delivered by three truck types (3.5T, 5T, 8T) across different cities. Each group of bars represents a city, with three bars for each city showing the volumes delivered by 3.5T (blue), 5T (green), and 8T (orange) trucks. The orange bars are generally the highest, indicating that 8T trucks carry the most volume, followed by 5T and 3.5T trucks. A legend at the top left corner explains the truck sizes represented by each color.
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.

🏫 Discover 70+ case studies using Python and VBA to automate reporting 🤖 and optimize transportation networks 🏪 in this Cheat Sheet

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

A grouped bar chart displays the percentages of different truck types generated with pytho used for deliveries to multiple cities. Each city has three bars representing the percentages for 3.5T (black), 5T (red), and 8T (blue) trucks. Black bars dominate in all cities, indicating that the largest percentage of deliveries is performed using 3.5T trucks. The red and blue bars vary in height, showing lower percentages for the 5T and 8T trucks. A legend in the top right corner explains the color.
(%) of Route per Truck Size (3.5T, 5T, 8T) — (Image by Author)
A dual-axis chart shows average truck size (in tons) on a red line and cost per ton (in RMB) as black bars for multiple cities. The red line fluctuates across cities, indicating variations in the average size of trucks used, with a noticeable peak in the middle. The black bars representing cost per ton have a consistent height across cities, except for a few cities with significantly lower values. The chart generated with Python highlights how larger trucks can lower transportation costs.
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.

A heatmap generated with Python of the transport plan for a fleet delivering to stores in September 2016. The x-axis lists 47 stores, and the y-axis lists dates from September 1 to September 30. Each cell represents a delivery, color-coded to indicate different routes taken by trucks. White cells indicate no delivery, while colored cells (ranging from yellow to purple) represent deliveries made along specific routes. The intensity of the color changes according delivery frequency.
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

Animated heatmap generated with Python of the transport plan for a fleet delivering to stores across months in 2016. The x-axis lists 47 stores, and the y-axis lists dates from September 1 to September 30. Each cell represents a delivery, color-coded to indicate different routes taken by trucks. White cells indicate no delivery, while colored cells (ranging from yellow to purple) represent deliveries made along specific routes. The intensity of the color changes according delivery frequency.
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.

Animated geographical map showing a region of China with marked routes for deliveries generated with Python. The map displays cities and transportation routes taken by trucks, highlighted by lines connecting various points on the map. The title at the top reads “Route ID = 19 covering 0.9% of deliveries,” indicating that this route accounts for a small percentage of the total deliveries. The cities, roads, and coastal features are visible, providing a geographic context for the delivery network.
All Stores Locations (blue points) — (Image by Author)

Visualization of the different routes covered per day

Animated geographical map of a region in China showing delivery routes for September 1, 2016 generated with Python. The map features 14 routes marked with colored lines connecting different cities, representing the delivery paths taken by trucks. The background includes city names, roads, and coastline features. The title at the top reads “2016–09–01: 14 routes,” highlighting the number of routes operated that day. The lines illustrate how deliveries are grouped geographically.
Visualisation of the different routes covered (1 colour = 1 route) — (Image by Author)

🏫 Discover 70+ case studies using data analytics to monitor supply chains ✅ and costs reduction 💸 in this Cheat Sheet

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.

The process of data querying and analytics is presented here. It starts with a question, goes through AI-driven insights using multiple data processing nodes, accesses SQL databases for querying, and outputs actionable results through an AI agent. The illustration emphasizes the role of both SQL queries and AI in creating an informed decision-making process for optimizing supply chain operations.
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,

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.

A mathematical formula to calculate CO2 emissions based on emissions factors. The formula is structured as follows: “CO2 Emissions = Distance × Weight × Emission Factor.” This equation calculates the carbon dioxide emissions by multiplying the distance traveled by the weight of the goods transported and the emission factor (representing the rate of emissions per unit of weight and distance). The formula is used in the context of transportation-related emissions calculations.
Formula using Emission Factor — (Image by Author)

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

A diagram depicting the calculation of CO2 emissions for a logistics route. The route involves multiple segments: a road shipment covering 120 km, an air shipment covering 10,000 km, and a final road shipment of 450 km. The total shipment weight is 1,100 kg, and the formula for calculating total emissions is displayed at the bottom: “E(total) = 1,100 × [(120 + 450) × E(road) + 10,000 × E(air)].” This highlights the process for calculating emissions across different transport modes using Python.
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,

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.

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

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.

Animated geographical map of a region in China showing delivery routes for September 1, 2016 generated with Python. The map features 14 routes marked with colored lines connecting different cities, representing the delivery paths taken by trucks. The background includes city names, roads, and coastline features. The title at the top reads “2016–09–01: 14 routes,” highlighting the number of routes operated that day. The lines illustrate how deliveries are grouped geographically.

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

For more details, have a look at this article.

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.

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

--

--

No responses yet