An Intelligent IoT Approach for Analyzing and Managing Crowds

Crowd management is a considerable challenge in many countries including Saudi Arabia, where millions of pilgrims from all over the world visit Mecca to perform the sacred act of Hajj. This holy ritual requires large crowds to perform the same activities during specific times, which makes crowd management both critical and difficult. Without proper crowd management and control, the occurrence of disasters such as stampedes, suffocation, and congestion becomes highly probable. At present, the internet of things (IoT) and its enabling technologies represent efficient solutions for managing and controlling crowd, minimizing casualties, and integrating different intelligent technologies. Moreover, IoT allows intensive interaction and heterogeneous communication among different devices over the internet, thereby generating big data. This paper proposes an intelligent IoT approach for crowd management with congestion avoidance in the Mina area, which is located in the holy city of Mecca. The approach implements a learning mechanism that classifies pilgrims based on the collected data and exploits the advantages of both IoT and cloud infrastructures to monitor crowds within a congested area, identify evacuation paths for pilgrims and guide the pilgrims to avoid congestion in real time. Moreover, the approach attempts to maximize crowd safety based on realistic scenarios by controlling and adapting pilgrim movements according to the characteristics of the possible hazards, pilgrim behavior, and environmental conditions. We evaluated our proposed approach by performing simulations based on real data sets and scenarios.


I. INTRODUCTION
In recent years, notable population growth has been observed worldwide, including that of individuals who follow the religion of Islam (Muslims). Hajj is a yearly event that takes place in Mecca City in the Kingdom of Saudi Arabia, with millions of Muslims traveling to Mecca each year from all parts of the world to perform Hajj, causing massive pedestrian congestion in several areas of Mecca. Various incidents of crowding during Hajj have been documented, the deadliest of which corresponds to a stampede that occurred in 2015 and caused nearly 2400 causalities [1]. According to the latest statistics, approximately 2.4 million pilgrims visited Mecca for Hajj in 2019 and gathered in confined areas, performing the same actions in a limited time frame [2]. Although the The associate editor coordinating the review of this manuscript and approving it for publication was Muhammad Khurram Khan . pilgrims were extensively trained for the Hajj rituals, little to no training was provided for other aspects, such as how to avoid crowding, how to react to emergency and chaotic situations, and, in the event of an emergency, where to go and where the exit points are located [1]- [6].
Managing the emergency evacuation of crowds is a critical aspect and a significant problem since it requires the consideration of multiple complex structures [4] while analyzing and predicting the pilgrim behavior through data derived from social media, wearable and GPS-enabled devices, and CCTV footage. The increasing availability of the tremendous amount of data generated by large-mass gatherings has provided unprecedented opportunities for understanding human behavior and predicting and avoiding dangerous crowding scenarios.
Understanding crowd data is of significance in several applications such as urban planning, business, intelligent transportation systems, and traffic optimization. For instance, the obtained knowledge can be used to optimize traffic flows according to the types of events and nearby congestion, adapt urban transportation systems based on commuting behavior, and identify patterns of collective behavior of city dynamics and urban land use through additional data sources such as social media and official information regarding the route. Such mechanisms help accumulate knowledge regarding crowded areas, which can allow authorities to monitor and control crowds with a holistic perspective [5]. In the context of Hajj, analyzing the crowd data can help realize Hajj planning, emergency control, mobile network design and service enhancement.
In this work, we utilize Hajj data as a tool to analyze the pilgrims' behavior. We analyze the types of crowding situations and describe and classify the major types of Hajj data that affect crowd management. We employ IoT and cloud infrastructures to implement an efficient, safe, and reliable solution that uses the available computation and communication resources on the cloud level and integrate different techniques to realize crowd management related tasks. Our approach attempts to identify evacuation paths in real time during emergency evacuation and maximize the safety of the suggested evacuation paths by considering the hazard characteristics, pilgrims' behavior, and environmental conditions. Notably, to enhance safety during the Covid-19 pandemic, our approach considers the pilgrims' origin and medical conditions during evacuation and classifies the pilgrims and predicts their behavior based on different attributes.
The main contributions of this paper can be summarized as follows: 1) An efficient internet of things (IoT) approach for crowd management is established that employs the large amount of data extracted by different infrastructures associated with crowd sensing and participatory sensing. 2) The proposed approach can enhance the safety and prevent congestion within Mina in the holy city of Mecca by considering multiple factors that have not been considered earlier.
3) An efficient crowd guidance approach is developed that utilizes the IoT infrastructure to enhance the pilgrims' efficiency and safety. 4) The selected region (Mina) is modeled using GIS maps, the pilgrims' behavior is predicted within this area, and it is assumed that the pilgrims will follow the routes (safe paths) identified using the proposed approach with a certain randomness.
In addition to these contributions, this work is aimed at preventing the catastrophes caused by congestion, which has previously led to the death and injury of many pilgrims in the holy area of Mina, by providing a secure and dependable method of guiding pilgrims to the safest available path. The objective is to help reduce the impact of congestion-related incidents and create a healthy environment that allows pilgrims to easily perform holy rituals in an orderly fashion. The area of interest is Mina, which is situated east of Mecca and covers 20 km 2 . Mina is selected as the area of interest because pilgrims spend most of their time in this region: approximately four or five days out of the six days, which constitute the normal duration of Hajj. Additionally, most of the Hajj rituals are performed in Mina. Mina is a relatively small area in comparison to the number of pilgrims and the large number of service centers that it contains. Consequently, most of the congestion disasters throughout the Hajj seasons have occurred in the Mina area.

