Graph-Indexed k NN Query Optimization on Road Network

: The nearest neighbors query problem on road networks constitutes a crucial aspect of location-oriented services and has useful practical implications; e


Introduction
The nearest neighbors (top-k nearest neighbors (kNN)) query in a road network is an essential problem in location-based services.The kNN search is applied in various practical contexts.For example, when using hospitality reservation services such as Tongcheng-Elong, it is crucial to show a range of venues near the user's location.Similarly, in vehiclefor-hire platforms like Didi Chuxing, it is advantageous to offer a variety of vehicles within a short distance of the user.
Given a road network G(V,E), a set of candidate objects M, and a query vertex q, the goal is to find the k objects in M that are closest to q. Figure 1 shows the example of a road network G, a moving object m 1 is on the edge from v 6 to v 3 , dist(v 3 , v 6 ) = 2, assuming all vertices are candidates.Given a query vertex v 3 , the four nearest neighbors of v 3 are v 3 , v 6 , v 7 , and v 10 , with shortest network distances to v 3 of 0, 2, 3, and 4, respectively; then, the three nearest moving objects are m 1 , m 2 , and m 5 .The kNN query problem on a road network has seen various research results.The most simple and direct solution is to use Dijkstra's algorithm [1]; i.e., given a query vertex q, search for vertices in order of non-decreasing distance from other vertices to q, ending when k vertices are found.Although this method is simple, the time cost is high, especially when the dataset is relatively large.The state-of-the-art algorithm for the kNN problem in road networks is TEN-Query [2], using the TEN-Index, which is based on tree decomposition.Mapping the graph into a tree structure, the kNN results for each vertex are precomputed and stored in the index.However, the establishment of the index is limited by the value of k, and the algorithm cannot perform queries when k increases.We have designed an index that breaks this limit by storing all candidate vertices in the local range of each vertex.Using a new tree decomposition generation algorithm, an average weight generation algorithm is used to construct tree decomposition.
The main contributions of this paper are as follows: (1) Conventional tree decomposition is refined based on the minimum degree principle, and we propose an flow graph index generated from a graph-decomposed tree, which can effectively preserve distance information within the road network; (2) Based on the flow graph index, the kNN query algorithm is proposed to significantly reduce the retrieval space of candidate nodes; thereby, it can enhance the performance of kNN queries in road networks; (3) Experiments on real road networks confirm the efficiency and accuracy of the proposed algorithm.
The remainder of this paper is organized as follows.Section 2 reviews related literature.Section 3 describes the problem.Section 4 explains the index-construction methodology and query algorithm.Section 5 reviews our findings.Section 6 presents our conclusions.

