## 4 The Simulation Framework
### Lanes, Paths, and Traffic Lights  
A lane is a segment of road represented by a polyline of GPS points, where a single line of vehicles may travel in an ordered way. A lane allows only one traffic flow in a single direction; to simulate roads that allow multiple parallel traffic flows, a different lane is required for each traffic flow.  
Lanes are implemented as objects of a JavaScript class. The lane path is represented as an array of GPS points that form a polyline, where the vehicles travel. The polyline resolution is variable and defined by code; in this case, the minimum distance between adjacent points is 10 cm, to allow for smooth curvatures. Lanes also have information about their slope (road inclination), which is a very important factor to determine fuel consumption and therefore CO\({}_{2}\) emissions.  
Lanes have a fixed speed limit and slope for all their points; to simulate a road segment with different speed limits or slopes, several lanes must be interconnected one after the other. Each lane keeps a record of the vehicles travelling inside that lane, and their position as well. The lane class has methods to determine what is ahead of each vehicle, and its distance and speed, if applicable. These methods are crucial to govern the movement of each vehicle in the lane.  
The lane class also has methods to obtain telemetry data, which include the number of vehicles in the lane, the number of vehicles waiting for the traffic flow to resume (for example, when a traffic light is red), and the cost of stopping the traffic flow in the lane--this will be explained later in another section.  
A path is a sequence of interconnected lanes that can be travelled by a vehicle. There are several different ways to interconnect lanes into a path:  
* Direct connection between two lanes: In this case, the end of one lane connects to the start of the other lane, without any traffic control in the transition. Vehicles move from one lane to the other lane without hindrance, except for a possible different speed limit in the next lane.
* Connection through a traffic light system: In this case, the end of a lane connects to the next lane through a traffic light system. Vehicles must observe the colour of the traffic light before entering the next lane.  
Figure 2: The simulation framework’s layered architecture.  
* Connection through a stop or priority sign: In this case, vehicles enter the next lane, not at its beginning but at a specific position in the lane. Before entering the lane, vehicles must comply with the control sign, either a stop sign or a priority sign--either explicit or implicit--such as when entering a roundabout.  
Paths can also create branches: at the end of one lane, traffic can be routed to several different lanes, according to a parameterised probability distribution. Different lanes can merge into a single lane as well. The network layer comprises all the paths in the simulation, from where the statistical information is gathered.  
Traffic lights are implemented as a class, which thereby determines how the vehicles behave when approaching an intersection controlled by traffic lights. Traffic lights have a visual representation on the map as well: red, yellow, or green circles, which help to visualize how vehicles behave at traffic lights.  
This class has two versions: one that implements the fixed time cycle system that is currently deployed at the intersection and another version, which implements the smart routing algorithm.