II. BACKGROUND
This section covers the background required to understand this work. Specifically, this section describes the major Hajj activities from the performance perspective, discusses Mina's outline as the area of interest, and presents several crowd scenarios that manifest within Mina.

A. MAJOR HAJJ ACTIVITIES
Hajj, as the fifth pillar of Islam, represents a yearly pilgrimage to Mecca, Saudi Arabia. All capable Muslims must make this journey at least once in their lifetime. Hajj lasts for five to six days. Hajj is performed between the 8 th and 13 th days of the Dhu al-Hijjah month in the Islamic calendar. During Hajj the pilgrims must perform many rituals, starting with the welcoming circumambulation, known as tawaf, around the Ka'aba, and the walk between the Safa and Marwah (Saee). After the morning prayer on the 8 th day, the pilgrims proceed to Mina where they spend the whole day in the region. On the proceeding day, the pilgrims move to Arafat and stand in vigil from noon to sunset praying and making supplications. Post sunset, the pilgrims head to Muzadalifah, where they spend the night in preparation for the next day's ritual of stoning the devil [7].
On the 10 th day of Dhu al-Hijjah, all pilgrims move to Mina to perform the symbolic stoning of the devil, shave or clip pieces of their hair and make an animal sacrifice for God. On the same day, the pilgrims head to the holy mosque at Mecca to perform tawaf al-Ifadah and return to Mina to repeat the stoning of the devil in three stages: Jamrat Oolah (the first Jamrat), Jamrat Wustah (middle Jamrat) and Jamrat al-Aqabah, between the 11 th and 13 th days. Before leaving Mecca, the pilgrims perform the last circumambulation of the Ka'aba, known as the 'farewell tawaf', seven times, as the final step of Hajj. This description of Hajj highlights that several activities are performed in Mina, and the pilgrims spent most of their time in this region [7].

B. MINA AREA
Mina is a small area situated 5 km to the east of Mecca. The area of Mina is 20 km 2 , with tents covering every open space during Hajj season. For the remaining year, Mina remains deserted. Mina contains over 100,000 air-conditioned tents that can house more than 3 million people. Many service centers are located in Mina, including police stations, guidance fields, hospitals, clinics, red crescent centers, food suppliers and train stations. Hajj rituals are performed in Mina for a minimum of three days. These rituals include praying, shaving or clipping pieces of the pilgrims' hair, sacrificing an animal for God and stoning of the devil, in which the pilgrims throw seven stones at three walls known as the Jamarat. The three Jamarat are located along the Jamarat Bridge. This bridge is 950 m long and consists of five floors. Moreover, the bridge has 12 entrances, 12 exit roads in four directions, and emergency outlets considering a gathering of 300, 000 pilgrims per hour [8]. The large number of pilgrims and rituals that must be performed in Mina pose several challenges, most of which can be solved by ensuring proper crowd management [9].
Crowd control refers to systematic planning aimed to manage public activities. During Hajj season, many disasters have been caused by congestion, which has led to the death and injury of many pilgrims. While performing rituals in Mina, many scenarios may occur that require crowd control to prevent injuries, as explained in the next subsection. Mina has multiple paths in a small area, as shown in Figure 1, which increases the possibility of misguided pilgrims. Managing the iterations of pilgrims entering and exiting the area is difficult due to the limited number of paths as well as their small capacity that prevents all pilgrims from entering and exiting from the same path. This scenario increases the risk of stampedes and other disastrous incidents.

C. CROWD-RELATED SCENARIOS
In the following subsections, we identify and discuss several crowd-related scenarios that are frequently experienced in Mina.

1) NORMAL SCENARIO
At the grand mosque in Mecca, pilgrims begin their Hajj by circling the Ka'aba seven times. Afterwards, the pilgrims move to Mina and perform religious rituals, pray from noon to dusk at Mount Arafat, and move to Muzdalifah, where they pick up the 49 stones required for the following day in Mina. After the pilgrims return to Mina, they throw the stones at the three pillars representing the devil. Next, Eid-Aladha begins, which consists of three days of ritual sacrifices. Finally, the pilgrims return to Mecca to circle Ka'aba seven more times.

