OneRail uses Nvidia AI for real-time last-mile delivery optimisation
Back to Tutorials
aiTutorialbeginner

OneRail uses Nvidia AI for real-time last-mile delivery optimisation

September 3, 202618 views5 min read

Learn to build a basic AI-powered delivery optimization system that selects the most cost-effective delivery methods for orders, similar to OneRail's OmniSTAR platform.

Introduction

In this tutorial, you'll learn how to build a simple delivery optimization system using AI concepts similar to what OneRail uses with Nvidia technology. You'll create a basic system that evaluates different delivery options and selects the most cost-effective one based on real-time data. This system will help you understand how AI can be used to solve real-world problems like last-mile delivery optimization.

Prerequisites

  • Basic understanding of Python programming
  • Python 3.6 or higher installed on your computer
  • Basic knowledge of data structures (lists, dictionaries)
  • Internet connection for installing packages

Step-by-Step Instructions

Step 1: Set Up Your Development Environment

Install Required Python Packages

First, you'll need to install the necessary Python packages for this project. Open your terminal or command prompt and run:

pip install pandas numpy

Why this step? We'll use pandas for data manipulation and numpy for numerical operations. These libraries are essential for handling delivery data and performing calculations.

Step 2: Create the Delivery Data Structure

Define Your Delivery Options

Let's create a basic data structure to represent different delivery options:

import pandas as pd

delivery_options = {
    'owned_fleet': {
        'cost_per_mile': 2.5,
        'speed_mph': 30,
        'capacity': 100,
        'reliability': 0.95
    },
    'courier_service': {
        'cost_per_mile': 3.2,
        'speed_mph': 40,
        'capacity': 50,
        'reliability': 0.85
    },
    'parcel_carrier': {
        'cost_per_mile': 1.8,
        'speed_mph': 25,
        'capacity': 200,
        'reliability': 0.90
    }
}

# Create a DataFrame for easier data handling
options_df = pd.DataFrame(delivery_options).T
print(options_df)

Why this step? This creates a structured way to store and compare different delivery methods. Each method has different costs, speeds, and capabilities that we'll use to make optimization decisions.

Step 3: Create Order Data

Define Sample Orders

Now, let's create some sample delivery orders to work with:

# Sample orders data
orders_data = [
    {'order_id': 1, 'distance_miles': 15, 'weight_pounds': 5, 'required_service_level': 0.95},
    {'order_id': 2, 'distance_miles': 8, 'weight_pounds': 2, 'required_service_level': 0.90},
    {'order_id': 3, 'distance_miles': 25, 'weight_pounds': 15, 'required_service_level': 0.92}
]

orders_df = pd.DataFrame(orders_data)
print(orders_df)

Why this step? We need sample orders to test our optimization system. Each order has distance, weight, and service level requirements that will influence which delivery method is chosen.

Step 4: Implement Cost Calculation Logic

Calculate Delivery Costs

Let's create a function to calculate the cost of each delivery option for a given order:

def calculate_delivery_cost(order, option_name, option_data):
    # Calculate cost based on distance and cost per mile
    base_cost = order['distance_miles'] * option_data['cost_per_mile']
    
    # Add weight factor (heavier packages cost more)
    weight_factor = order['weight_pounds'] * 0.1
    
    # Calculate total cost
    total_cost = base_cost + weight_factor
    
    return total_cost

# Test the function
order = orders_data[0]
print(f"Cost for owned fleet: ${calculate_delivery_cost(order, 'owned_fleet', delivery_options['owned_fleet']):.2f}")

Why this step? This function calculates the cost of delivery for each method, considering both distance and package weight. This is similar to how AI systems evaluate real-world delivery costs.

Step 5: Create Optimization Logic

Implement Delivery Selection Algorithm

Now, let's build the core optimization logic that selects the best delivery method:

def select_optimal_delivery(order, options):
    """Select the best delivery option based on cost and service level"""
    best_option = None
    best_cost = float('inf')
    
    for option_name, option_data in options.items():
        # Check if this option meets service level requirements
        if option_data['reliability'] >= order['required_service_level']:
            # Calculate cost for this option
            cost = calculate_delivery_cost(order, option_name, option_data)
            
            # Select the option with the lowest cost
            if cost < best_cost:
                best_cost = cost
                best_option = option_name
    
    return best_option, best_cost

# Test with our sample orders
for i, order in enumerate(orders_data):
    selected_option, cost = select_optimal_delivery(order, delivery_options)
    print(f"Order {order['order_id']}: Best option is {selected_option} for ${cost:.2f}")

Why this step? This is the heart of our optimization system. It evaluates all delivery options against each order's requirements and selects the most cost-effective one that meets service standards.

Step 6: Run the Complete System

Putting It All Together

Let's create a complete system that processes all orders and displays results:

def run_delivery_optimization_system(orders, options):
    """Run the full delivery optimization system"""
    results = []
    
    for order in orders:
        selected_option, cost = select_optimal_delivery(order, options)
        
        if selected_option:
            result = {
                'order_id': order['order_id'],
                'selected_delivery': selected_option,
                'estimated_cost': cost,
                'distance_miles': order['distance_miles'],
                'weight_pounds': order['weight_pounds']
            }
            results.append(result)
        else:
            print(f"No suitable delivery option found for order {order['order_id']}")
    
    return results

# Run the system
results = run_delivery_optimization_system(orders_data, delivery_options)
results_df = pd.DataFrame(results)
print(results_df)

Why this step? This final step ties everything together into a complete system that can process multiple orders and provide optimized delivery recommendations. It simulates how OneRail's OmniSTAR system would work in practice.

Step 7: Analyze Results

View and Interpret Results

Let's examine the optimization results in more detail:

# Calculate statistics
print("\nDelivery Optimization Results:")
print(f"Total orders processed: {len(results)}")
print(f"Average cost: ${results_df['estimated_cost'].mean():.2f}")
print(f"Highest cost order: ${results_df['estimated_cost'].max():.2f}")
print(f"Lowest cost order: ${results_df['estimated_cost'].min():.2f}")

# Count how many times each delivery method was selected
method_counts = results_df['selected_delivery'].value_counts()
print("\nDelivery method usage:")
print(method_counts)

Why this step? Analyzing results helps you understand the performance of your optimization system and make informed decisions about delivery strategies.

Summary

In this tutorial, you've built a basic delivery optimization system that mimics the technology used by OneRail. You've learned how to:

  • Structure delivery data using Python dictionaries and DataFrames
  • Calculate delivery costs based on distance and package weight
  • Implement optimization logic that selects the best delivery option
  • Process multiple orders and analyze results

This simple system demonstrates the core concepts behind AI-powered delivery optimization. While real-world systems like OmniSTAR use more sophisticated algorithms and real-time data, this foundation gives you a practical understanding of how such systems work. You can expand this system by adding more complex factors like traffic data, weather conditions, or dynamic pricing.

Source: AI News

Related Articles