Logistics Scheduling in Python — Core Concepts
Logistics scheduling assigns resources (trucks, drivers, dock slots, workers) to tasks (pickups, deliveries, loading, unloading) across time while respecting constraints. It determines not just who does what, but when and in what order.
Scheduling vs. routing
Routing answers “which stops in what order?” Scheduling answers “when does each activity start and finish, and who performs it?” In practice, the two are intertwined — a delivery route implies a schedule, and a schedule constrains feasible routes. Many real systems solve them jointly.
Common scheduling formulations
Job-shop scheduling
Multiple jobs must pass through multiple machines in a specific sequence. In logistics terms: multiple orders must be processed through receiving, quality check, storage, and loading stages, each with limited capacity.
Resource-constrained project scheduling (RCPSP)
Tasks have dependencies (loading must finish before transport begins) and require resources with limited availability. The objective is to minimize total completion time (makespan) or maximize on-time deliveries.
Shift scheduling
Assign workers to shifts to meet demand while respecting labor rules: maximum hours per week, minimum rest between shifts, skill requirements, and fairness across the team.
Constraint programming approach
Unlike mathematical optimization that minimizes an objective function, constraint programming (CP) searches for assignments that satisfy all constraints. It excels at scheduling because logistics constraints are naturally expressed as logical rules:
- “Driver A cannot work more than 10 hours per day.”
- “Dock 3 is available only between 6 AM and 6 PM.”
- “Order X must be loaded before Order Y because the truck delivers X first.”
Google’s OR-Tools CP-SAT solver is the most accessible Python tool for this:
from ortools.sat.python import cp_model
model = cp_model.CpModel()
# Create interval variables for each task
# Add no-overlap constraints for shared resources
# Add precedence constraints for dependent tasks
# Minimize makespan or weighted tardiness
Key constraints in logistics
Precedence
Some tasks must happen before others. A truck cannot depart until loading finishes. Loading cannot start until the order is picked. These form a directed acyclic graph (DAG) of dependencies.
Resource capacity
A loading dock handles one truck at a time. A warehouse has 20 pickers. These are unary (one at a time) or cumulative (multiple simultaneous, up to a limit) resource constraints.
Time windows
Deliveries must arrive within customer-specified windows. Dock appointments restrict when trucks can load or unload. Workers have shift start and end times.
Regulatory constraints
Driver hours of service (HOS) rules limit consecutive driving time and require rest periods. In the EU, drivers must take a 45-minute break after 4.5 hours. Violating these constraints incurs fines and is illegal.
Evaluating schedule quality
- Makespan — total time from first task start to last task finish. Important for throughput.
- Tardiness — how late are deliveries? Total tardiness sums all late minutes across orders. Weighted tardiness prioritizes high-value customers.
- Resource utilization — percentage of time each resource is active versus idle.
- Fairness — standard deviation of workload across workers or drivers.
When to use what tool
| Problem size | Recommended approach |
|---|---|
| < 20 tasks, few resources | CP-SAT exact solution |
| 20-200 tasks | CP-SAT with time limit (returns best found) |
| 200-1000 tasks | Metaheuristics (simulated annealing, genetic algorithm) |
| > 1000 tasks | Decompose by time period or zone, solve sub-problems |
A common misconception
Scheduling is not a one-time plan. In logistics, disruptions happen constantly: a truck breaks down, a worker calls in sick, a customer changes their delivery window. The schedule must be re-generated or repaired multiple times per day. The best scheduling systems are fast enough to re-solve within minutes.
The one thing to remember: Logistics scheduling uses constraint programming to assign tasks to resources across time while respecting precedence, capacity, time windows, and labor rules — producing executable timetables that beat manual planning.
See Also
- Python Adaptive Learning Systems How Python builds learning apps that adjust to each student like a personal tutor who knows exactly what you need next.
- Python Airflow Learn Airflow as a timetable manager that makes sure data tasks run in the right order every day.
- Python Altair Learn Altair through the idea of drawing charts by describing rules, not by hand-placing every visual element.
- Python Automated Grading How Python grades homework and exams automatically, from simple answer keys to understanding written essays.
- Python Batch Vs Stream Processing Batch processing is like doing laundry once a week; stream processing is like a self-cleaning shirt that cleans itself constantly.