This section describes the proposed technique for retrieving a list of individuals who are exposed to the infected patient and need diagnostic tests.
4.2. Solution Overview
This section presents the two main algorithms that describe the full functionality of the proposed technique.
Algorithm 1 illustrates the pseudocode of the proposed solution for the contact tracing. The algorithm has three input parameters: (a) tracing period $Tracin{g}_{period}$, which represents the incubation period for the disease, (b) time exposure threshold ${T}_{Exposure}$, and (c) social distance ${D}_{Eucl}$ (if the measured distance is less than this distance, this confirms the infection may transmit from an infected individual to a normal one). The algorithm returns the potentially infected list of users based on their trajectories. First, when the infected patient (query user) raises the flag that he has become infected, the algorithm considers this date of the query as the start date of the tracing and subtracts the tracing period from the start date to generate the tracing end date (lines 13 to 14). In line 15, the algorithm iterates from the tracing start date to the tracing end date, and for each iteration, the algorithm obtains all the trajectories that belong to the infected patient on this day (line 17). In line 18, the algorithm iterates over the query user’s trajectories each day. Then, the algorithm sets boundaries for the iterated query object’s trajectory, and these boundaries concern space and time (line 22).
In line 24, the algorithm creates a region named the overlapped region to catch the trajectories of the nearest neighbors’ objects that moved nearby the query object’s trajectory. This region was created by adding the identified ${D}_{Eucl}$ to the boundaries created around the query object’s trajectory from all sides. Next, in line 26, the algorithm employs the threedimensional RTree index to retrieve all trajectories included from the start time to the end time of the query object’s trajectory that moved through the overlapped region created in line 24. The algorithm considers these trajectories as suspected, and they need to be investigated from space and time perspectives to confirm the infection based on the disease transmission conditions. The algorithm iterates over these overlapped trajectories, and for each iteration, the algorithm checks the infection exposure criteria between the query object’s trajectory and iterated trajectory. If the iterated trajectory matches the identified criteria, the algorithm includes this trajectory in the infected list; otherwise, it iterates the exposure checks performed by Algorithm 2 (lines 27–32) again. It is critical to note that the algorithm configures the tracing modes before running occurs. If the tracing mode is “InDirect”, the algorithm makes recursive calls to retrieve the contacts of contacts by utilizing the direct tracing in each iteration (lines 35–40). Finally, the algorithm returns the infected list of users and their trajectories.
It is critical to note that for all points discovered with a time difference of zero and spatial distance less than or equal to the identified social distance, the proposed technique considers them as hotspots, which means places with significant risk or danger.
Algorithm 2 describes how the exposure is computed between the infected patient and a normal individual. The result indicates if the infection was transmitted to the normal individual from the infected patient or not. The algorithm receives four parameters: (a)
${\tau}_{1}$, which represents the trajectory of the infected patient; (b)
${\tau}_{2}$, which represents the trajectory of the suspected user; (c)
${T}_{Exposure}$, which represents the identified exposure time period with the same value configured in Algorithm 1; (d)
${D}_{Eucl}$, which represents the identified distance with the same value configured in Algorithm 1. The algorithm returns a boolean flag that indicates if this normal individual becomes infected or not. First, the algorithm iterates over both trajectories’ points to ensure if the objects’ of these trajectories meet each other at a specific point. In line 7, the algorithm checks if the time difference between the iterated points is 0 or not. If the time difference is 0, this means that these trajectories are at the same point or different points at the same time. The algorithm makes another check before starting the tracing by checking the distance between the meeting points
$Poin{t}_{i}$ from
${\tau}_{1}$ and
$Poin{t}_{j}$ from
${\tau}_{2}$. If the distance is greater than the
${D}_{Eucl}$, the algorithm does not complete the tracing and continues its iterations for other meeting points; otherwise, the algorithm completes the tracing. Subsequently, in line 9, the algorithm captures the time of
$Poin{t}_{i}$ and sets the value in a parameter named StartTime. After that, in line 10, the algorithm defines a new parameter named EndTime to store another specific time of a point.
Algorithm 1 TraceAll: Contact Tracer Technique 
 1:
