Home

Awesome

simobility

simobility is a light-weight mobility simulation framework. Best for quick prototyping

simobility is a human-friendly Python framework that helps scientists and engineers to prototype and compare fleet optimization algorithms (autonomous and human-driven vehicles). It provides a set of building blocks that can be used to design different simulation scenarious, run simulations and calculate metrics. It is easy to plug in custom demand models, customer behavior models, fleet types, spatio-temporal models (for example, use OSRM for routing vehicles and machine learning models trained on historical data to predict ETA).

Motivation

Create an environment for experiments with machine learning algorithms for decision-making problems in mobility services and compare them to classical solutions.

<img src="./examples/moving_vehicles.gif" width="35%" align="right">

Some examples:

Installation

pip install simobility

Contributions and thanks

Thanks to all who contributed to the concept/code:

Examples

Grid world simulation

Simple simulation

Taxi service

Log example

Benchmarks

Benchmark simulations with LinearRouter and GreedyMatcher. Simulations will run slower with OSRMRouter because OSRM cannot process requests as fast as the linear router.

Processor: 2,3 GHz Dual-Core Intel Core i5; Memory: 8 GB 2133 MHz LPDDR3

Simulated timeSimulation stepVehiclesBookings per hourExecution timeGenerated eventsPickup rate
1 hour10 sec501004 sec108296.97%
24 hours1 min5010012 sec2374588.37%
24 hours10 sec5010020 sec2388088.84%
12 hours10 sec20010018 sec1333799.89%
12 hours10 sec5050031 sec4095453.92%
12 hours10 sec20050046 sec6544499.3%
12 hours10 sec10005001 min 48 sec6660599.98%
1 hour1 min1000100014 sec11486
1 hour10 sec1000100018 sec11631
24 hours1 min100010005 min 1 sec262384
24 hours10 sec100010006 min 20 sec262524

A heuristic that allows estimating a maximum number of booking a fleet of N vehicles can handle: assume that an avarage trip duration is 15 minute, than 1 vehicle can not more then handle 4 booking per hour and the upper limit for 1000 vehicles is 4000 bookings per hour.

Metrics example

{
    "avg_paid_utilization": 63.98,
    "avg_utilization": 96.87,
    "avg_waiting_time": 292.92,
    "created": 3998,
    "dropoffs": 589,
    "empty_distance": 640.37,
    "empty_distance_pcnt": 33.67,
    "fleet_paid_utilization": 63.98,
    "fleet_utilization": 96.87,
    "num_vehicles": 50,
    "pickup_rate": 15.48,
    "pickups": 619,
    "total_distance": 1902.04,
}

Simulation logs

The are multiple ways to collect simulation log - use CSV or InMemory log handler or implement your own handler: loggers

Read CSV logs with pandas:

import pandas as pd

data = pd.read_csv(
    "simulation_output.csv",
    sep=";",
    converters={"details": lambda v: eval(v)},
)

details = data.details.apply(pd.Series)

Run OSRM

wget http://download.geofabrik.de/north-america/us/new-york-latest.osm.pbf
docker run -t -v "${PWD}:/data" osrm/osrm-backend osrm-extract -p /opt/car.lua /data/new-york-latest.osm.pbf
docker run -t -v "${PWD}:/data" osrm/osrm-backend osrm-partition /data/new-york-latest.osrm
docker run -t -v "${PWD}:/data" osrm/osrm-backend osrm-customize /data/new-york-latest.osrm
docker run -d -t -i -p 5010:5000 -v "${PWD}:/data" osrm/osrm-backend osrm-routed --algorithm mld /data/new-york-latest.osrm