Related Work
The kNN query can be based on Euclidean space or a transportation network.We concentrate on kNN queries within relaxation networks, which can be in either a static or dynamic environment.
The most elementary solution for kNN queries is Dijkstra's algorithm.Given a query point q, the algorithm searches for vertices in non-decreasing order of distance from the remaining vertices, stopping when k objects are found.Although effective, this is timeconsuming, especially in large networks and when candidate objects are far away.
The grid-based index is a typical index structure in road network queries.D. He et al. [3] proposed a grid-based kNN index, GLAD, dividing road networks into 2 x • 2 x grids according to the vertex latitude and longitude, maintaining a list of contained objects for each grid.To answer a kNN query, GLAD searches for objects starting from the mesh containing the queried vertices and updates the results by exploring adjacent meshes.Dong Tianyang et al. [4] introduced direction-aware kNN (DAKNN) for moving objects on road networks, which employs an R-tree and a simple grid as fundamental structures to index the static road network and moving objects, respectively.An azimuth represents the moving direction of a target in the road network, and a local network extension method is used to quickly judge the direction of the moving target.
Graph partition-based indices are also used in kNN queries.Bilong Shen et al. [5] proposed a V-tree index to support efficient kNN searches and dynamic updates for moving objects.They iteratively divide the road network into sub-networks, build a tree structure on top of these, and associate a moving object with the nearest vertex in the V-tree.When updating the position of an object, only the tree nodes on the path from the corresponding leaf node to the root must be updated.
Zhong R et al. [6] proposed a balanced search tree index, G-tree, recursively dividing a road network into sub-networks, where each G-tree node corresponds to a sub-network.They introduced a best-first search algorithm on road networks, and an assembly-based approach to efficiently compute the minimum distance from a G-tree node to a query location.Li Z et al. [7] proposed G*-tree, an improved kNN index structure, establishing shortcuts between selected leaf nodes to address the low query efficiency of G-tree.
Dan T et al. [8] proposed LG-tree, which partitions large graphs into subgraphs and indexes these using balanced trees.LG-tree constructs a hierarchical structure based on Dynamic Index Filtering (DIF) and boundary vertices, using stage-based dynamic programming to ensure the efficiency of the shortest distance search.
Bao JL [9] introduced the index structures used in nearest neighborhood queries, discussed current challenges, and explored future research focuses on nearest neighbor query techniques in road networks.Li L et al. [10] addressed the problem of continuously reporting alternative paths for users traveling along a given path by accessing vertices in ascending order of maximum depth value, so as to improve computational efficiency and enhance accuracy.Yuan-Ko Huang et al. [11] addressed the kNN skyline in dynamic road networks, conducting queries using three data structures: object attribute control matrix (OADM), road distance ranked list (RDSL), and skyline object extension tree (SOET).R. Halin et al. [12] introduced the concept of tree decomposition in 1976, expediting graph problem calculations by mapping graphs into tree structures.Dian Ouyang et al. [13] built on this with H2H-Query, a method to efficiently calculate the shortest distance between two vertices on a road network.The shortest distance for each vertex in each ancestor node is stored, enabling the most straightforward network distance calculation between any two points in O(w) time.They subsequently proposed a tree-decomposition-based index, TEN-Index, which precalculates the shortest distance from each vertex to its ancestor vertex and stores each vertex's local kNN, which reduces query times and enhances kNN performance.
There are other kNN indices and algorithms.Hyung-Ju et al. [14] proposed an efficient continuous search algorithm, UNICONS, using Dijkstra's shortest path algorithm and a precalculated NN list to enhance NN query performance.Maytham Safar [15] used network distance rather than Euclidean distance as the shortest path metric.Guang Zhong Sun [16] suggested a straightforward, effective precomputation technique for kNN calculations on extensive road networks, selecting a suitable representative node set R (a subset of V) from road network G(V,E) and precomputing the distance value for any pair in R.
In response to the natural extension of kNN queries for multiple moving objects, i.e., Aggregate k Nearest Neighbor (AkNN) queries, Abeywickrama T [17] proposed the Compressed Object Landmark Tree (COLT) data structure, which implements efficient hierarchical graph traversal and performs various aggregation functions effectively.Bareche I et al. [18] proposed a Velocity Spatiotemporal (VeST) indexing approach for continuous queries, mainly Continuous K-Nearest Neighbor (CKNN) and continuous range queries using Apache Spark.The proposed structure is based on a selective velocity-partition method, which reduces the update cost and improves the response time and query accuracy.Ying Ju Chen et al. [19] proposed the SQUARE algorithm, constructing a network index resembling the decoupling model while using coupling concepts to maintain kNN information relative to hotspot areas in the network index.Hotspots represent areas where frequent queries are found in history.Aye Thida Hlaing et al. [20] proposed a fast RkNN search algorithm using Simple Materialized Path View (SMPV), employing an Incremental Euclidean Restriction (IER) strategy for swift kNN queries.Luo et al. [21] proposed an index-based kNN query solution, Toain, based on a shrinkage hierarchy, and utilizing a shortcut-based index, SCOB, to accelerate query processing.Chuanwen Li et al. [22] proposed a kNN query algorithm using an index structure based on a lazy update strategy, capitalizing on both CPU and GPU resources.The region being queried is first identified, and the GPU is used to update the index for that region.The index is queried using the GPU and a candidate result set is generated, which is refined by the CPU to obtain the final result.

Problem Definitions
We study the kNN query problem on road networks based on tree decomposition, with symbols as defined in Table 1.
The road network is modeled as a weighted undirected graph G(V,E), where V is a vertex set and E is an edge set.For an edge e(v 1 , v 2 ), weight w(e) or w(v 1 , v 2 ) represents the length of the edge.A path p is a vertex sequence p = (v 1 , v 2 , . . ., v k ), where for any ) given two vertices v 1 and v 2 ; the shortest path between them is a path p from v 1 to v 2 that satisfies w(p) as s minimum.In this paper, dist(v 1 , v 2 ) is used to represent the length of the shortest path from v 1 to v 2 .
We study the road network kNN query in a static environment, i.e., when both the query point and candidate object are static.For the dynamic road network kNN query, the dynamic moving candidate object can be mapped into offset neighboring vertices; thus, it can be transformed into a static environment.Specifically, given a query point q and a moving object m, assuming that q is located on the edge e 1 = (v s , v e ), the distance from the vertex v e is d q , m is located on the edge e 2 = (v s , v e ), and the distance to the vertex v s is d m .Then, the distance between q and m is expressed as dist(q, m) = dist(v e , v s ) + d q + d m .This paper defines the kNN query problem as follows.