2) HAZARDOUS SCENARIO
All pilgrims gather at the entrance or the exit of Mina in Jamarat Bridge. The flow of crowds starts to slow down progressively until overcrowding occurs that prevents the smooth movement of the crowd. These events cause the crowds to behave in a disorganized manner, which renders the ritual completion difficult.

3) STAMPEDE SCENARIO
As mentioned, the rituals in Mecca during Hajj include circling of the Ka'aba, followed by Saee, which involves walking between the Safa and Marwa hills seven times (approximately 450 m, leading to a total distance of 3.15 km). Subsequently, the pilgrims undertake a 14.5 km journey to Arafat and stay the night in Muzdalifa. After dusk, a mass departure of pilgrims occurs from Arafat toward Muzdalifa [10]. While these crowds enter Mina, a majority of them enter and exit Mina using the same path. This scenario may lead to a massive stampede, which poses the risk of pilgrim casualties and injuries due to suffocation and panic induced conditions, among other aspects.

4) MISGUIDANCE SCENARIO
Owing to the large number of pilgrims entering Mina, many pilgrims, especially weak or elderly pilgrims, might be separated from their family or establishment. When the lost pilgrims arrive in Mina, they may find it difficult to return since they cannot leave from the same path that they entered from.

III. RELATED WORK
Four main infrastructures are used to realize crowd management and congestion avoidance in confined areas: Wireless sensor networks (WSNs), radio frequency identification (RFID), heterogeneous IoT solutions that combine multiple sensing technologies, and intelligent approaches.
In [11], the authors utilized a framework that supports mobile devices interaction through a smart phone application to gather data from sensors and display the optimal route to the agents. Reference [12] proposed a multi-path routing algorithm based on a cognitive packet network involving two types of WSN nodes for hazard detection and decision-making for guidance. A congestion-aware navigation algorithm was proposed in [13]. Specifically, the authors monitored the evacuees' movements, displayed the evacuation route using sensors and reduced the direction oscillations in navigation. The simulation results highlighted an enhancement in terms of the evacuation time and direction oscillations. Recent studies [14], [15] discussed the applicability of RFID in Hajj management systems since the tags can transmit data in wireless mode with no human intervention, and RFID readers can read multiple tags simultaneously. A case study by the author yielded impressive results in terms of the prompt identification and location of pilgrims. Reference [16] proposed the use of such tags in the King Abdulaziz International Airport for effectively managing and guiding the pilgrims, with the tags being distributed by the country of each pilgrim. However, [17] discussed the technical obstacles and security risks associated with RFID tags, for instance, those pertaining to the effect of natural factors on reliable radio transmissions and security threats such as eavesdropping and tag cloning. The work in [18] proposed a lightweight security protocol to overcome these challenges, which included the use of mutual authentication based on encrypted random numbers, use of digital certificates, automatic resetting of the original states to prevent blocking and jamming, and data encryption.
A crowd monitoring and management framework was proposed in [19], which focused on all the paths pertaining to the ritual locations in Mina. In particular, the authors numbered the paths to the location of every Hajj ritual on each floor and used pilgrim sensor units to identify the entrance and exit locations. This framework was evaluated using three scheduling mechanisms, with weighted round robin achieving the best results. In [20], the author proposed an integrated RFID and WSN tag system that could track, monitor and assist visitors in Al-Masjid Al-Nabawi. The author divided the area into equal cells with static readers to read the tag of every visitor in range, which included data such as the blood pressure and pulse rate to provide any necessary assistance, especially in critical areas such as Mina.
Intelligent approaches such as mobile augmented reality techniques can help alleviate Hajj difficulties, as shown in [21], owing to their powerful processing and high transmission rate. These technologies can be utilized by Hajj authorities for sharing information regarding the pilgrims' movements among staff and operators. In [22], the authors suggested a framework for developing an intelligent realtime virtual environment model to enable the efficient movement of vehicles during the Nafrah traffic, by adopting different movement scenarios, simulation and optimization approaches, which can be used by Hajj authorities. The framework performed a spatial analysis of the current location and simulation to evaluate the efficiency of the current scenario and included a multi-agent artificial intelligent system to model the dependency of traffic paths. In addition, augmented reality has been used in pedestrian surveillance, as demonstrated in [23], in which the authors proposed a fully integrated closed-circuit television (CCTV) based technology that could automate the pedestrian traffic systems by using particle image velocimetry, a machine learning-based regression model, boosted ferns, and the model of a camera perspective to accurate and efficiently predict the pedestrian traffic distribution from multi-cam feeds in a high-density pedestrian traffic video.
In this work, we use a hybrid approach including WSN and RFID technologies. The proposed approach collects data regarding the pilgrims' movement to detect and avoid congestion by routing the pilgrims to alternative paths. Notably, such a hybrid approach exhibits the same advantages and limitations as those of the relevant approaches.
Additionally, a cloud platform is used; the proposed framework thus has two modules: a cloud module and a local module onsite.

