Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Challenge: Optimize Delivery Routes | Logistics and Transportation Optimization
Python for Supply Chain
Sectionย 3. Chapterย 5
single

single

bookChallenge: Optimize Delivery Routes

Swipe to show menu

In previous chapters, you explored how to represent supply chain transportation networks using Python dictionaries, with nodes (such as warehouses and delivery points) and edges (routes with associated costs). You also learned about route optimization techniques, including Dijkstra's algorithm for finding the shortest path in a network. These concepts allow you to model real-world logistics scenarios, compute the most cost-effective delivery routes, and analyze transportation costs across a network.

123456789101112131415
# Example transportation network and delivery locations # The network is represented as a dictionary where each key is a node, # and its value is a dictionary of neighboring nodes with the cost to reach them. network = { "Warehouse": {"A": 4, "B": 2}, "A": {"Warehouse": 4, "C": 3, "D": 2}, "B": {"Warehouse": 2, "C": 1}, "C": {"A": 3, "B": 1, "D": 4, "E": 2}, "D": {"A": 2, "C": 4, "E": 1}, "E": {"C": 2, "D": 1} } # List of delivery locations you need to reach from the Warehouse delivery_locations = ["A", "C", "D", "E"]
copy

Your challenge is to use the provided transportation network and delivery locations to implement a complete delivery route optimization workflow. You should:

  • Apply Dijkstra's algorithm to find the shortest route from the "Warehouse" to each delivery location;
  • Calculate the total transportation cost for delivering to all locations;
  • Determine which delivery location is the most expensive to reach based on the optimal route costs;
  • Visualize the entire network using matplotlib, with nodes as points and routes as lines. Highlight the optimal route to each delivery location in a distinct color for clarity;
  • Print a summary for each delivery location, showing the optimal route and its cost.

Remember to use only the libraries and techniques introduced in earlier chapters, and ensure your code is clear and well-documented. This challenge will help reinforce your understanding of network modeling, route optimization, cost analysis, and visualization in supply chain logistics.

Task

Swipe to start coding

You are given a transportation network as a dictionary and a list of delivery locations. Your task is to:

  • Find the optimal (lowest cost) route from the "Warehouse" to each delivery location using Dijkstra's algorithm.
  • Calculate the total cost of delivering to all locations using the optimal routes.
  • Determine which delivery location has the highest optimal route cost.
  • Visualize the network using matplotlib, with nodes as points, all routes as lines, and optimal routes highlighted in a different color.
  • Print a summary for each delivery location showing the optimal route and its cost.

Solution

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Sectionย 3. Chapterย 5
single

single

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

some-alt