How to Simulate a Global Delivery Platform

One simulated day in Barcelona showing the hourly locations of couriers: start, pickup and delivery (customer).

Why Simulate?

How to Simulate?

Stochastic vs. Deterministic

Continuous vs Discrete Time vs Discrete Event

  1. Continuous Time Simulation: we know the variables in the simulations continuously over time.
  2. Discrete Time Simulation (DTS): the simulation is done in discrete time steps, i.e. variables are changed every time step.
  3. Discrete Event Simulation (DES): we only make changes to variables based on certain events, such as for example the arrival of a certain courier to a restaurant to pick up an order.

Discrete Time Simulation (DTS)

Discrete Event Simulation (DES)

Implementation

import simpy
env = simpy.Environment()
env.process(some_process_function())
def some_process_function():
while True:
yield env.timeout(5)
print(env.now)
env.run(until=100)

Timeout

yield self.env.timeout(travel_time)
...
agent_arrived_event.succeed()

Events

agent_arrived_event = env.event()
yield agent_arrived_event

Processes

process = env.process(some_process_function())

Simulator Output

12:44:59: Courier 514148: I have done the check in
12:50:22: Order 85134596 : I am waiting to be assigned
12:51:00: Jarvis: Order 85134596 will be stacked to courier 514148
12:51:00: Order 85134596: I have been stacked to a courier
13:00:00: Courier 514148: I will start to deliver the order 85134596
13:00:00: Order 85134596 : I have been dispatched to a courier
13:19:48: Order 85134596: I have been dispatched to a partner
13:19:48: Partner: I have received a notification to start preparing an order
13:19:48: Partner: I have started to prepare the order 85134596
13:19:48: Order 85134596: I have been dispatched to a partner
13:19:48: Order 85134596: I have been dispatched to both partner and courier
13:20:21: Order 85134859 : I am waiting to be assigned
13:21:00: Jarvis: Order 85134859 will be stacked to courier 514148
13:21:00: Order 85134859: I have been stacked to a courier
13:29:48: Courier 514148: I have arrived at the pickup point and I will start to wait
13:29:48: partner finished to prepare the order 85134596
13:29:48: Order 85134596: I have been picked up
13:29:48: Courier 514148: I have picked up the order 85134596 and going to delivery
13:29:48: the courier picked up the order 85134596
13:35:01: Courier 514148: I have arrived at delivery point
13:37:01: Courier 514148: I have delivered the order 85134596
13:37:01: Order 85134596: I have have been delivered
13:38:00: Courier 514148: I will start to deliver the order 85134859
13:38:00: Order 85134859 : I have been dispatched to a courier
...

Simulation Validation

How do we use it?

  • To identify the main drivers of courier service and customer delivery times.
  • Understand the behaviour of the overall system when we change certain courier behaviour.
  • Measure expected delivery time improvements due to changes of algorithms’ parameters.
  • Find the best algorithm parameters that improve overall delivery times. In the image below we see an example of the distance limit per courier assignment versus the average delivery times for a day in a city.
The average delivery times per courier distance limit for a day in a city.

Conclusion and future work

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Alex Goldhoorn

PhD in Robotics. Data Scientist @ Matching in Glovo. Simulating…