X(v).extList
Node expansion list of node X(v), sorted in ascending order of road network distance from node The true shortest road network distance from vertex The current shortest road network distance from vertex v 1 to vertex v 2 along path p R kNN set of query point q, sorted in ascending order of road network distance from q root The root of the kNN index threshold Threshold M Candidate vertex set Definition 1 (kNN Query).Given a road network G(V, E), a query point q, an integer k, and a set of candidate vertices M (|M| > k), the kNN query aims to calculate a set R that satisfies: In the road network shown in Figure 2, there are ten vertexes, the distance between v 2 to v 3 is 6, given the query point v 3 , with k = 3, and dotted line vertices (such as v 1 , v 5 , v 6 , v 8 , and v 10 ) are candidate vertices, the 3NN of v 3 in the candidate vertices is R = {v 6 , v 10 , v 8 }, and their shortest network distances to v 3 are 2, 4, and 5, respectively.Notably, due to the potential for identical edge weights, the kNN for each vertex may need more uniqueness.This factor does not compromise the algorithm's validity, as presented in this treatise.

Index and Algorithm
We present the solution to the kNN problem on road networks, using an amalgamated index structure, Average Weight Tree Decomposition with Ancestor Table and Children Table (AWTDAC).

Average Weight Tree Decomposition Index Construction
Definition 2 (Tree Node).For each vertex v in the road network G(V, E), its corresponding tree node is denoted by X(v), X(v) represents a subset of the road network vertex set V, comprising vertex v and its neighboring vertices.In this paper, v is referred to as the principal vertex of X(v) and is denoted in gray, symbolized by X(v).grayId.The neighboring vertices of v are considered adjacent vertices of X(v).
Taking the road network shown in Figure 1 as an example, Figure 3 depicts the tree node X(v 3 ) corresponding to vertex v 3 , where v 3 serves as the principal vertex, and v 1 , v 4 , and v 8 constitute adjacent vertices.The calculation process of the specific values of the adjacent vertices of v 3 is based on the average weight tree decomposition process.The result comes from the constructed decomposition tree.Tree decomposition [5] accelerates the computation of numerous graph problems by mapping graphs onto tree structures and is defined as follows.
Definition 3 (Tree Decomposition).Given a graph G(V, E), its tree decomposition is denoted T G , and is composed of several tree nodes with the set of all tree nodes represented as Λ.T G satisfies the following conditions: Definition 4 (Tree Height and Tree Width).Given a tree decomposition T G , this manuscript stipulates that the root node's depth is 1, while the depth of other tree nodes is the depth of their parent node plus 1.Based on this, the tree height of T G is defined as the maximum depth of all tree nodes, denoted by h.The treewidth of T G is defined as the maximum number of adjacent vertices among all tree nodes, represented by w; that is, Definition 5 (Elimination Order).Given a graph G(V, E), this manuscript sequentially removes vertices in G following a specific rule.For each currently deleted vertex v, v.deleteOrder is utilized to record its removal order, referred to as the elimination order of vertex v.
For instance, considering the road network G(V, E) depicted in Figure 1, vertex v 6 is the first to be removed; hence, v 6 .deleteOrder= 1.
We briefly describe the generation process of tree decomposition.For any road network G(V, E), the traditional tree decomposition generation algorithm is based on the principle of minimum degree (i.e., the vertex with the smallest degree in graph G) and it is divided into two stages.
Stage One: Vertex Removal.Select vertex v with the smallest degree in G each time, and use v and its neighbors as tree nodes X(v).For any pair of neighbors (v 1 , v 2 ) of v, if no edge exists between v 1 and v 2 , add an edge e(v 1 , v 2 ), whose weight . Finally, delete v from G. Repeat this step until all vertices in G have been removed and record the elimination order of each vertex.
Stage Two: Tree Decomposition Construction.For each tree node X(v) generated in Stage One, select the vertex v with the smallest elimination order among the adjacent vertices of X(v), designating X(v ) as the parent node of X(v).Repeat this step until all tree nodes coalesce into a tree.
Figure 4 exhibits a tree decomposition created using the minimum degree principle for the road network G illustrated in Figure 1.The gray vertices are the principal vertices, like v 1 is the principal vertex, and v 2 , and v 9 constitute adjacent vertices.In this paper, a tree decomposition is constructed by the average weight principle.Both the average weight principle and the minimum degree principle are important concepts in graph algorithms, each having advantages in different types of problems.The average weight principle typically provides better results in dealing with weighted graph problems because it considers the weights of all nodes, not just their degrees.The minimum degree principle, on the other hand, is more suitable for specific problems such as connectivity issues.The average weight principle can provide improvements compared to the minimum degree principle, especially in dealing with weighted graph problems.However, the minimum degree principle may be more effective in dealing with certain specific types of problems.Therefore, the choice of which principle to use depends on the specific problem being addressed and the characteristics of the data. 143 6 The proposed average weight tree decomposition builds upon the minimum degree principle.The deletion of vertices no longer adheres to the minimum degree principle but defines a priority S(v)(α, β, γ) instead, where S(v).α represents the average weight of vertex v, i.e., the sum of edge weights of v divided by its degree.S(v).γ is the number of edges that must be added after deleting vertex v, and S(v).γ is the ID of vertex v.For the vertices in G, priority is sorted according to α; if α values are equal, sorting is based on β.Vertex v is removed after sorting S(v)(α, β, γ), and other operations remain unaltered.Figure 5 shows a tree decomposition generated based on the average weight principle for the road network G in Figure 1.Using Figure 5 as an example, the tree height of T G is h = 6, and the tree width is w = 3, as the tree nodes within T G contain a maximum of three adjacent vertices.For example, v 3 serves as the principal vertex, and v 1 , v 4 , and v 8 constitute adjacent vertices.In the road network, utilizing tree decomposition is reasonable, since the tree width and height are significantly less than the total number of vertices in the road network.
An average-weight-based tree decomposition algorithm is presented as Algorithm 1, where lines 2-9 represent vertex deletion, and lines 10-13 represent the tree decomposition phase.Upon the algorithm's completion, all tree nodes form a connected tree decomposition.The time complexity of Algorithm 1 is O(n(w 2 + log(n))), where n is the number of vertices in G, and w is the tree width of tree decomposition T G .The space complexity is O(nw).The calculated tree decomposition has the following properties [12].
Proposition 1.For a graph G and its corresponding tree decomposition T G , for any two distinct vertices Proposition 2. Considering a graph G and a tree decomposition T G , for any tree node X(v) ∈ Λ and any vertex v ∈ X(v)/v, X(v ) is an ancestor of X(v) in the tree node T G .
Definition 6 (Ancestor).With the tree decomposition TG of G, for any tree node X(v) ∈ Λ, the ancestor of X(v) is expressed as the set X(v).anc, and the ancestor table of the root node is specified in this paper as ∅.Utilize X(v).parent to represent the parent node of X(v).Consequently, the ancestor X(v).anc = X(v).parent.grayId∪ X(v).parent.anc.