IV. THE PROPOSED APPROACH
Before discussing the design of our approach, we outline the following realistic assumptions that are considered in designing our approach and specifying the area of interest. Our assumptions are formulated to match the real scenarios of Hajj based on the information provided by Hajj companies and the Ministry of Hajj and Umrah (MoHU) as they work in the field with the pilgrims. The key assumptions are as follows: 1) Each pilgrim is provided an RFID card in his/her country before arriving in Saudi Arabia. In this study, RFID cards were used to reflect the Hajj conditions at the time of conducting this research. However, cards can be replaced with any alternative wearable technology such as pins, badges, or the RFID bracelets that MoHU plans to implement in subsequent years to avoid the numerous issues related to RFID cards. 2) The RFID cards are connected to the IoT infrastructure built in the holy area of Mecca. 3) Pilgrims carry their RFID cards all times during the Hajj event. 4) LCD monitors are present in the area, which are connected to the cloud and continuously display the best path to guide the pilgrims. 5) Pilgrims follow the instructions and do not enter congested paths, although it is considered that the pilgrims may not follow the instructions with a certain level of randomness (randomized movement). Additional help and guidance for following the instructions can be provided by security guards, as necessary. 6) To address RFID failures, a matching technique is adopted to extract the crowd status from data collected by cameras and other wireless sensor technologies. The collected crowd data are input to the proposed framework to provide the appropriate guidance. 7) As cameras provide full coverage over the area, in addition to the mechanisms to match the data provided by the RFID reader, the proposed approach relies on the most accurate data provided by cameras and RFID readers. 8) All paths are unidirectional with different levels of priority, and each path has a specific capacity. 9) Cameras are installed in each path, with the number of cameras depending on the priority of the path. 10) Data provided by the RFID cards and other entities are legitimate.
A. SYSTEM ARCHITECTURE AND COMPONENTS The proposed system consists of a number of components used for monitoring, simulating, routing and guiding pilgrims to their intended destinations within the Mina area through the best available paths. The overall system architecture and components are shown in Figure 2.

1) RFID CARDS AND READERS
RFID cards represent the primary component of the system architecture. These devices act as the main tracking device to monitor the pilgrim behavior. Each pilgrim carries an RFID card that stores information regarding their health condition, age, nationality and Hajj agency. Each path has one or more RFID readers to detect the signal from the RFID cards and collect information regarding the pilgrims to help calculate the cognition level of the crowd and most suitable path.

2) DECISION NODES (DNs)
DNs are distributed over paths with different densities according to the path class. The DNs receive data from the RFID tags, cameras, and environmental sensors, and input from the MoHU. As soon as a DN receives the data, it starts calculating the risk factors and communicates with its nearby DNs to execute local evacuation in a cooperative way, shows the determined evacuation directions on LCD screens, and reports the data to the cloud servers.

3) CAMERAS
Cameras function as the secondary input source that monitor and capture the pilgrims' behavior. The cameras are connected with DNs to transmit the information regarding the presence of congestion according to the captured movements of pilgrims to the decision nodes.

4) CLOUD COMPONENTS
The cloud has access to all entities of the system. The main role of the cloud in this approach is to manage the data exchange and information integration. Moreover, the cloud is responsible for formulating the evacuation decisions when congestion is detected. In addition, the cloud can communicate directly with the city agencies (Hajj authorities) and pilgrims through LCD screens.

5) GATEWAYS
The local gateway acts as an interface between the local sensors and cloud for data transmission. The outer gateway is an interface between the IoT cloud and city agencies.

6) LCD SCREENS
LCD screens are distributed in multiple points over all paths in the Mina area. Each path has different numbers of screens that have different dimensions and are deployed with different densities depending on the path capacity, priority, and number of intersections. For example, a path with a higher capacity, priority and number of intersections may have a larger number of screens. The screens continuously display the paths that have been identified by the decision nodes and cloud. Moreover, the LCDs are assumed to have an efficient and user-friendly design to provide guidance to the pilgrims in a way that is easy to understand and follow.

7) CITY AGENCIES
City agencies include local authorities that play key roles during Hajj, such as MoHU officials, security personnel, civil defense, healthcare agencies, and any parties related to Hajj. These agencies receive an alert from the cloud servers with a copy of the collected information in the case of dangerous situations to act upon the information. The information collected from cameras and RFID readers are remotely transmitted to DNs stationed at each path. The DNs collect and send data to the IoT cloud through a local gateway for processing. In normal situations, while the data is still being processed and analyzed at the cloud, the DNs locally identify the best paths and display them on the LCD screens. However, in critical situations, the paths identified locally by the DNs may not be as accurate as those determined globally by the IoT cloud that utilizes the information provided by all parties of the system. Therefore, after identifying the optimal paths, the cloud directly updates the DNs and LCD screens. In addition, the cloud alerts MoHU and other Hajj authorities when the congestion level and other risk factors exceed the threshold.

