# An IoT-Based COVID-19 Prevention and Control System for Enclosed Spaces
## 3 Materials and Methods
### Booking Algorithm  
Subareas exist in an enclosed space, e.g., different shops and dining rooms are in a shopping mall. Physically, each subarea is able to contain plenty of people; nevertheless, gathering crowds lead to higher infection risks. Hence, an optimized booking algorithm is introduced. Here, an example to explain how to calculate \(w\), \(s\), and \(r\) is shown in Table 1. There are 4 people (A, B, C, and D) applying to enter an area which can only contain 1 person. Related details are shown below (Table 2). At 12:00, [PERSON] applies to enter the area, and he plans to stay there for about 1 minute (service time). At 12:01, [PERSON] attempts to enter the area and the request is then immediately satisfied. At 12:02, [PERSON] should wait for [PERSON] until 12:05, and so should D. At 12:05, the waiting time for [PERSON] and D is 3 minutes and 1 minute, respectively. The booking algorithm is a variant of the original HRRN algorithm. In the original HRRN algorithm, \(r\) is defined as below (Equation (1)). \[r=\frac{w+s}{s}=1+\frac{w}{s} \tag{1}\]  
The main idea of the HRRN algorithm is to allocate the CPU resource to the job or process waiting longer (greater \(w\)) and requiring less service time (less \(s\)), i.e., the job or process with greater \(r\) has higher priority to get the CPU resource. In the booking algorithm, an area is seen as a CPU, and people are seen as processes. If the space can contain the amount of people who are requesting to enter, their requests will be satisfied immediately (e.g., 3 people concurrently apply to enter an area with 5 free vacancies). Nonetheless, pandemic guidelines do not encourage a person to spend too much time waiting. Additionally, for fairness, individuals requiring too little service time are also not encouraged. Therefore, the original definitions of waiting time and service time are modified. In Equations (2)-(4),  
\[f(w)=\left\{ \begin{aligned} w,\ 0\leq w<w_{0}\\ C_{1}\ln w+w_{0}-C_{1}\ln w_{0},\ w\geq w_{0},\ C_{1}>0\end{aligned} \right. \tag{2}\]  
\[g(s)=\left\{ \begin{aligned} C_{2}\ln\frac{1}{s}+s_{0}-C_{2}\ln \frac{1}{s_{0}},\ 0<s\leq s_{0},\ C_{2}>0\\ s,\ \ s>s_{0}\end{aligned} \right. \tag{3}\]  
\[r=1+\frac{f(w)}{g(s)} \tag{4}\]  
\(C_{1}\) and \(C_{2}\) are constant values preliminarily set by the manager of an area. Other related scheduling algorithms such as FCFS, SJF, and HPF are unsuited for COVID-19 prevention and control. FCFS ensures that a person who comes earlier can also get an earlier permit. However, people who only need to stay in an area for a short time may wait for a long time. The sum of waiting time of all people will not be the minimum. Though SJF is conducive to getting a minimum total waiting time, it is unfair for people needing to stay in an area for a longer time, leading to bad user experience. As for HPF, we cannot confirm the priority values for individuals easily in advance. Therefore, the \begin{table}
\begin{tabular}{c c} \hline \hline
**Name** & **Abbreviation** \\ \hline Waiting Time & \(w\) \\ Service time & \(s\) \\ Response Ratio & \(r\) \\ Modified Waiting Time & f(\(w\)) \\ Modified Service Time & f(\(s\)) \\ \hline \hline \end{tabular}
\end{table} 
Table 1: Symbol table of the algorithm. \begin{table}
\begin{tabular}{c c c} \hline \hline
**Person Name** & **Booking Time** & **Service Time** \\ \hline A & 12:00 & 1 min \\ B & 12:01 & 4 min \\ C & 12:02 & 6 min \\ D & 12:04 & 0.5 min \\ \hline \hline \end{tabular}
\end{table} 
Table 2: Information about bookings. HRRN is a compromise which considers both COVID-19 prevention and control and user experience. Let \(C_{1}=C_{2}=1\), \(w_{0}=s_{0}=1\). Hence, Equations (5) and (6) are presented. \[f(w)= \begin{cases}\begin{array}{c}w,\ 0\leq w<1\\ \ln w+1,\ w\geq 1\end{array}\end{cases}  \tag{5}\]  
\[g(s)= \begin{cases}\begin{array}{c}\ln\frac{1}{s}+1,\ 0<s\leq 1\\ s,\ s>1\end{array}\end{cases}