Definition 7 (Children).
Given the tree decomposition T G of G, for any tree node X(v), the child of X(v) is symbolized as the set X(v).child.This paper stipulates that the leaf node's child is ∅, employing X(v).childSet to represent the principal vertex set of X(v)'s child node and the child of the non-leaf node X(v).
Upon obtaining a tree decomposition, the shortest network distance between two vertices can be computed in O(w) time using the H2H-Index [13], where w is the tree width.This is currently the most sophisticated technique to calculate the shortest net distance between vertices in road networks.
For any pair of vertices q and v with the nearest common ancestor X, the shortest path network distance between them is shown, which is described in Dian Ouyang et al. [13]: We introduce the proposed kNN index.Given a query point q, we traverse the ancestors and children of each vertex.For any other vertex v, there are three possible scenarios: 1.
If v ∈ X(q).anc, then dist(q, v) has been pre-calculated, and dist(q, v) can be obtained in O(1) time.

3.
If v / ∈ X(q).child and v / ∈ X(q).anc, according to Equation (3) , the shortest path network distance between v and q must pass through a vertex u in their nearest common ancestor.Hence, dist(q, v) = dist(q, u) + dist(u, v).This paper can obtain dist(q, u) and dist(u, v) in O(1) time, allowing the retrieval of dist(q, v) within O(1) time.
In summary, for any other vertex v, this paper can obtain dist(q, v) in O(1) time.
Definition 8 (Node extension list).Given a tree decomposition T G of G, for any tree node X(v) ∈ Λ, the node extension list of X(v) is denoted as the set X(v).extList, where X(v).extList = X(v)/v ∪ X(v).child.
To enhance the algorithm's efficiency, this paper arranges the vertices in X(v)'s node extension list in ascending order based on their road network distance to vertex v.
We were inspired by Sun et al. who put forward the idea of flow graph to serialize the processing graph [23].According to the T G structure on average weight tree decomposition in Figure 5, if the relationship between two vertices belongs to the parent-child relationship, the edge between the two vertices is called a tree edge; otherwise, it is a non-tree edge.The direction of the tree edge is from the parent vertex to the child vertex, and the direction of the non-tree edge is the direction from the deleted vertex to its adjacent vertices; in Figure 6, the solid line indicates the tree edge, and the dashed line indicates the non-tree edge.It can be seen that v 3 is the parent vertices of v 2 , v 7 , v 8 , and v 9 , and the distances from child vertices to v 3 are 6, 5, 5, and 5.The adjacent vertices of v 3 are v 4 , v 1 , v 8 .Definition 9 (Flow Graph).Given a directed label graph F(V F , E F , L F ), where V F represents a set of vertices, E F is a set of edges, and L F represents a label function, assigning one or more labels to nodes in V F .In this paper, L F can be expressed as distance from two vertices, the vertex that contains the moving object M and the number of moving objects.
Relying on average weight tree decomposition, we maintain a node extension list for each tree node, resulting in the kNN flow graph index structure depicted in Figure 6.If there is a parent-child relationship between two vertices, the edge between the two points is called a tree edge, otherwise it is called a non-tree edge.The direction of the tree edge is from the parent-child vertex to the child vertex.The direction of the non-tree edge is from the deleted vertex to its adjacent vertex.The solid line represents the tree edge and the dotted line represents the non-tree edge.The parent and child vertices of vertices v 2 , v 7 , v 8 , and v 9 are v 3 , and their distances to v 3 are 6, 5, 5, 5 respectively.The adjacent vertices of v 3 are v 4 , v 1 , v 8 .The space complexity of the kNN flow graph index is O(n 2 ), where n is the total number of vertices in the road network.Using the flow graph index structure can completely preserve the index structure of the tree decomposition, and it can also save the weight between vertices and the information about the moving objects on the vertices.
Theorem 1 verifies the node completeness between the road network and the flow graph index.
Theorem 1.Given a node v, if there exists a neighbor node v of v, the tree node X(v ) is a passing node on the path from root node r to v in the graph-decomposed tree Λ rooted by node r.
Proof of Theorem 1. Considering a node v and its neighbor nodes N(v), node v can be abstracted as a tree node X(v), satisfying N(v) = X(v)−v.If there exists a tree node X(v ), satisfying that X(v ) is a parent of X(v), then v ∈ X(v)−v.v is connected with all other neighbor nodes X(v)−v−v after v is deleted.It is the same if there exists a tree node X(v ), Similarly, all tree nodes abstracted from neighbor nodes of v can be found in a path from the root node to v.
In addition, a filtering rule can be defined to prune the redundant nodes for kNN searching on the road network, shown as Lemma 1 Lemma 1.Given a query node q and a data node v, if there exists a minimum common ancestor v of q and v, the shortest path dist(q, v) is equal to the sum of shortest paths dist(q, v ) and dist(v , v).
Proof of Lemma 1.If there exists one other node v , satisfying the condition that the shortest path dist(q, v) is equal to the sum of shortest paths dist(q, v ) and dist(v , v), then there must exist one or more across-path edges to connect the node v .However, it is impossible that there exists one across-path edge in a graph-decomposed tree according to Theorem 1 because any node v and its neighbor nodes are only found in the path from root node r to v.
We present the index construction and update strategy.For each tree node in average weight tree decomposition, it is only necessary to compute its node extension list.The construction algorithm for the node extension list is shown as Algorithm 2, where lines 1-3 calculate the shortest network distance from adjacent vertices in X(v) to v, adding it to the node extension list; lines 4-6 compute the child vertices of X(v) and incorporate them into the node extension list; and line 7 sorts the node extension list.The time complexity of Algorithm 2 is O(nw), where n is the total number of vertices in the road network, and w is the tree width of T G .