B. ACQUISITION AND ANALYSIS OF CROWD DATA
In the proposed approach, data are collected via RFID sensors, cameras and environmental sensors. The RFIDs collect the pilgrim information, including a pilgrim's name, age, nationality and his/her location at a time T. Cameras collect images of the current situation, and the environmental sensors acquire the environmental information such as the weather and humidity rate.

1) ENVIRONMENTAL CONDITIONS
Environmental conditions such as the weather and quality of air vary with time and can be divided into three categories: favorable (sunny), average (drizzle, fog, and light wind) weather, and unfavorable (dust and/or heavy rain) weather. The pilgrim movements are highly affected by the environmental conditions. Moreover, the environmental conditions increase the risks associated with evacuation.

2) CONGESTION LEVEL
The congestion is monitored and evaluated by tracking the RFID tags, cameras, and sensors located throughout the paths. The congestion is classified into six levels depending on its intensity, namely, extremely low, low, medium to low, medium to high, high, and dangerous. Once the congestion reaches the medium to low level, the system initiates the congestion-avoidance approach.

3) PILGRIM CLASSIFICATION
To effectively manage pilgrims, it is necessary to classify pilgrims into different groups based on the medical condition, age, gender and speed.

4) CLASSIFICATION OF EVACUATION PATHS
The priority of paths is classified into different levels based on the path distance from key services such as Jamarat, hospitals, restaurants, metro stations, entrances, exits and other paths. The paths that are closest to these services are often the most congested. Figure 3 presents the conceptual design of the proposed approach. DNs periodically receive various data regarding the current situation from several devices. The DNs perform certain computations and display the safest paths on LCD screens through the IoT cloud.

C. CONCEPTUAL DESIGN
The main steps performed by our system in real-time are as follows: Step 1. At time T , each DN receives evacuation parameters from the RFID sensors, cameras, sensor nodes, and MoHU. Step 2. The DNs calculate the risk factors, which depend on the classification of the paths, current load, and pilgrims' condition.
Step 3. The DNs compare the calculated risk with a threshold for each path and decide the presence of congestion in any of the surrounding paths. Step 4. Based on the result, if congestion is detected or predicted, the DNs report congestion to the cloud, city agencies, and nearby DNs.
Step 5. The DNs calculate the parameters that maximize the risk according to the information derived from the environmental sensors, RFID tags, and MoHU to decrease the threshold value. Step 6. If the congestion is less than the threshold, the DNs execute the local evacuation plan and notify the nearby DNs. Step 7. The system adjusts the paths and displays them on the LCD screens.

D. MAIN MODULES
Our approach involves three main modules, namely, monitoring, simulation and routing, and guidance modules. Figure 4 shows the interaction among the three modules and the main processes.

1) MONITORING MODULE
The monitoring module collects data from several IoT devices including the RFID card readers, cameras, decision nodes, environmental sensors, and MoHU. Each pilgrim carries an RFID card that tracks his/her location at all times, thereby allowing the system to determine the number of pilgrims at each point. Moreover, the RFID cards contain personal  information regarding each pilgrim such as his/her nationality, age, and health condition.
Furthermore, additional data are collected from environmental sensors that detect the condition of the area, such as rain, dust, humidity, temperature, pressure, and level of oxygen. Moreover, the data from nearby nodes are collected in a localized manner instead of independently collecting data from each node. The system enables communication between nodes to obtain an overall view of the crowd movement and congestion points. The information provided by the MoHU is prioritized in the congestion avoidance decision.

