This project demonstrates and compares two different approaches for solving the order-biker assignment problem in a food delivery system: a greedy algorithm and the Hungarian (Munkres) algorithm.
The project simulates a real-world scenario where food delivery orders need to be assigned to available delivery bikers in an optimal way. It includes two different implementation strategies:
-
Greedy Algorithm (greedy-assign.py)
- Assigns each order to the nearest available biker
- Simple and fast, but may not find the global optimal solution
- Good for real-time assignments with limited computational resources
-
Hungarian Algorithm (hungarian-assign.py)
- Uses the Hungarian (Munkres) algorithm to find the globally optimal assignment
- Minimizes the total distance traveled by all bikers
- More computationally intensive but guarantees optimal results
numpy
scipyInstall dependencies using:
pip install -r requirements.txtRun either implementation:
# Run the greedy algorithm implementation
python greedy-assign.py
# Run the Hungarian algorithm implementation
python hungarian-assign.py- Geographic Distance Calculation: Uses Haversine formula to calculate real-world distances
- Random Data Generation: Creates test scenarios with random orders and biker positions
- Configurable Parameters: Easily modify number of orders and bikers
- Performance Metrics: Shows total distance for comparing algorithm effectiveness
├── README.md
├── requirements.txt
├── greedy-assign.py # Greedy algorithm implementation
└── hungarian-assign.py # Hungarian algorithm implementation
Both implementations share common classes:
Order: Represents a delivery order with pickup and dropoff locationsBiker: Represents a delivery biker with current locationAssignment: Represents an order-biker pairing with distance
The main difference is in the assignment strategy:
- Greedy approach pairs each order with its closest available biker
- Hungarian approach optimizes the total distance across all assignments simultaneously
The simulation outputs:
- Generated orders and their locations
- Available bikers and their positions
- Final assignments with individual distances
- Total distance for all assignments
This boilerplate is useful for:
- Testing different assignment strategies
- Benchmarking algorithm performance
- Learning about optimization problems
- Building real-world delivery systems
MIT License