Algorithm 2: Node Expansion List Construction Algorithm (X(v))
Input: Tree node X(V) Output: Node expansion list of X(v) Regarding index updates, each vertex v has a flag bit, v. isCandidate , indicating its status as a candidate point, which is false when v ceases to be a candidate point.Consequently, index updates have time complexity O(1).

Query-Processing Method Based on kNN Index
We examine the specifics of the query algorithm AWTDN.Definition 10 (Ancestor Relationship).Given any two vertices v 1 and v 2 , within the average weight tree decomposition T G , if v 1 ∈ X(v 2 ).child or v 2 ∈ X(v 1 ).child, then v 1 and v 2 are said to possess an ancestral relationship.
Definition 11 (Current Shortest Path Network Distance).Given vertices v 1 and v 2 with no ancestral relationship, and common ancestor X(v 3 ), the current shortest network distance from vertex v 1 to vertex v 2 via vertex v 3 is represented as curDist To enhance algorithm efficiency, this paper introduces a threshold for pruning, initially set to infinity and updated accordingly when the result is set |R| ≥ k.
To facilitate the explanation of the kNN query problem, for a given query point q, we use a triplet (v 1 , v 2 , s) to suggest that v 1 via v 2 has the shortest network distance to query point q equal to s, with the intermediate point v 2 termed the base point.
The vertex expansion strategy of AWTDN has three steps.
Step 1: Insert the query point into the min-heap, process the first vertex p of the heap, and if p is a candidate point, add it to the result set R.
Step 2: Determine the relationship between p and the base point.( 1) If p is a child of the base point, add the next vertex of p to the min-heap.(2) If p is an ancestor of the base point, add both the next vertex of p and the next vertex of the base point's node extension list to the min-heap.(3) If the distance between vertex v and the query point in the heap is updated, add the next vertex of vertex v to the heap.
Step 3: Process the heap's leading vertex, repeat the first two steps, and when the current road network distance from the heap's leading vertex to the query point is no less than the threshold, the algorithm concludes.
Consider a 3NN (q = v 3 , k = 3) of the query vertex v 3 as an example.In the first step, v 3 is added to the min-heap, the first vertex p of the heap is processed, and the vertex p = v 3 is handled for the first time.As v 3 is not a candidate point, it is not processed.In the second step, with no ancestral or child relationship with the base point, the next vertex v 2 of v 3 's node extension list is added to the min-heap.Correspondingly, in the third step, the heap's first vertex, v 2 , is processed.
As mentioned earlier, this paper uses curDist((q, v)|p) = dist(q, p) + dist(p, v) to denote the current shortest path network distance from vertex q to vertex v when passing through point p.Evidently, curDist((q, v)|p) is the upper bound of dist(q, v).Since dist(q, p) and dist(p, v) are pre-calculated, curDist((q, v)|p) can be retrieved in constant time.
We present a lemma that supports the development of our query algorithm and two theorems that guide it and demonstrate its correctness.Lemma 2. For any given vertices q and v, if v is a kNN of q, there must exist a vertex p ∈ X(q).extList ∪ {q} such that v satisfies the following: (i) v ∈ X(p).child; (ii) dist(q, v) = dist(q, p) + dist(p, v).
As an illustration, consider Figure 6.Assume all vertices are candidate points, and given q = v 3 and v = v 5 .For {v 3 } ∈ X(v 3 ).extList,we have S = {v 3 , v 1 , v 4 , v 8 }.There exists a vertex p = v 8 in S such that the shortest path from v 3 to v 5 passes through vertex v 8 .
Based on Lemma 2, we propose our query algorithm.For a given query point q, we scan each vertex p in {q} ∪ X(q).extList.We first determine whether p is a candidate point.If so, we compare it with the last vertex in result set R, and update R accordingly.We then assess the relationship between p and the base point and process it accordingly.
Theorem 2. For a query vertex q, vertex v, and their common ancestor p, if curDist((q, v)|p) ≥ threshold, then vertex v cannot be a kNN of q.
Proof of Theorem 2. Given a query vertex q, assume that there is a vertex v and their common ancestor p, satisfying curDist((q, v)|p) ≥ threshold, and v is a kNN of q.Let R be the kNN set of q.It is easy to know that when threshold = +∞, there is |R| ≥ k, and for any point v in R, there is dist(q, v ) ≤ threshold, so there is dist(q, v ) ≤ threshold ≤ curDist((q, v)|p), and from the definition of kNN, we can know that v is not the kNN of q, which contradicts the hypothesis.The proof is completed.
Based on Theorem 1 and the ascending order feature of the node expansion list, when curDist((q, v)|p) ≥ threshold, then the vertex v and the vertices after v in the node expansion list must not be kNN of q, so we can exit the calculation early.This example helps illustrate the efficiency of AWTDN in handling kNN queries.The algorithm can use the precomputed shortest distances and a threshold value to prune unnecessary computations, improving overall performance.
By focusing on an average weight tree decomposition instead of on the minimum degree, we can more accurately capture the inherent structure of the road network.It visits fewer vertices for a given query point, which increases computational efficiency, as the number of visited vertices of a query point q is much smaller, as confirmed by our experiments, because average weight tree decomposition better preserves the distance information on the road network.On average, the vertices are similar to those in intermediate weight tree decomposition.

