This repository contains the source code for the ad hoc simulator used to generate data across various two-car following system scenarios. The collected data supports the benchmarking and comparison of three perceptual Forward Collision Warning Algorithms (FCWA) based on safety and driver efficiency metrics.
Rear-end collisions account for a significant portion of road accidents in Metro Manila, highlighting the need for advanced driver assistance systems (ADAS) such as Forward Collision Warning (FCW) systems. These systems aim to improve road safety by providing timely alerts to drivers, helping prevent rear-end accidents. This study evaluates three perceptual algorithms–Honda, Hirst & Graham, and Bella & Russo–within a two-car following system.
A computational analysis was conducted using NumPy to examine trends in Modified Time to Collision (MTTC) based on relative velocity and acceleration. Additionally, an ad-hoc simulator is developed to evaluate the impact of these algorithms on driver behavior and efficiency. Results indicate that while all three algorithms contribute to improved safety, variations in warning distances affect driver response patterns, with implications for both driving efficiency and envi- ronmental impact.
This study emphasizes the need to balance safety and efficiency in FCW sys- tems to minimize false positives, avoid overly conservative warnings, and reduce unnecessary braking events that increase fuel consumption and carbon emissions. Future research should explore real-world implementation and extend the analysis to more complex traffic scenarios, such as vehicle platoons, to further refine FCW performance.
- Running through `nix`
- Run `nix develop` to bootstrap a shell that includes `nodejs_23` and pnpm through corepack. > You can also use this devShell (`./nix/devShell.nix`) as your development environment! - `pnpm install` - `pnpm dev`- Other systems
- install NodeJS v23 and `pnpm` manually or through `corepack`. - `pnpm install` - `pnpm dev`The simulator has four key components: the simulator generator function, the renderer, the parallel processing infrastructure, and the persistence layer.
Simulator Generator Function The simulator generator function is a TypeScript generator which aims to lazily generate simulation states. This function is strictly detached from all other components, allowing for headless invocations.
The function resides in ./src/lib/simulator/simulator.ts with sample usage in (renderer), lagrangian and parallel Svelte routes.
The renderer serves as the runner which prompts the simulator generator function for system states for every tick. As the simulation states are all in metric units, the renderer converts the results into a specific pixel representation. It then updates the PixiJS Canvas with the appropriate values, before starting another render call. This project comes with two renderers: the default one, and the lagrangian renderer.
The default renderer displays the scenario derived from the given parameters as a whole. That is, as the vehicle representation goes out of bounds, the simulation halts.
zen_yYO9KHLm4C.mp4
On the other hand, the lagrangian simulator works a bit differently. It still retains the mechanism where the renderer prompts the simulator for values, as well as the metric-to-pixel conversion. However, the simulation halting condition with this renderer is based on the set maximum run distance (by default, 1 kilometer). The renderer pans the view as the vehicles go out of bounds, with options to follow the FV or LV. For ease of interpretation, lane markers are also renderered as well as signs for every 100m of the road.
zen_fTB3jfZ0nv.mp4
Both renderers keep track and display certain metrics such as:
- Current headway
- Average headway
- Following Car Average velocity (in mps)
- Warning Distance (hit/no hit)
- Current MTTC
- MTTC on first warning distance hit
These metrics are then analyzed within the study to gauge the performance of the three perceptual warning algorithms under varying driving conditions.
This project also houses a parallel runner located in the parallel Svelte route. The parallel runner initializes a worker pool of size 100, where simulation requests are dispatched and independently processed. Worker status are also displayed to show which workers are currently preoccupied with running simulations, and which workers are idle. As of now, the default tasks are based on the simulation data required by the study. Upon finishing a task, the simulation data is exported as JSON.
I recommend running the parallel runner in a chromium-based browser. Firefox-based browsers tend to finish all tasks twice as longer.
opera_bOLBR8bYLw.mp4
The simulation framework utilizes Dexie.js, a lightweight and performant wrapper for IndexedDB, to manage persistent storage of simulation data. Each row in the Chapter 3. Methodology 19 database contains one simulation run, with its primary keys being the simula- tion inputs and the simulation results as other columns. Dexie.js also allows for quick JSON exports, which allows seamless integration with Python for further visualizations and analyses.
This ad-hoc simulator is written in TypeScript with the following technologies:
This project uses Svelte v5, however some routes are still not migrated.
As this project is written with heavy time constraints, there are a few more avenues for improvement. I recommend future forks of this project to work on the following item points:
- Full rework for the default renderer
- Kinematics FCWA support
- Proper IndexedDB tables for each task in parallel runner
- Ability to create task queue from the interface
- Ability to set maximum run distance in interface of Lagrangian renderer
- Proper code refactors
- Migrate to Svelte 5
- Migrate to PixiJS v8
This project was developed as part of my undergraduate thesis under the Scientific Computing Laboratory of the Department of Computer Science, College of Engineering at the University of the Philippines Diliman.
Special thanks to Dr. Jaymar B. Soriano for his guidance and support throughout the research.
Copyright (C) 2025, Michael M. mlmonasterial@up.edu.ph.