2) SIMULATION AND CLASSIFIED ROUTING MODULE
The simulation and routing module utilizes the information provided by the monitoring module. In Figure 4, in the first two steps associated with the simulation and routing module, the collected evacuation data parameters are transferred to DNs to calculate the risk factors. The value of the risk factors is a function of the pilgrims' data and path state. The medical state of certain classes of pilgrims and their previous behavior might be considered hazardous, leading to higher risk factors. For example, the cultural and physical attributes of certain pilgrims, based on their native environment or health condition, may influence their behavior in congested area and increase the level of risk. Moreover, people with disabilities may slow the pilgrims' movement. These factors affect the flow of paths, movement, and speed. The proposed approach calculates the factors related to each path, such as its capacity, priority, and level, and predicts the load for each path in the Mina area based on the current state. Next, the DNs start identify the optimal routes to all possible destinations by calculating the next hop, expected time for reaching it and its state (passable or congested) based on the factors collected from the previous monitoring module.
Subsequently, the environmental factors, for instance, rain, dust storm, or natural hazards, are identified as they affect the pilgrims' behavior, attitude, and movement. The impact of these environmental factors on the paths and the associated risk percentages, which can increase the total risk probability, are determined.
Next, we calculate the congestion factors for all nearby paths and verify the occurrence of congestion in each path. If the congestion level is higher than the threshold, alternative evacuation paths are determined. Moreover, the module reports congestion to the nearby (predecessor) paths to perform rerouting and avoid congestion. The detected congestion is immediately reported to the MoHU. This module continues to process all paths, identifies the least congested paths and performs rerouting through these paths. Next, the paths are displayed on LCD screens to guide the pilgrims, and the collected data and processed results are reported to and stored in cloud servers. These processing steps are repeated to ensure updated information is available for providing guidance to the pilgrims and addressing the path congestion.
The proposed approach performs classified routing, considering human factors, environmental factors, path priority, and path condition. Routing in this approach is based on classifying entities of the system into different groups or classes, as presented in Figure 5.
The paths are classified depending on their capacity, priority (distance from key point), and usual congestion level. The priority of the paths is classified into different levels based on their distance from key services such as hospitals, restaurants, and stations. The paths that are closest to these services are usually the most congested; since pilgrims must use these paths, they are assigned the highest priority. The capacity of the paths is calculated from the available maps of Mina. In addition, the usual congestion level of each path is considered.
Furthermore, the pilgrims are classified according to their nationality, health condition, age and gender. Nationalitybased classification separates pilgrims depending on their behavior and physical strength. According to their health condition, the pilgrims are classified as healthy pilgrims and pilgrims with abnormal health conditions (pilgrims suffering from any medical condition). According to the age, the pilgrims are split into three groups (0 to 15 y), (16 to 44 y) and (45 y or older) [24]. The gender of pilgrims is either male or female.
Environmental condition can affect the mobility of pilgrims. We consider three weather conditions: favorable, average and unfavorable weather. Unfavorable weather is more likely to influence the risk factor, thereby affecting the mobility of pilgrims.

3) PILGRIM GUIDANCE MODULE
The last module is the guidance module. The primary function of this module is to continuously update and display the most and least congested routes to all possible destinations. To this end, the information collected by the DNs at each link is used. To obtain accurate results, instead of identifying the congestion in a link-wise manner, the system evaluates it for up to two hops to avoid routing to a path that eventually leads to congestion. To realize this aspect, the system allows nearby DNs to communicate with one another and share their congestion levels; in this manner, if the current path is congested, the system alerts predecessor paths to reroute. Similarly, if the DN at the current path detects congestion at the successor path, it begins rerouting to avoid congestion.
These design considerations and the above mentioned modules can address the scalability aspects of crowd management during Hajj. As Hajj requires large crowds to perform the same activities during specific times, our classified routing avoids dangerous crowding scenarios.

V. EXPERIMENTAL DESIGN
In this section, we present the experimental design of the proposed approach. We discuss the characteristics of the area of interest (Mina), input variables, and performance factors. In the following sections, we discuss the modeling of the map, roads, key services, and agents (representing pilgrims) as well as their mobility. We implement our experiments using a multi-method simulation modeling tool known as AnyLogic [25]. AnyLogic provides an efficient simulation engine that allows the user to easily create high accuracy models of large complex systems.
Because the area of interest (Mina) has a large number of paths and key services, we consider a subset of these main paths and key services in the simulation based on their importance. To load the map of Mina in the simulator, we adopt the GIS features available in AnyLogic with an open street map to model the area. Moreover, we use the tools available in AnyLogic to process the details of the map. To add agents to the map, the corresponding paths are drawn for every main road in the map. Each path is decomposed to two nodes pertaining to the beginning and end of the path and the link between the nodes. To represent the intersection between two VOLUME 9, 2021 paths, we create a network of nodes and links between the paths that all agents must pass to reach their final destination. For simplicity, we identify and consider the main roads in Mina, as shown and labeled in Figure 6.
In the modeled area, all the main paths are unidirectional. Each path has a different capacity and threshold. The capacity depends on the priority and width of the actual street, for example, the capacity of paths 1 and 2 is larger than that of the other paths. The threshold for the critical paths that are near the Jamarat Bridge or key services is less than the that for the other paths due to their higher load and level of risk.
Using the tools provided by AnyLogic, we identify four main key services, as shown in Figure 7. These services are considered as the main destination points in our simulation, and each service has a delay to represent the real-life congestion that occurs near the service points. Jamarat Bridge is not considered a service and instead treated similar to the other points since it is the destination point for most pilgrims in the simulation and suffers from extreme congestion. The Al-Khaif mosque is added as a service point after consultation with Hajj agencies; in particular, this mosque is a source of critical congestion as many pilgrims take shelter during the day to reach the mosque. In addition, several small restaurants are present near the mosque, which attract many pilgrims. Medical centers and police stations are essential services that have been known to cause congestion throughout Hajj and are modeled as key services in the performed simulation process.