.3. kNN-Query-Processing Method in a Dynamic Environment
We focus on the kNN query problem in a dynamic road network environment, where the candidate points are moving objects.Specifically, given a query point q, we must find the k moving objects that are closest.Since the positions of moving objects change with time, we use the offset method to map them to the nearest road network vertex and then convert the query from a dynamic environment to a static environment.
Considering the directionality of moving objects, we model the road network as a directed weighted graph G(V, E).

Definition 12 (Moving Object
).Each moving object on the road network is represented by m = < (v i , v j ), offset, t >; that is, at time t, moving object m is on edge (v i , v j ), at an offset from vertex v j .
For instance, referring to Figure 7, if the current time is t, moving object m 13 can be represented as m 13 = < (v 3 ,v 2 ),2,t>, meaning m 13 is on the edge between v 3 and v 2 , the distance between v 3 and v 2 is 5 and the offset from vertex v 2 is 2. The algorithm maps each query point to the starting vertex with the offset.For example, if q 1 is located on edge (v 2 , v 1 ), it is mapped to starting point v 2 with an offset of 1.Therefore, the distance between a moving object m The location information of each moving object m is updated regularly.We use a moving object table to store this location information at a given moment.Figure 8 shows the location information of the moving objects on a road network at times t and t + 1, where v start and v end are the respective start and end vertices of edge (v start , v end ); M is the set of moving objects on this edge; offset contains the offsets of the moving objects to the end vertex v end , corresponding one-to-one with the moving objects in M; and M N is the number of moving objects in M.  Taking Figure 8 as an example, given query point q 1 and assuming that all moving objects are candidate objects, when we initiate a kNN query at time t, we first map the query point q 1 to the starting vertex with an offset; i.e., q 1 (v 2 , v 1 ), 1, t .Subsequently, all moving objects are offset to the vertices in their end direction, which become the candidate vertices.For example, moving object m 13 can be represented as m 13 (v 3 , v 2 ), 2, t ; i.e., m 13 is on the edge (v 3 , v 2 ), with an offset of 2 from the vertex v 2 .Similarly, each moving object is mapped to a vertex on the road network with an offset, and the final result is as shown in the Moving Object List at time t.In this way, we can use the AWTDN algorithm for kNN queries.For the kNN set, R = {v 1 , v 2 , • • • , v K } returned by AWTDN is not the true result.We must continue restoring the vertices in R to moving objects on the road network.Taking v 1 as an example, M N = 1; i.e., there is only one moving object on v 1 , i.e., m 13 .The final distance from m 13 to the query point q 1 is dist(m 13 , q 1 ) = dist(v 2 , v 1 ) + q 1 .offset+ m 13 .offset= 0 + 1 + 2 = 3.The actual kNN result set is obtained after restoring all vertices to moving objects in turn.It is worth noting that some vertices have more than one moving object, such as vertex v 2 , which has moving objects m 11 and m 13 .Therefore, it is necessary to further screen the moving objects to obtain the final k results.
At time t + 1, as shown, due to the changes in positions of moving objects, the vertices to which moving objects are offset may also change.For example, due to the change in the position of m 13 , its offset vertex changes from v 2 at time t to v 1 at time t + 1.At this point, we need to set v 2.isCandidate to false andv 1.isCandidate to true.We take Figure 9 as an example to explain the kNN query in a dynamic environment.
Moving Object List The starting vertex of query point q in Figure 9 is v 3 .At time t, there are five moving objects, m 1 , m 2 , m 3 , m 4 , m 5 .m 1 is on the edge (v 3 , v 6 ), and the distance between v 3 and v 6 is 2. We map each to a terminating vertex with the offset.Table 3 shows the moving object list at time t after mapping.O f f set = 1 means the distance from m 1 to v 6 is 1, M N = 1 means the number of the moving object on the edge (v 3 , v 6 ) is 1.Then, for the vertices after mapping, we use AWTDN to obtain the result set R and restore its vertices to real moving objects according to the moving object list, so as to obtain the final kNN result.The solution process is shown in Table 4.In the dynamic query, we must modify the kNN result set obtained by AWTDN.Suppose that the 4NN of query point q is 4NN = {v 6 , v 7 , v 10 , v 4 }.If a vertex v 8 satisfies dist(v 8 ,q) = dist(v 4 ,q), then we continue to save v 8 ; i.e., the 4NN of q is 4NN = {v 6 , v 7 , v 10 , v 4 , v 8 }.This ensures that the real moving objects are not missed.
A moving object table stores the moving objects' location information at specific time points, including information such as the starting and ending vertices of the edge on which the object is located, the set of moving objects on that edge, the offset of each object from the ending vertex, and the number of moving objects on the edge.This allows the transformation of the problem from dynamic to static, allowing the use of conventional static kNN algorithms.

