It is sufficient to run:
python XPedSimulator.py
The following packages must be installed:
- numpy
- matplotlib
Within the main.py
file, the following parameters can be changed:
w=5 # Width of the path (and also of the actual intersection)
l=25 # Length of the path
b=0.25 # Radius of the circular space occupied by a single pedestrian
vmin=1.1 # Minimum pedestrian velocity [m/s]
vmax=1.3 # Maximum pedestrian velocity [m/s]
dt=0.1 # Timestep [s]
tMax=60 # [s]
phi=2 # Pedestrian Flux [pedestrian/s]
maxAcceleration=2 # Maximum acceleration [m/s^2]
After each iteration, the code export an image containing all the pedestrians in the domain and the trajectories that they followed up until that time-step.
All the images can be grouped into a video through ffmpeg (i.e. ffmpeg -framerate 10 -pattern_type glob -i '*.png' -c:v libx264 -pix_fmt yuv420p outputName.mp4
, where the framerate should be set s.t.
The additional output is a csv file that contains the tuple$(x_{position}, y_{position}, v)$ for each pedestrian in each time-step. If a pedestrian is not in the domain at one time-step, (NaN. NaN, NaN) is outputted.
Each row contains the information for one pedestrian. Each column contains information for one time-step (except the first column, which contains the strings “AB” or “CD” according to the path that the pedestrian is following).
+------+---------------+---------------+-----+---------------+
| Path | t0 | t1 | ... | tMax |
+------+---------------+---------------+-----+---------------+
| CD | (x0 y0 v0) | (x1 y1 v1) | ... | (NaN NaN NaN) |
+------+---------------+---------------+-----+---------------+
| AB | (NaN NaN NaN) | (x0 y0 v0) | ... | (NaN NaN NaN) |
+------+---------------+---------------+-----+---------------+
| AB | (NaN NaN NaN) | (NaN NaN NaN) | ... | (xn yn vn) |
+------+---------------+---------------+-----+---------------+
This geometry is hard coded in the code in the effort of making it more efficient. Only the dimensions (length and width) can be changed.
In this simulator, the time-step must be chosen according to three considerations:
- It must be low enough to introduce new pedestrian according to the prescribed pedestrian flux
- The bigger the time-step, the more crossings of pedestrian trajectories are filtered out of the simulation
- Due to the implementation, the bigger is the time-step, the lower is the “spatial awareness” of the pedestrian. That is, the pedestrian trajectory evaluation is performed over a smaller region of space.
A new pedestrian is inserted in the simulation at the inlet “A” or “C” in a random position within the segment inlet (and considering the size of the pedestrian). If placing the pedestrian in the random position do not lead to an overlap with other pedestrians, then the insertion actually takes place, otherwise another position is searched.
At the same time, a characteristic velocity of the pedestrian is generated s.t.
If the pedestrians is outside the domain after a time-step, it is removed from the simulation and its “history” is written to the .csv file.
The movement of pedestrians, without any obstacles, is simply linear at a constant velocity.
It is generally described by:
- A velocity (Which is characteristic of the pedestrian and held constant throughout the simulation)
- An
$\alpha$ coefficient that handles any slowing of the pedestrian and its return to its original velocity (that cannot increase) - The angle of motion
$\theta$ . Basically it is$0$ for pedestrians moving from A to B and$\pi/2$ for those moving from C to D with temporary variations caused by obstacles.
The algorithm works as follows:
-
At the candidate position of the pedestrian is computed considering the maximum allowable acceleration (if the pedestrian is moving slower than its characteristic velocity) and the basic value of
$\theta$ ($0$ or$\pi/2$ )$\begin{cases}\alpha_{\max}=\min(1, \alpha_{old}+a_{\max}\Delta t/v) \ x_{cand}=x_{old}+\alpha_{\max}v\cos(\theta) \ y_{cand}=y_{old}+\alpha_{\max}v\sin(\theta) \end{cases}$
-
The candidate position is compared with:
- all the pedestrians moving along the same path
- the pedestrians moving along the perpendicular path and at the intersection only if also the considered pedestrian is at the intersection
-
If no obstacle is found, then the candidate motion is the actual one and the position of the pedestrian is updated
-
If one or more obstacles are encountered, the pedestrian must choose its deceleration and a deviation
$\delta \theta$ . This is computed with a separate functionchoosePath
.
choosePath
The candidate motion of the pedestrian is defined by the combination of these two lists:
Lists are generated with evenly spaced elements such that len(alpha_list)=180
and len(theta_list)=50
. This was chosen arbitrarily by seeking a compromise between code speed and precision in finding the optimal movement.
The pedestrian can move based on any of the combinations of the two lists. Then, the combination matrix is constructed and sorted based on the combinations that maximize
The ordered list of combinations is evaluated until the yielding candidate position:
- Do not lead to a collision with other pedestrian
- Do not lead to a collision (or bypassing) of the walls
Furthermore, since
In each folder of this repository it is possible to find different simulations results with