Optimizing Delivery Routes Using R (osrm)

Why it matters?

  • Delivery companies need fast and efficient routes
  • Transportation costs are a major part of supply chains

What is the osrm Package?

  • R package for routing and transportation analysis
  • Uses real-world road data (OpenStreetMap)
  • Calculates:
    • Distance
    • Travel time
    • Fastest routes

Key Functions

  • osrmRoute() → finds route between locations
  • osrmTable() → travel time between multiple points

Example 1: Route Between Two Cities

What this does:
Finds the fastest route between two cities using real road data. Used by companies like Amazon and Uber Eats.

Code
library(osrm)
library(leaflet)

src <- data.frame(lon = -88.4154, lat = 44.2619)
dst <- data.frame(lon = -88.0198, lat = 44.5133)

route <- osrmRoute(src = src, dst = dst)

Example 2: Travel Time Between Multiple Locations

What this does:
Calculates travel time between multiple location and helps decide the most efficient order of deliveries.

Code
library(osrm)

locations <- data.frame(
  lon = c(-88.4154, -88.0, -87.9),
  lat = c(44.2619, 44.5, 44.4)
)

row.names(locations) <- c("Warehouse", "Store1", "Store2")

result <- osrmTable(loc = locations)

round(result$durations, 1)
          Warehouse Store1 Store2
Warehouse       0.0   40.4   53.7
Store1         42.2    0.0   21.1
Store2         55.4   21.3    0.0

Limitations

  • Depends on availability of road data
  • Does not account for real-time traffic

Key Takeaways

  • osrm helps solve real-world routing problems
  • Easy to use for travel time and route analysis
  • Useful for transportation and supply chain decisions

Thank You!

Questions?