## 4 The Simulation Framework  
This section describes the simulation framework, which has been developed specifically for this work. Although some well-established simulators such as VISSIM [37] or SUMO [38] could be used for the simulation, it was decided to build a new simulator from scratch. The main reason for this decision is that we wanted to have absolute control of every aspect of the simulation, including the different vehicles' characteristics and kinematics, precise CO2 emission estimation, and simulation of diverse driving styles. The goal was to create a simulator able to accurately reflect the reality of the traffic and driving styles at the target intersection.  
The traffic simulation framework implements a microscopic model, a type of traffic model that describes traffic at the level of individual vehicles and their interaction with each other and the road infrastructure [39]. The framework supports predefined traffic profiles, different types of vehicles, different driver behaviour models, and a set of rules that determine when vehicles accelerate, decelerate, brake, and change lanes.  
The framework has been developed from the ground up to simulate a simple specific use case. However, a few design requirements were established to allow the framework to scale up to more complex scenarios and use cases if needed. These requirements include  
* The framework should be able to run on any typical general-purpose device.
* The framework should be easy to deploy as a web-based application.
* The framework should use open and free programming stacks.
* The framework should include a visual interface, with the individual elements shown on a map.  
These requirements led to the choice of popular and mature web technologies, such as HTML, JavaScript, Open Street Maps, and Leaflet. This technology stack allows the framework to run on any device with a modern browser and Internet connectivity.  
The framework has been designed as a layered architecture, using JavaScript object-oriented programming, with specific classes for each layer. This architecture can be seen in Figure 2.  
The main components of the framework are  
* Lanes: segments of road represented by polylines, for a single line of vehicles.
* Traffic lights: an element that controls the flow of traffic from one lane to another.
* Routing: how traffic lights are controlled.
* Paths: how lanes are interconnected.
* Network: the set of paths that can be travelled by vehicles.  
\begin{table}
\begin{tabular}{c c c c c c c c c} \hline \hline \multirow{2}{*}{**Lane**} & **Vehicles per** & **Small Diesel** & **Small Petrol** & **Big Diesel** & **Big Petrol** & **Medium Van** & **Big Van** & **Bus** \\  & **Hour** & **Passenger** & **Passenger** & **Passenger** & **Passenger** & **Medium Van** & **Big Van** & **Bus** \\ \hline
1 & 324 & 37.3\% & 21.0\% & 23.1\% & 3.4\% & 13.9\% & 0.9\% & 0.3\% \\
2 & 60 & 48.3\% & 5.0\% & 20.0\% & 0\% & 11.7\% & 15\% & 0\% \\
3 & 331 & 36.3\% & 2  
* Vehicles: individual vehicles, each one with its own characteristics, that can travel across the network.
* Drivers: a model that tries to mimic individual and diverse driving styles.
* Map: a graphical representation of the network, traffic lights, and vehicles.
* Telemetry dashboard: a dashboard to visualize the statistics of the simulation.
* Traffic profiles: pre-recorded traffic profiles that can be injected into the simulator, to test the results of different routing strategies.