# The Efficient Processing of Moving \(k\)-Farthest Neighbor Queries in Road Networks +
## 5 MOFA Algorithm for M\(k\)FN Query Processing in Road Networks
Accordingly, \(d(q_{b},f)\geq\)\(d_{\mathit{camd}}(q_{b})\). Unnecessary facilities \(f\) should be removed from \(\Sigma(q_{b})\); thus, each facility \(f\) in \(\Sigma(q_{b})\) is examined to verify that \(f\) is a candidate facility for \(\overline{q_{s}q_{e}}\). \(f\) is removed from \(\Sigma(q_{b})\) if it does not satisfy the qualification of a candidate facility. Finally, the set of candidate facilities for \(\overline{q_{s}q_{e}}\), \(\Sigma(q_{b})\) is returned either if all of the facility clusters are investigated or if \(d_{\mathit{camd}}(q_{b})>d_{\mathit{max}}(q_{b},\overline{F_{C}})\) (Line 11 and 12), i.e., the candidate distance is larger than the largest distance from \(q_{b}\) to the facility cluster \(\overline{F_{C}}\). ```
0:\(k\): number of FNs requested for \(q\), \(\mathit{len}(\overline{q_{s}q_{e}})\): length of \(\overline{q_{s}q_{e}}\), \(q_{b}\): border point of \(\overline{q_{s}q_{e}}\), \(\overline{F}\): set of facility clusters
0:\(\Sigma(q_{b})\): set of candidate facilities for \(\overline{q_{s}q_{e}}\), which are obtained from \(q_{b}\)
1:\(\Sigma(q_{b})\leftarrow\emptyset\)// The set of candidate facilities for \(\overline{q_{s}q_{e}}\) is initially set to the empty set. 2:\(d_{\mathit{camd}}(q_{b})\gets 0\)// \(d_{\mathit{camd}}(q_{b})\) determines whether \(f\) is a candidate facility for \(\overline{q_{s}q_{e}}\) or not. 3:// Section 4.2 elaborates the calculation of the largest distances between \(q_{b}\) and facility clusters in \(\overline{F}\). 4:for each facility cluster \(\overline{F_{C}}\)\(\in\)\(\overline{F}\)do
5: compute \(d_{\mathit{max}}(q_{b},\overline{F_{C}})\)
6:// The facility clusters \(\overline{F_{C}}\) are arranged for \(q_{b}\) in a decreasing order based on \(d_{\mathit{max}}(q_{b},\overline{F_{C}})\). 7:\(\overline{F}\leftarrow\)\(\mathit{arrange\_facility\_clusters}(\overline{F})\)// \(\overline{F}\) keeps the ordered facility clusters for \(q_{b}\). 8:// Facility clusters are examined consecutively. 9:for each ordered facility cluster \(\overline{F_{C}}\)\(\in\)\(\overline{F}\)do
10:// Note that \(d_{\mathit{camd}}(q_{b})\) is updated in Line 23. 11:if\(d_{\mathit{camd}}(q_{b})>d_{\mathit{max}}(q_{b},\overline{F_{C}})\)then // The facilities in \(\overline{F_{C}}\) cannot be candidate facilities for \(\overline{q_{s}q_{e}}\). 12:go to line 24// Each facility \(f\) in \(\overline{F_{C}}\) is accessed to retrieve candidate facilities for \(\overline{q_{s}q_{e}}\). 13:for each facility \(f\in\overline{F_{C}}\)do // If \(q_{b}\) is inside \(\overline{F_{C}}\), then \(d(q_{b},f)\) is calculated by a graph search algorithm. 14:if\(q_{b}\in\overline{F_{C}}\)then \(d(q_{b},f)\) is calculated by a graph traversal algorithm such as [27]
15:else
16:\(d(q_{b},f)\leftarrow\)\(\mathit{min}\{d(q_{b},f_{b})+d(f_{b},f_{b})|f_{b}\in B(\overline{F_{C}})\}\)// Note that the path from \(q_{b}\) to \(f\) is \(q_{b}\to f_{b}\to f\). 17:// If \(d(q_{b},f)\geq d_{\mathit{camd}}(q_{b})\), then \(f\) should be included in \(\Sigma(q_{b})\). 18:if\(d(q_{b},f)\geq d_{\mathit{camd}}(q_{b})\)then \(\Sigma(q_{b})\leftarrow\Sigma(q_{b})\cup\{f\}\)// \(\Sigma(q_{b})\) collects candidate facilities for \(\overline{q_{s}q_{e}}\). 19:\(d_{\mathit{camd}}(q_{b})\gets d(q_{b},f_{\mathit{kth}})-\mathit{len}( \overline{q_{s}q_{e}})\)// \(f_{\mathit{kth}}\) is the current \(k\)th FN of \(q_{b}\). 20:// Unnecessary facilities are eliminated from \(\Sigma(q_{b})\). 21:for each facility \(f\)\(\in\)\(\Sigma(q_{b})\)do // If \(d(q_{b},f)<d_{\mathit{camd}}(q_{b})\), then \(f\) is no longer a candidate facility for \(\overline{q_{s}q_{e}}\). 22:if\(d(q_{b},f)<d_{\mathit{camd}}(q_{b})\)then // \(f\) is removed from \(\Sigma(q_{b})\). 23:\(\Sigma(q_{b})\leftarrow\Sigma(q_{b})-\{f\}\)// The set of candidate facilities for \(\overline{q_{s}q_{e}}\), \(\Sigma(q_{b})\), is returned. 24:return\(\Sigma(q_{b})\)
```  
**Algorithm 2**\(find\_candidates(k,q_{b},len(\overline{q_{s}q_{e}}),\overline{F})\).