Experimental Parameters
We implemented the AWTDN algorithm in the Java language and compared it with TEN-Query [2] and G*Tree [7].The experimental environment comprised an AMD Ryzen 9 5900X 12-Core CPU at 3.69 GHz, 64 GB of memory, a 4 TB hard drive, and Windows 10.
Dataset: The dataset came from real-world road networks provided by Urban Road Network [24].Six sets were selected for experiments, as shown in Table 5, where h and w are the respective height and width of average weight tree decomposition.Parameter Configuration: For each dataset, we randomly generated candidate objects and controlled their numbers via object density θ, defined as the ratio of the numbers of candidate objects and road network vertices.The configurations of θ-and k-values can be found in Table 6, with default values written in boldface.

Impact of Dataset Size on Algorithm Query Time
We compared the query times of AWTDN, G*Query, and TEN-Query for different dataset sizes, where the object density θ and k take default values.We randomly generated 1000 vertices as query points, using the mean of all query times as the ultimate query time.The results are shown in Figure 10.It is evident that both AWTDN and TEN-Query are significantly more efficient than G*Query, and AWTDN is the fastest.This is attributed to the avoidance of ineffective computations by applying thresholds.We compared the performance of the algorithms under varying k-values.

Impact of Changing k-Values on Algorithm Query Time
We compared the query efficiencies of the algorithms across six datasets by altering k-values, as shown in Figure 11.
The query performance varying different k-values is evaluated in Figure 11.A more stationary linearity of our algorithm is measured than G*Query and TEN-Query algorithms as the incremental changes of k-values.The flow graph index abstracts all nodes of the graph as the tree nodes, and the size of the tree nodes depends on the quantity of neighbors.Therefore, this tree is not related to the selection of k-value, which transcend the k-value limitation by storing all potential nodes.

