Home

Awesome

Introduction

This repository contains a race simulation for the simulation of motorsport circuit races. The intended application is the determination of an appropriate race strategy, i.e. of the pit stops (number of stops, inlaps, tire compound choice, possibly refueling). The race simulation considers long-term effects such as mass reduction due to burned fuel and tire degradation as well as the interactions between all race participants. It is based on a lap-wise discretization for fast calculation times. Probabilistic influences are also modeled and can be evaluated using Monte Carlo simulation. For the making of automated race strategy decisions, we developed the Virtual Strategy Engineer (VSE).

Many parts of this repository are focused on the Formula 1 racing series. However, most code can also be used for other racing series.

Contact person: Alexander Heilmeier.

List of components

Dependencies

Use the provided requirements.txt in the root directory of this repo, in order to install all required modules.
pip3 install -r /path/to/requirements.txt

The code was developed with Python 3.8 on Windows 10 and tested with Python 3.8 on Ubuntu.

Solutions for possible installation problems (Windows)

cvxpy, cython or any other package requires a Visual C++ compiler -> Download the build tools for Visual Studio 2019 (https://visualstudio.microsoft.com/de/downloads/ -> tools for Visual Studio 2019 -> build tools), install them and chose the C++ build tools option to install the required C++ compiler and its dependencies

Solutions for possible installation problems (Ubuntu)

  1. matplotlib requires tkinter -> can be solved by sudo apt install python3-tk
  2. quadprog requires Python.h -> can be solved by sudo apt install python3-dev
  3. For building the cvxpy wheel you will need sudo apt install build-essential

Intended workflow

The intended workflow is as follows:

  1. Determine basic strategy: Use the simplified race simulation in racesim_basic to determine the fastest basic race strategy. It can be used as a first guess for the race strategy in the race simulation.
  2. (optional) Train reinforcement VSE: Train the VSE within the race simulation to make reasonable strategy decisions.
  3. Evaluate and prepare final race strategy: Use the race simulation in racesim to simulate the race and to optimize the race strategy. The VSE can be used for other participants if you do not want to determine all strategies manually. Of course, it could also be used for the own driver.

Running the basic race simulation

If the requirements are installed on the system, follow these steps:

Race times for various two-stop race strategies

Running the VSE training

If the requirements are installed on the system, follow these steps:

Training of the reinforcement learning VSE

The RL VSE must be trained specifically for each race. This is possible by executing the main_train_rl_agent_dqn.py script. The according source code for the setup of the RL environment etc. can be found in the machine_learning_rl_training directory. After training, please copy the output files from that directory to racesim/input/vse to make the trained DQN (deep Q-network) available to the race simulation. Pre-trained reinforcement VSE are included for all available races except (partly) wet races.

For more information on the VSE, we refer to our paper Virtual Strategy Engineer: Using Artificial Neural Networks for Making Race Strategy Decisions in Circuit Motorsport (more bibliographic details are listed below).

Running the race simulation

If the requirements are installed on the system, follow these steps:

Race simulation real time output for the Yas Marina racetrack

Contained parameter files

We included exemplary parameter files for the 121 Formula 1 races in the seasons from 2014 to 2019. They were automatically created on the basis of our Formula 1 timing database (link is below). The program used for this was developed by Marcel Faist as part of his master's thesis within the project. Please keep in mind that an exact reproduction of the real races in the simulation is practically impossible.

Virtual Strategy Engineer (VSE)

If activated in the bottom part of main_racesim.py, the virtual strategy engineer (VSE) determines the race strategies of the race participants. It eases the handling for the user of the race simulation since he must not determine the strategies of all race participants manually. Several variants of the VSE are available, which can be set separately for each driver at the bottom of the race parameter files (/racesim/input/parameters/*.ini):

With the basestrategy option, the VSE uses a pre-defined strategy (stored at the bottom of the parameter files as well) that was optimized for a minimum race duration (under the assumption of a race without opponents). This was done by using the basic strategy optimization in main_racesim_basic.py. With the realstrategy option, the strategies of the real-world races are applied (stored at the bottom of the parameter files). With the supervised option, the VSE is based on two artificial neural networks that were trained on real-world timing data to make the race strategy decisions. Please keep in mind that our VSE is focused on Formula 1. Thus, it only determines whether a driver should come into the pits and which tire compound should be fitted to the car. The reinforcement option activates a VSE that was trained within the race simulation based on a reinforcement learning (RL) approach.

Before activating the reinforcement option, consider performing your own training instead of using one of the pre- trained reinforcement VSE, see previous section. Pre-trained reinforcement VSE are included for all available races except (partly) wet races. This is because the VSE is currently only implemented to handle dry compounds. The training was performed against the supervised VSE. However, the resulting NNs werde not checked in terms of decision behavior. It can therefore be suboptimal! The following eleven races were (partly) wet:

Publications

Detailed description of the race simulation (deterministic parts)

Please refer to our paper for further information:

@inproceedings{Heilmeier2018,
doi = {10.1109/itsc.2018.8570012},
url = {https://doi.org/10.1109/itsc.2018.8570012},
year = {2018},
month = nov,
publisher = {{IEEE}},
author = {Alexander Heilmeier and Michael Graf and Markus Lienkamp},
title = {A Race Simulation for Strategy Decisions in Circuit Motorsports},
booktitle = {2018 21st International Conference on Intelligent Transportation Systems ({ITSC})}}

Detailed description of the race simulation (probabilistic effects and random events)

Please refer to our paper for further information:

@article{Heilmeier2020,
doi = {10.3390/app10124229},
url = {https://doi.org/10.3390/app10124229},
year = {2020},
month = jun,
publisher = {{MDPI} {AG}},
volume = {10},
number = {12},
pages = {4229},
author = {Alexander Heilmeier and Michael Graf and Johannes Betz and Markus Lienkamp},
title = {Application of Monte Carlo Methods to Consider Probabilistic Effects in a Race Simulation for Circuit Motorsport},
journal = {Applied Sciences}}

Detailed description of the virtual strategy engineer (VSE)

Please refer to our paper for further information:

@article{Heilmeier2020,
doi = {10.3390/app10217805},
url = {https://doi.org/10.3390/app10217805},
year = {2020},
month = nov,
publisher = {{MDPI} {AG}},
volume = {10},
number = {21},
pages = {7805},
author = {Alexander Heilmeier and Andr{\'{e}} Thomaser and Michael Graf and Johannes Betz},
title = {Virtual Strategy Engineer: Using Artificial Neural Networks for Making Race Strategy Decisions in Circuit Motorsport},
journal = {Applied Sciences}}

Related open-source repositories