Brian Ovrum's cycle race simulation won model of the month in October 2019. In this guest blog he dives into the details of why and how he made it.
Introduction
The day AnyLogic presented their AnyLogic 8.5 updates I was very excited. In addition to the headline developments, such as levels support or improvements to the Material Handling Library, I found that they had added a 3D bike object. That reminded me of an old model of bikes that I had uploaded to RunTheModel, and that, in turn, made me think about developing an idea to create a similar model using the Process Modeling Library. Would it be possible to create a discrete-event (DE) model that seems as if it was created entirely using agent-based (AB) modeling?
I made this model during my work research time. At Accenture Applied Intelligence, we are continuously developing simulation models to help solve complex real-world problems. And we use AnyLogic simulation modeling software to do so. It allows us to use different modeling methods, as well as combine them and build multimethod models. Moreover, its libraries allow us to respond quickly. We can rapidly develop concept models and present them to stakeholders in a visually attractive and self-explanatory way.
Main Idea
The goal was to recreate a simplified version of the annual UCI World Road Cycling Championship. Specifically, the men’s elite road race. The route for this competition follows a similar structure year after year: a long and demanding first part, then several laps of a circuit (that usually incorporates a half-height mountain and an intermediate sprint), and a final section to the finish line.
In these races, the competitors from each team collaborate to help their leader win the race. The position of each competitor influences the performance, fatigue, and effort of all the other competitors. These factors, combined with persistent attacks on the lead from other competitors, mean that race positions are constantly changing.
Logic
In the model, the logic was represented with a series of delays (one for the first part of the route, 10 for each part of a lap around the circuit, and a final delay for the finish line). delay2 ends on the first mountain, then the cyclists go downhill until the end of delay4, after which they go up again until the end of delay7, at the top of the highest mountain of the circuit. After the summit, they go downhill once more, finishing at delay10, where the intermediate sprint is located.
When passing from one delay to another, a series of decisions determine the behavior of each agent. This results in a hybrid model that employs both discrete event (DE) and agent based (AB) modeling. Also, although it can take you away from an ideal situation, performance is greatly improved by making decisions when transitioning between delays rather than deciding what to do as time increments, which would be the common behavior of a 100% AB model.
The behavior of each cyclist was simplified as follows: a competitor’s speed depends on that of other nearby competitors (those in the next delay and the previous delay) and the position of teammates. A plus is added to a competitor’s speed when they decide to attack. Competitors in first position expend more effort and will use more energy in each section. Using a lot of energy is a risk because the lower a cyclist's energy, the greater the chance of them leaving the race. Two specific places on the circuit allow cyclists to exit the race. Note: cyclists with a black circle on top are the most tired and they could leave the race.
Visual Representation
Unlike the old model, where each cyclist followed a straight line, we wanted to simulate the competitors following a circuit (going up, down, and turning corners). For that, we took advantage of features in the Process Modeling Library and created a path for each delay, each one connected to the next. In this way, continuity was generated between each path, as a continuous flow, but with the speed change calculated at the previous point.
The paths allow you to change direction in all three dimensions. And, thanks to this, we were able to take the presentation to another level and make it even more realistic and impressive by creating an environment that contains valleys, mountains, rivers, lakes, and forests.
The next step was to define how to view the race. In reality, cycling races are mainly followed in two ways: with motorcycles ahead or behind the most important riders (covering the race leader and the main squad) and helicopters that follow those same riders from the air. Therefore, we did the same: we added a camera to each cyclist that accompanied him from behind (in the first person) and added three helicopters: the blue helicopter that follows the leader from up close, the green one that follows him from above (and also shows a more panoramic view), and a third, orange, helicopter that follows the peloton. To define the location of the helicopter cameras, the camera from the Autoclaved Aerated Concrete Factory model was used as a reference.
The cameras of the green and orange helicopters have practically the same function, and all that changes is the dynamic position of X and Y according to the cyclist they are following. The blue helicopter camera, on the other hand, references a point in the middle of the map (near the top of the highest mountain) and calculates its rotation based on that point, so that the mountain always appears in the center of its recording.
The following image shows the position and rotation of the blue helicopter camera. As you can see, there is a first condition that verifies if cyclistCamera is null. This is a Cyclist-type variable, which was added to choose a specific cyclist during the race (either a cyclist chosen by the user running the model or the first cyclist that goes from one delay to the next).
There are some aspects to consider when using cameras. For instance, I always have trouble going from a camera that follows an agent to a free camera. Therefore, I usually use two different 3D windows, one for the free cameras (like the one at the finish line or at the top of the mountain) and another one for the other cameras. And every time I switch from one camera to the other one, I set one 3D window visible and the other one invisible.
Another tip that can be quite useful: when running a model, you can right-click in the 3D window and copy the camera's location. Therefore, you can just run a simulation, move the camera around and, when you have found a good location, export it and set the initial location of your camera in the model with that information.
Finally, the controls to navigate the model were added. For this, 3 viewing areas were created, each with a main objective: one showing the 2D view; another, the 3D view; and, in the main view, you see a smaller 3D view and the main menu. From this menu, you can see data from the run (how many mountain and sprint points cyclists have, how long they have been running), the condition of each competitor in a team, and also select cyclists to attack. The side menu was inspired by this other model created with our work team and also takes into account several ideas explained by Benjamin Schumann in this YouTube video.
Next Steps
There are several ways to add complexity to the behavior of cyclists. For instance, by providing different strategies for both individuals and groups to carry out during the race. Or, each cyclist’s terrain specialization could be accounted for flat, medium mountain, or high mountain terrain.
As for the visuals, this model is still a basic representation of what is possible. More information on each cyclist, different ways to visualize this information during the race, pre and post-race images, dropout information, each cyclist's probability of winning, etc. All this and much more is possible with the AnyLogic libraries!
Other Models
Further examples: this series of models from our Accenture Applied Intelligence team can better exemplify some of the possible additional tools:
- Sprint: it simulates the last kilometers of a race. In this model, we used the pedestrian library, assuming each cyclist could behave similarly to a pedestrian. The road is contained by walls, and the speed is modified by changing grounds from one segment to another.
- Copa Libertadores Final 2018: it has a very clear UI to define the initial conditions of the model and show the most important points on the map.
- Airplane Boarding Policy Simulator: with a very simple UI, it allows you to run different scenarios, see what each agent does and, at the same time, see graphs that show the evolution over time of the total number of passengers.
- Gas Station Load Balancer: as previously mentioned above. It has a very clear left menu and shows in a very interesting way the information of each station on the map.
- CrossRoads: the model started as a test of the Road Traffic Library and ended up being a microworld, with cameras installed in submarines, airplanes, trains, and cars. It has several cameras in each car, and you can move from one car to another and travel around all of the roads.
- Trains: in this case, the ones that follow a specific path are the plane cameras. In this way, they manage to closely monitor the train's journey and show other views of objects that appear on the simulated island.
Credits
Some of the icons were downloaded from www.flaticon.com and are listed here:
- The helicopter icon was made by Freepik
- The cyclist icon was made by Global Warming
- The mountain icon was made by Business
- The finish icon was made by Motor Sports
The profile of the UCI World Road Cycling Championship was obtained from cyclingweekly.com
I want to thank the AnyLogic Cloud team for enabling the sharing of simulation models. These models are a constant source of inspiration, both for the creation of new models and of new business cases. Furthermore, I want to thank the entire team of AnyLogic for allowing me to publish this post on their blog, and for their constant help and support, which allow us to grow together.