Impact of Changing Object Density θ on Algorithm Query Time
We compared the query efficiencies of the three algorithms across six datasets by adjusting θ values, with results as shown in Figure 12.
It is apparent that, irrespective of changes in the θ value, the performance of AWTDN across all six datasets is markedly superior to that of TEN-Query and G*Query, thereby confirming the universal applicability of AWTDN.

Comparison of Accessed Vertex Numbers across Different Datasets
We compared the number of vertices accessed by AWTDN, TEN-Query, and G*Query across six datasets.For each dataset, we generated 1000 random query points and took the average total number of accessed vertices as the final count.Both k and θ took default values.The comparison results are shown in Figure 13.The results reveal that AWTDN accesses significantly fewer vertices than TEN-Query and G*Query, which is attributable to the efficient pruning capacity of the threshold.

Comparison of Index Construction Time and Space across Different Datasets
We compared the index construction time and space of AWTDAC, TEN-Index, and G*Query across datasets of varying sizes, where the object density θ takes the default value of 0.3.Since the construction of TEN-Index depends on k, to accommodate queries of all k-values, we set k to 100.It is worth mentioning that AWTDAC does not rely on k and thus can satisfy kNN queries of any k-value.We set the parameters of G*Tree according to the original text.The comparison results are depicted in Figures 14 and 15   AWTDAC incurs higher construction time and space costs than TEN-Index, which only stores the kNN results within the contracted neighbor range, which explains why TEN-Index depends on the k-value.In contrast, AWTDAC stores all vertices within the subtree scope, thus breaking the k-value limitation and enabling kNN queries of any k-value.Although G*Tree has the smallest space cost, it has the largest time cost.G*Tree employs the Dijkstra algorithm to calculate the shortest path network distance, while AWTDAC and TEN-Index use H2H-Query to measure the road network distance, which is significantly more efficient than Dijkstra.

Conclusions
kNN queries for road networks are studied in this paper.Firstly, a flow graph index is proposed to store the intermediated results, which is generated from a graph-decomposed tree.Rules obtained from the flow graph index are found to reduce the quantity of candidate nodes.Secondly, the kNN query algorithm is used to conduct the final results on this flow graph index.Finally, the effectiveness and efficiency of our proposed algorithm are confirmed through experiments.

4 Figure 1 .
Figure 1.The example of a road network G.

1 Figure 2 .
Figure 2. Example of kNN query of road network.

Figure 4 .
Figure 4. Tree decomposition T G based on minimum degree.

Figure 5 .
Figure 5. Tree decomposition T G based on average weight.

Algorithm 1 : 4 v 8
Average Weight Tree Decomposition Construction Algorithm (G(V, E)).Input: Road network G(V, E) Output: Tree decomposition T G 1 T G ← ∅; 2 for i = 1 to |V| do 3 Sort the vertices in G according to S(v)(α, β, γ) ; ← Selected vertices after sorting ; 5 Create tree node X(v) ← {v} ∪ {neighbor vertices of v}; 6 Adding edges to G makes all neighbors of v connected ; 7 Delete v and its neighbors from G ; Update the α and β values of v's neighbors ; 9 v.deleteOrder ← i ; 10 end 11 for v ∈ V do 12 if |X(v)| > 1 then 13 v ← the vertex with the smallest elimination sequence in X(v) − {v}; 14 Set X(v ) as the parent node of X(v) in T G ;

Figure 6 .
Figure 6.Example of kNN Flow Graph Index.

Figure 7 .
Figure 7. Example of kNN Flow Graph Index.

Figure 8 .
Figure 8. Example of moving object list.

Figure 10 .
Figure 10.Tree decomposition T G based on average weight.

Figure 11 .
Figure 11.Impact of Changing k-values on Algorithm Query Time.

Figure 12 .
Figure 12.Impact of Changing Object Density θ on Algorithm Query Time.

Figure 13 .
Figure 13.Comparison of the number of visited vertices. .

Figure 14 .
Figure 14.Comparison of index construction time.

Figure 15 .
Figure 15.Comparison of index construction space.

Table 3 .
List of moving objects at time t.

Table 4 .
kNN solution process of q.

Table 5 .
Statistics of road network data.