## 4 Results and Discussions  
Algorithm 1 was tested using Anaconda, which is a free and open-source distribution of the Python and R programming languages for scientific computing. The performances were estimated  
Figure 9: Table description of the input matrix used by the algorithm for emergency management. using several prerecorded videos that compared the output to the manual counting of the people, showing an accuracy above 90%. Algorithm 2 was tested using Keras, a deep-learning library that allows for easy and fast prototyping. Algorithm 2 showed a test accuracy of about 85%. Algorithm 3 (see Figure 10) was tested using Matlab, taking as inputs the output of Algorithms 1 and 2 and modifying, accordingly to the above results, the G graph. When it is executed with data coming from Algorithm 1, the Algorithm 3 shows the areas that are closed because of the activation of the overcrowding alarm. In the case of data coming from Algorithms 1 and 2, the Algorithm 3's output represents the safest and fastest path to reach an exit or assembly point in case of active environmental or structural alarms. The following figures (Figures 11 and 12) show the results of the Algorithm 1 in two simulated cases of overcrowding alarm according to those shown by Figure 6. Note that Figure (a)a is an example of a graph of the theme park without alarm, while Figure (b)b is an example of a graph with alarm. The latter was automatically generated because of the activation of the overcrowding alarm at node 4, which led to the closing of the area number 4 (please note that the name of node 4 changed from \"N4\" to \"A4 CLOSED\"). Meanwhile, Figure (c)c is a table that shows the overall conditions and that consists in the columns: (i) \"Area\", which reports the six areas into which the theme park was divided; (ii) \"People_in\", which reports the number of people entering in each area (which will be provided by the Algorithm 1 in the real application of the IoT system); (iii) \"People_out\", which reports the number of outgoing people from each area (provided by the Algorithm 1 in the real application); (iv) \"People_inside\", which reports the number of people that are inside each area at the time t\({}_{1}\) (when the crowd management plan was generated), which was calculated by subtracting the entering and outgoing people in relation to each area (note that only the positive values are reported, while the null and the negative ones are represented with zeros); (v) \"Threshold\", which reports the maximum number of people allowed to stay at the same time in each area; and (vi) \"Alarm\", which can be \"NO\" and \"ACTIVE\" if the overcrowding alarm is inactive and active, respectively. Note that, when an area  
Figure 10: Pseudo-code of the Algorithm 3 for: (**a**) crowd and (**b**) emergency management. is closed, it is only possible to leave the area (see the arrows on the graphs), and specific messages, shown by the digital signages installed in the park, prevent the access to the closed area. Figure 11: Example of the results of the Algorithm 3 in case of an overcrowding alarm at node 4, where (**a**) is the graph without an alarm, (**b**) is the graph in case of an alarm, and (**c**) is a table showing the overall condition. Figure 12: Example of the results of the Algorithm 3 in case of an overcrowding alarm at nodes 2 and 5, where (**a**) is the graph without an alarm, (**b**) is the graph in case of an alarm, and (**c**) is a table that shows the overall condition. As in Figure 11, Figure 12 shows the results of the Algorithm 3 in case of an overcrowding alarm, but, in this case, this alarm was detected by nodes 2 and 5, contemporaneously. The next figures ( Figures 13-18) show two examples of the Algorithm 3's output, which were obtained by carrying out two simulations according to Figure 8 (i.e., environmental/structural alarm active at node 3 (see Figures 13-15) and at nodes 1, 3, and 5 (Figures 16-18)).