procedure
Contact_Tracer  2:
INPUT: Tracing Period Tracing_{period}, Time Threshold T_{Exposure}, Social Distance D_{Eucl}.  3:
/* Overlapped Traces list */  4:
Let OverlappedTracesList OL $\leftarrow \varphi $  5:
/* Infected list */  6:
Let SuspectedList IL $\leftarrow \varphi $  7:
/* Overlapped Region */  8:
Let OverlappedRegion Region_{Overlapped} $\leftarrow \varphi $  9:
/* Region Bounding Query Trajectory */  10:
Let Region Bounding${\tau}_{Q}\leftarrow \varphi $  11:
/* Query Trajectories List */  12:
Let $Q{L}_{\tau}\leftarrow \varphi $  13:
Tracing_{StartDate} = CurrentDate  14:
Tracing_{EndDate} = CurrentDate − Tracing_{period}  15:
for Tracing_{StartDate} to Tracing_{EndDate} do  16:
/* ${\tau}_{Q}$ Query object’s trajectories */  17:
Get $Q{L}_{\tau}$ in iterated day  18:
for each ${\tau}_{Q}\in $$Q{L}_{\tau}$ do  19:
/* ${\tau}_{Others}$ Other object’s trajectories */  20:
Get ${\tau}_{Others}$ in iterated day  21:
/*Region created from max&min points ${\tau}_{Q}$*/  22:
Region${\tau}_{Q}$ = Bound ${\tau}_{Q}$  23:
/*Add social distance to overlapped region*/  24:
Region_{Overlapped} = D_{Eucl} + Region${\tau}_{Q}$  25:
/*Get traces in overlapped region by RTree*/  26:
OL ← RTree(Region_{Overlapped},${\tau}_{Others}$)  27:
for each o ∈ OL do  28:
isExposed=IsExposed(${\tau}_{Q}$,o)  29:
if isExposed = True then  30:
add o to IL  31:
end if  32:
end for  33:
end for  34:
end for  35:
if TracinMode = InDirect then  36:
for 0 to Tracing_{period} do  37:
/*Increment IL by fetched contacts*/  38:
Call Mobility_Tracer  39:
end for  40:
end if  41:
end procedure  42:
OUTPUT: Return objects belongs to IL

The algorithm computes the EndTime by adding
${T}_{Exposure}$ to the StartTime defined at line 9. Next, the algorithm obtains the subtrajectory from
${\tau}_{1}$ (starting from a point located at the StartTime and extending to the point that exists at the EndTime) and stores the result as a new variable named
$Sub{\tau}_{1}$ (line 12). Similarly, the algorithm obtains the subtrajectory from
${\tau}_{2}$ (starting from a point located at the StartTime and extending to the point that exists at the EndTime) and stores the result as a new variable named
$Sub{\tau}_{2}$ (line 14). In line 16, the algorithm computes the average distance between the created subtrajectories. If the average distance is less than or equal
$Dsocial$, the algorithm returns that the
${\tau}_{2}$ belongs to an infected individual and breaks the loops; otherwise, the algorithm continues the iterations.
Algorithm 2 Is Exposed 
 1:
procedure
IsExposed  2:
INPUT: Trajectory 1 ${\tau}_{1}$, Trajectory 2 ${\tau}_{2}$, Time Threshold, T_{Exposure}, Social Distance ${D}_{Eucl}$.  3:
let isExposed $\leftarrow false$  4:
for each Point_{i}$\in $ do  5:
for each Point_{j}$\in $ do  6:
/* Checks if ${\tau}_{1}and{\tau}_{2}$ meets */  7:
if T_{Diff}(Point_{i}, Point_{j}) = 0  8:
&dist(Point_{i}, Point_{j}) ≤ D_{Eucl} then  9:
StartTime = TimeStamp of Point_{i}  10:
EndTime = startTime + T_{Exposure}  11:
/*Points from startTime to EndTime ${\tau}_{1}$*/  12:
Sub${\tau}_{1}$ = SubTrajectory from ${\tau}_{1}$  13:
/*Points from startTime to EndTime ${\tau}_{2}$*/  14:
Sub${\tau}_{2}$ = SubTrajectory from ${\tau}_{2}$  15:
/* Computes the average distance */  16:
if dist(Sub${\tau}_{1}$, Sub${\tau}_{2}$) ≤ D_{Eucl} then  17:
isExposed = true  18:
Break loops; Return the result  19:
end if  20:
end if  21:
end for  22:
end for  23:
end procedure  24:
OUTPUT: Return is Exposed