A. INPUT VARIABLES
In this part, we describe the input variables (independent variables) used to implement the proposed approach and design the experiments. Table 1 defines the range of values allowed for the input variables along with any randomness or probabilities considered in determining these values.
For the input (controllable) variables, as explained previously, the following factors that affect the congestion, routing and mobility of agents are considered: 1) Number of agents.
2) Routing requirements (origin and intended destination). 3) Factors that affect agent's mobility: Speed, age, medical condition and gender. 4) Environmental condition: Favorable (sunny), average (drizzle/fog/light wind), or unfavorable (dust and/or heavy rain). As shown in Table 1, we deploy 30,000 agents to act as pilgrims in our simulation. The speed changes dynamically during the simulation process; for example, the speed of agents with a health condition is decreased by 1 mph, which represents half the normal human speed. In most experiments, the agents' gender is equally distributed, with 50% males and 50% females. The ages are randomly generated ranging from 0 to 80 y. We considered the following age groups: (0 to 15 y), (16 to 44 y) and (45 y or older). The speed of the younger (0 to 15 y) and older (45 y or older) groups is decreased from the normal speed by 0.2 and 0.6 mph, respectively.
The environmental condition is determined manually at the beginning of each experiment. These conditions affect the path threshold, which increases the risk. The increased risk affects the evacuation procedure. We consider three weather conditions: favorable (0), average (1) and unfavorable (2). The default condition is favorable weather (0), which is associated with a 0 risk and does not change any path threshold. Average weather (1) increases the risk to 0.2 (since we use 0 to 1 measures). Unfavorable weather (2) is associated with a high risk (0.4), which reduces the threshold of the paths, causing an alert notification to be sent to the agencies.

B. PERFORMANCE FACTORS
The main performance factors (dependent variables) considered to assess the performance of the approach are as follows: 1) End-to-end delay: Time for pilgrims to move from the starting point, pass the intended destination and reach a specific termination point. The delay is calculated as the difference between the ideal time to reach the final destination and actual time required to reach the destination. 2) Delay-Jitter: Jitter is calculated considering the standard deviation for each delay per path. 3) Number of congestion points: Total number of congestion points with a value exceeding 5 min. 4) Critical congestion points: Total number of congestion points with a value exceeding 10 min, which may trigger high-risk congestion. 5) Delay per paths: Additional time added to each congested path. 6) Number of injuries: Total number of injuries caused by congestion. 7) High risk occurrence: The risk increases under critically unfavorable environmental conditions and when pilgrims from specific nationalities are present.

VI. IMPLEMENTATION AND PERFORMANCE DISCUSSION
In this section, we describe the characteristics of the different algorithms and techniques used to implement the proposed approach. Moreover, we discuss the performance of the proposed approach. Many tools can be used to simulate crowds. However, various tools have different features. To identify the optimal tool with features suitable in the context of the proposed model, a number of crowd simulation environments and their associated features are compared.
AnyLogic is a licensed multi-method simulation modeling tool developed by The AnyLogic Company. AnyLogic models can be developed through any main simulation modeling method, such as discrete event, systems dynamics, and agent based techniques. The animation and visualization in AnyLogic are remarkable, the flowcharts can be converted into interactive movies, and sets of graphical objects are available to visualize people, vehicles, buildings, and other items. Models can be presented in a visually attractive manner.
Many features of AnyLogic can help model, simulate and implement the approach, as a certain layer can be a map of the Mina area, or an image of the map of Mina can be uploaded to easily create paths on Mina streets. Therefore, we use AnyLogic to simulate the proposed approach and test its efficiency with respect to several risk factors. Next, we evaluate the results using common performance factors.
To assess the efficiency of the proposed approach in avoiding congestion and allowing safe evacuation, we compare its performance to that of the conventional shortest path (SP) based evacuation approach, which chooses the shortest path leading to the destination, regardless of the congestion level.
To evaluate the performance of the proposed IoT approach for crowd management (IACM), we conduct 3 experiments to assess the performance of our approach from different perspectives. Each experiment is repeated 5 times and the average values are presented. In addition to repeating the experiments, we calculate the variation (jitter or standard deviation) in the extracted results from different perspectives to assess the consistency of the results. In all the experiments, the simulation is terminated when all live agents complete their tours.
The first experiment is aimed at examining the impact of the change in the number of agents on the performance of the proposed approach and shortest path approach. The second experiment studies is aimed at examining the influence of different weather conditions on the risk factor and evacuation parameters. The third experiment is aimed at examining the impact of the presence of a larger number of pilgrims with abnormal medical conditions, which may restrict the pilgrim movement, and therefore, the evacuation parameters performance factors.

A. EXPERIMENT I: VARYING NUMBER OF AGENTS
This experiment examines the impact of the number of agents on the performance of the crowd management algorithm and compares it to the shortest path-based algorithm. Table 2 shows the average delay, number of injuries and number of congestion points when the number of agents varies from 10,000 to 30,000. The number of agents in the first, second, third, fourth and fifth iterations is 10K , 15K , 20K , 25K and 30K , respectively. As shown in Table 3, an increase in the number of agents increases the number of critical and noncritical congestion points in both approaches. However, the proposed approach can more effectively avoid injuries and minimize the evacuation time and number of critical congestion points. Figure 8 show the average delay time in minutes between the IACM and SP approaches. In all the iterations, the average delay of the proposed approach is less than that of SP. In reality, congestion during Hajj is unavoidable. However, it is necessary to manage the congestion and pilgrim evacuation in a way that avoids any aggravation in the congestion while minimizing or eliminating the occurrence of injuries or death caused by critical congestion. As shown VOLUME 9, 2021  in Table 3, using our approach, up to 57% congestion points can be prevented from transforming into critical congestion points that may lead to death and injuries as a result of exceeding a certain congestion threshold and lack of adequate personal space or ventilation quality.

