## 2 IoT System Description
### Software: NN-Based and SPF Algorithms for Emergency Management and Social Distancing
The output of the NN cited above is one of all the possible combinations of alarm. The number of alarm combinations is equal to the permutations of the number of sensing nodes without repetitions and can be calculated using the following expression:  
\[A=\sum_{i}\frac{N!}{K_{i}!\cdot(N-K_{i})!}, \tag{1}\]  
with i = 1,..., 6, and where N is the length of the array {1, 2, 3, 4, 5, 6} that represent the sensing nodes of the WSN, and K is an integer that shows how many nodes detected an alarm at the same time. Note that the WSN used in this study consists of six sensor nodes. Hence, the number of alarm combinations A without repetitions (e.g., the condition \"alarm actives at node 1 + alarm actives at node 3\" is equal to the condition \"alarm actives at node 3 + alarm actives at node 1\") is 63. The third algorithm (Algorithm 3, represented by box 6 in Figure 3) is used to define the shortest and the safest paths if the Environmental and/or Structural alarm or the Overcrowding alarm is active in at least one node of the WSN. In particular (cf. Table 5), the Algorithm 3 automatically updates: (1) when the overcrowding alarm is active, a crowd management plan that consists of an image that highlights, with red areas and white signals, the overcrowded areas (see two examples in Figure 6); (2) when the environmental/structural alarm is active, an Emergency plan that consists of an image (see two examples in Figure 8) that shows in which nodes the alarm is active (with red circles and yellow triangles), if an exit is closed (with a no entry sign), and the exit or the assembly point that must be reached (with green and white signs, respectively). In more detail, Algorithm 3 is based on the graphs shown by Figure 4 (i.e., graph in Figure 4a was used in the case study 1, while graph in Figure 4b was used in the case study 2) and was developed using Matlab tools (i.e., using the \"shortestpath\" and \"digraph\" functions [47]). It takes as input the connections among the graphs and the alarm conditions, and takes the people in each area as weight; it then returns the sequence of nodes that should be passed through, which corresponds to the safest path for the people who, because of active alarm/s, must reach a predefined point (which could be an exit or an assembly point) from their starting node. In summary, the fastest (i.e., on paths traveled by few people) and safest (i.e., avoiding nodes where an alarm is active) path is suggested at the same time, considering that the spatiotemporal distribution of the people could affect the speed of the flow to reach the available exits or, alternatively, the assembly points. Note that Algorithm #3 is based on the assumption that all the edges of the graph have the same endless capacity, and the main parameter used to evaluate the availability of each edge is the number of people that are on the edge when an alarm is activated. Based on this assumption, the objective of the algorithm is not the flow of people that can move on the graph per unit of time but to recognize and provide, as a solution, the less busy path to reach an exit or an assembly point. Importantly, although the Matlab function \"shortestpath\" was used, Algorithm #3 does not select the \"shortest\" path but selects the path that includes edges that allow one to reach a final point (exit or assembly point) while avoiding slowdowns, even though the path is the longest one. \begin{table}
\begin{tabular}{c c c c c} \hline \hline
**Scopes** & **Input** & **Output** & **Steps** \\ \hline \multirow{4}{*}{Classify environmental and structural conditions and trigger related alarms when predefined thresholds are exceeded.}