It is important to bear in mind that the distance between
$Sub{\tau}_{1}$ and
$Sub{\tau}_{2}$ when meeting points are discovered is measured based on the Hausdorff distance technique [
34,
35,
36]. The Hausdorff distance technique is described in detail in
Section 4.3. Indeed, the technique iterates over points
$Sub{\tau}_{1}$, and in each iteration, computes the distance between
$Sub{\tau}_{1}$ points and
$Sub{\tau}_{2}$ points, obtains the minimum distance for each point comparison, and finally, produces the maximum of minimum distances generated in each iteration. Likewise, the technique iterates over points
$Sub{\tau}_{2}$, and in each iteration, computes the distance between
$Sub{\tau}_{2}$ points and
$Sub{\tau}_{1}$ points, obtains the minimum distance for each point comparison, and finally, produces the maximum of minimum distances generated in each iteration. In the end, the technique produces the maximum for scores obtained from
$Sub{\tau}_{1}$ and
$Sub{\tau}_{2}$, and this distance is considered the total distance between
$Sub{\tau}_{1}$ and
$Sub{\tau}_{2}$.
In this work, we adapt the Hausdorff technique to cope with the proposed cases. The adaption is made by considering if the distance between any two points exceeds the ${D}_{Eucl}$, the Hausdorff technique stops scanning other points and returns to Algorithm 2 that the calculated distance between the compared subtrajectories is greater than ${D}_{Eucl}$, which saves more processing time.
Figure 1 illustrates how the proposed technique bounds the query object’s trajectory and creates the overlapped region. First, it searches for the minimum point and maximum point in the query object’s trajectory. The maximum point means maximum longitude and latitude through the query object’s trajectory, and the minimum point means minimum longitude and latitude through the query object’s trajectory. Next, it calculates the height and width of the rectangle region that surrounds the query object’s trajectory. According to the rectangle boundaries created around the query object’s trajectory, the technique starts to create the overlapped region by adding the identified “social distance”
${D}_{Eucl}$ to all sides of the created rectangle and generates a larger rectangle to be the overlapped region.
Figure 2 provides an overview of how the proposed technique catches the nearest neighbor’s trajectories that move around the query object’s trajectory and considers them as suspected cases. First of all, the system exploits the overlapped region that resulted from
Figure 1 and employs a threedimensional RTree to perform a range query to obtain all trajectories located in the overlapped region that are also between the start and the end time of the query object’s trajectory. In particular, the three dimensions here mean two dimensions of space and one dimension for time. More specifically, RTree is a tree index structure used to handle spatial data objects efficiently. The main idea of the RTree structure is to group nearby spatial objects and store them in a minimum bound rectangle (MBR) in the next level of the tree (the R character in the word RTree stands for the rectangle). This work chooses RTree because it is much faster in nearestneighbor queries and window queries, such as “inside”, “covers”, and “contains”.
Figure 3 provides a detailed overview of the breakdown of the tracing process, according to three fundamental properties; meeting points, social distance, and exposure time. Furthermore,
Figure 3 presents the intercorrelations among these properties. After getting the overlapped trajectories from
Figure 2, the proposed technique starts to inspect each overlapped trajectory.
Figure 3 describes three cases for inspection to detect if this trajectory belongs to an infected patient or not. In the first case, in point P1, the proposed technique detects that the time difference between P1 and the corresponding point
$P{1}_{Q}$ in the query object’s trajectory is zero, but the distance between these two points is greater than the identified social distance
${D}_{Eucl}$, so the technique continues scanning other parts of the trajectories. In the second case, the technique detects that the time difference between point P2 and the corresponding point
$P{2}_{Q}$ in the query object’s trajectory is zero, and after that, the technique checks the distance between these points and finds that the distance is less than the identified social distance. As a result, the technique starts to capture the subtrajectories from both trajectories (query object’s trajectory and trajectory 5) to compare them. These subtrajectories were created by selecting a part from each trajectory, starting from points with time difference zero until the point at a time after adding the identified “exposure time”. Then, the technique computes the average distance between these subtrajectories; in this case, the technique finds that the average distance is greater than the identified social distance, so the technique continues scanning other parts of the trajectories. In case 3, it is the same as case 2, except that the average distance between the created subtrajectories is less than the identified social distance, and the technique identifies that this trajectory belongs to an infected user.
The robustness of our proposed solution lies in answering contact tracing queries efficiently and in a responsive time manner. Furthermore, the flexibility in retrieving the contacts and flexibility to configure the incubation period of the disease allows the enduser to easily control the contact tracing process in realtime.