| 🎉 Demo of agent based model on GPU using CUDA 12.2.1 and OpenGL 4.5 (Windows/Linux) 🎉 |
A demo of using CUDA and OpenGL to render different locations with multiple agents with their own properties.
This is a useful begin place for those want to illustrate or experiment how an agent based model works.
You can update the adjust_person_entity
function in src/gpu/GPUBuffer.cu
to change the moving path and color of each agent.
🎯 Each triangle is an agent with different color and trajectory.
🎯 On GTX 3060 the software can render 5-10M agents without problem.
🎴 The image below illustrates a demo of 12,000 agents each location (60,000 agents in total) for easier observation.
In this demo, each triangle is an independent agent and it has two properties: color and moving path.
The color is assigned by the location so all agents in the same location will have the same color.
The moving trajectory is randomized for each agent.
🎴 The image below illustrates a demo of ~500,000 agents of 100 (10x10) locations configured a from GIS raster file where each location has a random number of agents. This demo is from dev
branch.
🎴 The image below illustrates a demo of ~15,000,000 agents of 21,798 (173x126) locations configured a from GIS raster file of Burkina Faso. Moreover, the population is dynamically changed based on census data. The color of each agent is based on the population density of each location. This version will be released soon.
| 💎 Features 💎 |
✅ Agent instances on GPU memory
✅ Uses SSBO (Shader Storage Buffer Object) for instanced objects (with GLSL 450 shaders)
✅ CUDA OpenGL interops
✅ Renders with GLFW3 window manager
✅ Dynamic camera views in OpenGL (pan,zoom with mouse)
✅ Libraries installed using vcpkg
✅ Load configuration as YAML file
✅ Load location data in GIS raster file (.asc file)
✅ Update number of agents dynamically based on census data
| 📚 Libraries 📚 |
vcpkg install glfw3 opengl glew glm imgui[core,glfw-binding,opengl3-binding] easyloggingpp date yaml-cpp
| 📝 Citation 📝 |
Tran, K. T. (2023). Agent based simulation using GPU and OpenGL (1.0.0).
Zenodo. https://doi.org/10.5281/zenodo.10263352
or
@software{Tran_Agent_based_simulation_2023,
author = {Tran, Kien Trung},
doi = {10.5281/zenodo.10263352},
month = dec,
title = {{Agent based simulation using GPU and OpenGL}},
url = {https://github.com/KienTTran/ABMGPU},
version = {1.0.0},
year = {2023}
}
| ❓ How it works ❓ |
The simulation is a combination of instancing feature and parallel computing from OpenGL
and CUDA
respectively.
Using OpenGL
, you can instance as many objects as you want using SSBO
and compute position and color of clone objects on shader via GLSL
file. Instead of using shader, this demo using CUDA
to compute postion and color (via glm::mat4 matrix
and glm::vec4 color
arrays) of all instances at the same time and all agents are computed in batch processing.
| 🌟 How to build 🌟 |
- Clone the repository
- Install
vcpkg
and install requirement libraries
vcpkg install glfw3 opengl glew glm imgui[core,glfw-binding,opengl3-binding] easyloggingpp date yaml-cpp
Note: Some libraries are extra for experiment and future development (imgui, easylogging, date, glew) - On Window:
- Use any IDE (I'm using
CLion
) supportsCMake
project to load the project folder - Edit the CMakeList file to match your
vcpkg cmake
file andCUDA
installation folder on your computer. - Build and run with arguments:
-i <path to config file>
(e.g.-i ../../input/config.yaml
)
- Use any IDE (I'm using
- On Linux:
- Edit the CMakeList file to match your
vcpkg cmake
file andCUDA
installation folder on your computer. - In the project folder, type
mkdir build && cd build && cmake ..
then execute the binary built with arguments:-i <path to config file>
(e.g../ABMGPU -i ../../input/config.yaml
)
- Edit the CMakeList file to match your
- Star 🌟, issue and pull request are welcomed