B. EXPERIMENT II: VARYING ENVIRONMENTAL CONDITION
Experiment II examined the impact of varying environmental conditions on the performance of IACM and SP approach. Figure 9 shows the number of critical and normal congestion points when environmental conditions are favorable, average and unfavorable.

C. EXPERIMENT III: VARYING THE PERCENTAGE OF PILGRIMS WITH SERIOUS MEDICAL CONDITION
In this experiment, we study the impact of varying the percentage of pilgrims with critical health conditions to identify their effect on the overall number of injuries and average delay time when using the proposed approach. In the simulation we consider different percentage values to study the impact. In Figure 10, the results of only three values (25%, 35% and 60%) since they indicate the variation in the number of injuries in all experiments.  Figure 10 shows that when the percentage of pilgrims with critical health conditions does not exceed 25% (<1000 pilgrims), the number of injuries is significantly small. When the percentage is increased to 35% or more, a significant increase occurs in the number of injuries. This phenomenon can be explained by the fact that pilgrims with abnormal health conditions are slower than healthy pilgrims and tend to aggravate both critical and noncritical congestion points, leading to a large number of injuries.
As discussed, employing a congestion avoidance approach helps mitigate injuries, congestion points and critical congestion points. Furthermore, the comparison of the results obtained using the proposed approach and shortest-path approach indicates that the proposed approach yields safer results, thereby reducing injuries and providing a safe path for all pilgrims.

D. FINAL REMARKS ON PERFORMANCE RESULTS
The key objective is to build a congestion avoidance approach that can route pilgrims to their destinations through the safest available paths. We evaluated the efficiency of the proposed approach in reducing the number of injuries caused by congestion points. A comparison of the results obtained using the proposed approach and the shortest path-based approach indicated that the proposed approach can significantly reduce the number of injuries and number of critical and noncritical congestion points. We adopted 30,000 agents (or pilgrims) in our experiments as a typical crowing scenario, as determined in consultation with the management personnel in the region. However, this number may increase, especially in the case of more crowded situations. To simulate such situations, we must increase the number of agents. To ensure the scalability, it is necessary to use a machine with higher resources (with higher computing capabilities and memories). This scalability aspect will be considered in our future work.
Based on the performance evaluation, the following findings can be summarized: 1) The impact of the environmental conditions should be considered while managing crowds to avoid congestion and minimize injuries especially in bad weather. 2) According to the results of Experiment I, when the number of agents is increased, the number of congestion and critical congestion points are increased for both algorithms; however, when the proposed algorithm is adopted, the number of critical congestion points that may cause injury is considerably lower than that associated with the shortest path algorithm. Accordingly, our algorithm can more effectively control the crowd. 3) According to the results of Experiment II, by considering the impact of the environmental conditions, our approach yields a lower number of congestion points and critical congestion points. 4) According to the results of Experiment III, the number of injuries is directly affected by the number of pilgrims with critical health conditions. In conclusion, the proposed approach can reduce the number of injuries and congestion points by utilizing the data collected using classified routing IoT-based technologies to communicate the risk factors on each path.

VII. CONCLUSION
Due to the Covid-19 outbreak and with millions of people visiting holy areas every year to perform Hajj, crowd intelligent management is imperative to prevent disasters that risk the lives of pilgrims or hinder their ability to complete their Hajj rituals in a safe environment [26], [27]. In this paper, we proposed a crowd management approach that utilizes the data associated with the pilgrims and environment to realize classified evacuation in crowded areas. We specifically considered the crowd management issues and approaches in the holy area of Mina.
In designing this approach, we attempted the realization of classified routing that adapts to the pilgrims, environment, and evacuation conditions to define our simulation variables. The design can be varied to attain the highest efficiency. To evaluate the proposed approach, we used AnyLogic to simulate our model and vary the scenarios to test our design to enhance the pilgrims' movement.
In comparison with the shortest-path approach for crowd management, the proposed approach yielded superior results by reducing the number of injuries and congestion points by using IoT-based technologies to communicate the risk factors on each path.
In future work, we aim to expand our performance study by including more iterations and additional crowd scenarios. Moreover, we intend to extend our approach by classifying the health conditions and considering Covid-19 immunity by performing routing based on different classes of diseases or disabilities. Furthermore, we plan to explore the scenarios in which the RFID cards of a set of pilgrims are misplaced, which represents a real scenario during Hajj.