A Deep Reinforcement Learning Approach to Dynamic Bike Repositioning
CABRA is the implementation of the methods described in our paper:
A Cost-Aware Adaptive Bike Repositioning Agent Using Deep Reinforcement Learning
If you use this code in your work, please cite our paper:
@ARTICLE{StaffolaniCABRA2025,
author={Staffolani, Alessandro and Darvariu, Victor-Alexandru and Bellavista, Paolo and Musolesi, Mirco},
journal={IEEE Transactions on Intelligent Transportation Systems},
title={A Cost-Aware Adaptive Bike Repositioning Agent Using Deep Reinforcement Learning},
year={2025},
volume={},
number={},
pages={1-11},
keywords={Costs;Vehicle dynamics;Urban areas;Docking stations;Deep reinforcement learning;Scalability;Optimization;Electronic mail;Computer science;Shared transport;Dynamic bike repositioning;reinforcement learning;resource allocation},
doi={10.1109/TITS.2025.3535915}
}
Below is an overview of the CABRA system architecture:
For questions or further information, please contact:
alessandro.staffolani@unibo.it
- Python: Version 3.9
- Docker: Required to set up Redis and MongoDB instances.
Note: Ensure Docker is installed and running on your system. See Docker Documentation for installation details.
- Redis: Used to monitor run progress. A Docker deployment is provided.
- MongoDB: Used to store run configurations and summary results. A Docker deployment is provided.
-
Clone the Repository:
git clone https://github.com/AlessandroStaffolani/cabra-paper.git cd cabra-paper
-
Install Python Dependencies:
pip install -r requirements.txt
-
Start Docker Compose:
The provided Docker Compose file sets up both Redis and MongoDB.
Execute:docker compose -f docker/docker-compose.yml up -d
-
Prepare the Dataset:
Follow the instructions in the cabra-datasets repository to set up the necessary dataset.
The repository provides a command-line interface (cabra.py
) to schedule and execute experiments for training, validation, and evaluation.
This command reads a configuration file, generates a set of runs, and stores the run configurations in MongoDB while enqueuing a reference in Redis.
python cabra.py run scheduler multi-runs -mcp <config_file_path> -q <queue_name>
- Replace
<config_file_path>
with the path to your configuration file. - Replace
<queue_name>
with the desired Redis queue name.
Offline Mode:
If you prefer to schedule runs without using MongoDB and Redis, add the flags --offline
and --schedule-locally
to store scheduled runs in a local folder.
python cabra.py run scheduler multi-runs -mcp <config_file_path> -q <queue_name> --offline --schedule-locally
After scheduling the runs, execute them using a worker. The following command processes runs sequentially until the queue is empty. To speed up execution, you can launch multiple workers in parallel.
python cabra.py run worker run-worker -p 0 --stop-empty -q <queue_name>
Offline Worker:
For offline runs, use the offline-worker
command:
python cabra.py run worker offline-worker --stop-empty -q <queue_name>
Note:
The-q
flag indicates the queue name (or, in offline mode, the local folder) where the runs have been scheduled. Multiple processes can pull runs from the same offline folder if needed.
This repository is provided for academic use. Please refer to the LICENSE file for further details.