# Boundary Conditions

Depending on the simulation scenario, we use periodic and open boundary conditions.

### Periodic Boundary Conditions

These apply to the ring-road scenario. These conditions are easy:

- First, one numbers the vehicles from 1 to n with 1 the first and n the last vehicle on a given lane. The first vehicle can be chosen arbitrarily.
- Vehicles 2 to n follow their respective leaders. The leader of Vehicle 1, however, is assigned to be Vehicle n, so the approaching rate for vehicle 1 is given by Delta v1 = vn - v1, and the gap by s1 = x1-xn-ln-L, where ln is the length of the n'th vehicle, and L the circumference of the ring road.

### Open Boundary Conditions

These conditions are more tricky. Specifically, one has to distinguish between outflow and inflow boundary conditions.

#### Outflow Boundary Conditions

Here, we assume just a free road, i.e., the gap of the first vehicle of the simulation is just set to infinity, so this vehicle accelerates freely until it is taken out of the simulation once it crosses the end of the simulated road section.

#### Inflow Boundary Conditions

These are the most tricky ones since the requested inflow cannot always be accomodated by the road, particularly if high inflows are set by the sliders, or a traffic jam or stop-and-go wave propagates to the upstream end. In the simulator, we do the following:

- Calculate the time headway as the inverse of the actually set inflow
- After this time headway has elapsed, try to insert a new vehicle on the other lane as the last one (notice: it would be better to select the lane with the largest gap)
- The insertion is successfull if the (bumper-to-bumper) gap is larger than a minimum which is set to a fixed value of 27 m.
- If the insertion attempt is successful, the vehicle will be inserted at the beginning (x=0) at a speed corresponding to the steady-state speed for this gap. Otherwise, the vehicle attempting to enter is discarded (one could also add it to a buffer of waiting vehicles but this would make the simulation less reactive). In any case, the time interval since the last attempt is reset to zero and the next insertion attempt will be done after a new time headway (calculated with the actual inflow request) has elapsed.

This makes sure that the requested inflow is accepted whenever this is possible, and no crashes occur otherwise, i.e., when the upstream end of the road is congested and/or the demand is too high.