Batch query method for shortest paths in road network
By adopting query decomposition, path expansion, retention and replacement strategies in the road network, combined with query matching strategies, the problem of low efficiency of existing shortest path query is solved, which improves computing efficiency and reduces storage costs.
Patent Information
- Application Number
- CN202411145116.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-20
- Publication Date
- 2024-12-17
- Estimated Expiration
- 2044-08-20
AI Technical Summary
The existing shortest path query method has shortcomings in query efficiency and computing efficiency, which cannot meet the actual needs, and requires complex decomposition processes and large-scale cache storage, resulting in low computing efficiency and high storage cost.
A shortest path batch query method in the road network is proposed. The query is decomposed into a subset with high similarity through the query decomposition strategy, and the path extension, path retention and path replacement strategies are adopted, combined with the query matching strategy, and the existing result sets are quickly used. Get the shortest path.
This greatly improves query efficiency and computing efficiency, reduces storage cost, and optimizes the query process through similarity calculation and decomposition strategies, and realizes efficient processing of multiple queries.
Smart Images

Figure CN119149593A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of information processing technology, and in particular to a method for batch querying the shortest paths in a road network. Background Art
[0002] The classic Dijkstra algorithm is usually used to query the shortest path distance of a road network. It uses the intersections of the urban road network as points in the graph, and the road length or travel time as the weight of the edge in the graph. It obtains the shortest path distance between any two points in the graph through a breadth-first search strategy.
[0003] However, since the algorithm needs to traverse all points and edges in the graph when querying the shortest path distance, the query efficiency is very low and cannot meet actual usage needs. In addition, the existing shortest path query method requires a complex decomposition process for the query and also requires the construction of a large number of caches to match the answers, which greatly reduces the computational efficiency of the query process and increases the storage cost. Summary of the invention
[0004] The present invention provides a method for batch querying the shortest paths in a road network to overcome the above technical problems.
[0005] In order to achieve the above object, the technical solution of the present invention is:
[0006] A method for batch querying the shortest paths in a road network comprises the following steps:
[0007] S1: Obtain a query request about a source vertex and a target vertex in a road network, and perform similarity matching between the query and any result query in a given query result set;
[0008] Determine whether the similarity between this query and the result query meets a preset similarity threshold;
[0009] If the query is satisfied, then based on the constructed query matching strategy, the shortest path for this query is obtained according to the shortest path corresponding to the result query in the query result set;
[0010] Otherwise, execute step S2;
[0011] S2: put the query into the cache set which is initially empty, and use it as the query set until the cache set reaches the maximum capacity or the maximum storage time;
[0012] S3: based on the query decomposition strategy, decomposing the query set into a number of query subsets;
[0013] S4: obtaining the main query and the secondary query of each query subset in sequence;
[0014] The main query is a query with the longest Euclidean distance between the source vertex and the target vertex selected from all queries in the query subset;
[0015] The secondary query is the other query in the query subset except the main query;
[0016] S5: Add the source vertex of the main query as the path starting point to the defined heap set, obtain a new path based on the constructed path extension strategy, and add the new path to the heap set in increasing order of the estimated shortest path distance to obtain the main query extension heap;
[0017] S6: storing the source vertex of the secondary query as the path starting point in the defined retention heap, and obtaining the secondary query retention heap based on the constructed path retention strategy;
[0018] S7: Based on the constructed path replacement strategy, the shortest path of all queries in the query set is obtained according to the main query expansion heap and the secondary query retention heap.
[0019] Furthermore, the S3 specifically includes the following steps:
[0020] S31: Calculate the query similarity for any two queries in the query set Q, and the calculation formula for the query similarity is:
[0021] S(q i ,q j )=w1DS(q i ,q j )+w2AS(q i ,q j )
[0022]
[0023] AS(q i ,q j )=cosθ
[0024] Where: S(q i ,q j ) represents the query similarity between any two queries, and 0≤S(q i ,q j )≤1;DS(q i ,q j ) represents the distance similarity of two queries; AS(q i ,q j ) represents the angular similarity of the two queries; cosθ represents the cosine value of the smaller angle between the starting point and the end point of the two queries; d max Represents the distance similarity threshold between two points; q i ,q j represents any two queries in the query set Q, and qi =(s i ,t i ), q j =(s j ,t j );s i ,t i Respectively represent the query q i The source and target vertices of s j ,t j Respectively represent the query q j The source vertex and target vertex of the grid; w1, w2 represent the weight coefficients used to adjust the importance of the starting point, end point and angle in the similarity calculation;
[0025] S32: construct a similarity scoring function to group all queries in the query set Q into similar queries and obtain several query subsets;
[0026] And the expression of the similarity scoring function is
[0027]
[0028] Where: f(Q) represents the similarity scoring function; S(Q i ) represents the value used to measure the query subset Q i An indicator of the similarity between inner queries; Indicates that in the query subset Q i The number of combinations of any two queries in the query set Q; n represents the number of queries in the query set Q; q m ,q n Represents the query subset Q i Any two queries in .
[0029] Furthermore, the S5 specifically includes the following steps:
[0030] S51: adding the source vertex of the main query as the path starting point to the defined heap set, confirming and selecting the first heap path in the heap set with the source vertex as the starting point as the processing path path;
[0031] S52: determining whether the end point of the processing path path reaches the target vertex of the main query; if the end point of the processing path path does not reach the target vertex of the main query, performing path extension on the processing path path based on the constructed path extension strategy to obtain multiple new paths;
[0032] The path extension strategy is:
[0033] S521: confirm whether the end point v of the processing path path is an extended node in the road network;
[0034] S522: If it is confirmed that the end point v of the processing path path is an unexpanded node, the end point v is used as a source vertex, and all neighboring nodes adjacent to the end point v and not belonging to the processing path path are used as target vertices to obtain multiple new extended paths, and then execute step S53;
[0035] If it is confirmed that the end point v of the processing path path is an expanded node, the processing path path is discarded and not added to the expansion heap;
[0036] The expanded nodes are all neighbor nodes in the acquired road network that are adjacent to the end point v of the processing path path and do not belong to the processing path path, and are used as the next node of the end point v of the processing path path to form an extended path, and the neighbor nodes that are adjacent to the end point v of the processing path path and do not belong to the processing path path are marked as expanded nodes;
[0037] S53: adding each extended new path to the heap set in increasing order of the estimated shortest path distance, so as to update the extended heap to obtain the current main query extended heap;
[0038] S54: Obtain a new processing path path starting from the source vertex in the current main query expansion heap according to the greedy algorithm; if the end point of the new processing path path is not the target vertex, repeat steps S52 to S53 until the end point of the new processing path path is the target vertex, so as to obtain a complete path from the source vertex to the target vertex to obtain the final main query expansion heap.
[0039] Furthermore, the calculation formula for the estimated shortest path distance is:
[0040] preDist(path(v i ,v))=Dist(path(v i ,v))+LDist(v,v j )
[0041] Where: preDist(path(v i ,v)) represents the estimated shortest path distance of the new path to the target vertex; v i Indicates the source vertex of the processing path path; v j Represents the target vertex of the main query; path(v i ,v) represents the processing path and path(v i ,v): <v1=(v i ),v2,…,v n =(v)>;Dist(path(v i ,v)) means v i The path distance between v and LDist(v,vj ) represents the current path endpoint v and the target vertex v j The straight-line distance between .
[0042] Further, the path retention strategy constructed in S6 includes a neighbor node retention strategy, an extended node retention strategy, and a deleted path retention strategy in sequence;
[0043] The neighbor node retention strategy: When the main query path is expanded to the neighbor node s i When the neighbor node s i The path distances between all nodes of the currently processed path are stored in the reserved heap;
[0044] The extended node retention strategy: When the main query path is expanded, the neighbor node s i When expanding, the neighbor node s i To neighbor node s i The path distances of the neighbor nodes are stored in the reserved heap, and the paths with repeated path endpoints v are deleted and the paths with small path distances among the repeated paths are retained;
[0045] The deletion path retention strategy: when there is a deletion path path′(s i ,v);
[0046] Then confirm to delete the path path′(s i ,v) and processing path path(s i ,v) path distance size;
[0047] If you delete the path path′(s i ,v) than the processing path path(s i ,v) is small, then the path path′(s i ,v) is stored in the reserved heap, otherwise, the path path(s) is processed i ,v) Store in the retention heap to obtain the secondary query retention heap;
[0048] The deletion path path′(s i ,v) is the processing path path(s) in the main query expansion heap i ,v) Paths with the same first and last nodes.
[0049] Furthermore, the path replacement strategy constructed in S7 is specifically:
[0050] When the main query is expanded to the target vertex of the secondary query, a replacement path is obtained based on all paths in the main query expansion heap based on the path replacement strategy;
[0051] The method for obtaining the replacement path is:
[0052] Given any path in the main query expansion heap, path= main ,…,v j ,…,v i > and the sub-query retains the path path′ in the heap = i ,…,v j >
[0053] Then main ,…,v j ,…,v i >Subpath main ,…,v j >Replace with i ,…,v j >, get the source vertex s in the secondary query retention heap i To all path endpoints v in the main query expansion heap i Path i ,…,v i >, recorded as the secondary query to retain the path path′(s i ,v i )'s replacement path.
[0054] Furthermore, the query matching strategy constructed in S1 is specifically:
[0055] S11: Define a matching heap H match And it is initially an empty set;
[0056] Given a query q = (s, t), and based on the inverted list preset in the query result set Rset, confirm whether there is a path number in the inverted list corresponding to the same source vertex s and target vertex t;
[0057] If there is an identical path number p, then path number p is used as the matching path for query q;
[0058] If there is no identical path number p, obtain the point set of neighbor nodes adjacent to the source vertex s and the target vertex t, and record the point set of neighbor nodes of the source vertex s as the source set S;
[0059] Record the point set of the neighbor nodes of the target vertex t as the destination set T, and obtain multiple identical path numbers in the inverted lists of the source set S and the destination set T;
[0060] According to the path number, obtain the path p′(s′, t′) corresponding to a pair of neighbor nodes (s′, t′) closest to the source vertex s and the target vertex t as the matching path of the query q, and s′∈S, t′∈T;
[0061] And put the matching path of the query q into the matching pile H match middle;
[0062] S12: Obtain the initial processing path path of query q according to query q = (s, t) and the corresponding matching path<s,…,t> ; Where, ... represents the path to be filled;
[0063] Based on the forward expansion strategy and the reverse expansion strategy, the initial processing path path<s,…,t> Perform path filling to obtain forward / reverse extension paths;
[0064] The forward expansion strategy: Get the initial processing path path<s,…,t> The last node before the to-be-filled part is taken as the forward expansion node v;
[0065] Get the node that is adjacent to the forward expansion node v and does not belong to the initial processing path path<s,…,t> All nodes v in neighbor , and take the forward expansion node v as the source vertex, and take the node v neighbor as the target vertex to obtain multiple forward expansion paths;
[0066] The reverse expansion strategy: Get the initial processing path path<s,…,t> The first node after the part to be filled is taken as the reverse expansion node v′;
[0067] Get the node that is adjacent to the reverse expansion node v′ and does not belong to the path<s,…,t> All nodes v in neighbor ′, and take the reverse expansion node v′ as the source vertex, and take the node v neighbor ′ as the target vertex to obtain multiple reverse extension paths;
[0068] S13: Obtaining a plurality of final processing paths according to the random combination of the forward extension path and the reverse extension path;
[0069] Based on the matching estimated shortest path distance calculation formula, the matching estimated shortest path distance mpreDist of each final processing path path is obtained, and each final processing path path is added to the matching pile H in the increasing order of the matching estimated shortest path distance mpreDist match To update the matching heap H match ;
[0070] And according to the updated matching heap H match Get the shortest path corresponding to query q.
[0071] Furthermore, the matching estimated shortest path distance calculation formula in S13 is:
[0072]
[0073] Where: mpreDist(path(v i ,v)) represents the path path(v i ,v) reaches the target vertex v j The matching estimated shortest path distance; Dist(v i ,v) represents the source vertex v i The path distance from the current path end point v; Dist(v n ,v j ) represents node v n With the target vertex v j The path distance between them; LDist(v,v n ) is the current path endpoint v and node v n The straight-line distance between .
[0074] Beneficial effect: The present invention provides a method for batch querying the shortest paths in a road network. First, a query decomposition strategy is proposed. On this basis, a group of query subsets with high similarity are constructed, and a main query is selected from them. Then, a path expansion strategy, a path retention strategy and a path replacement strategy are proposed. In the process of expanding the main query, some information useful to the secondary query is stored in the secondary query retention heap and the path is replaced, so that the shortest path of the secondary query is obtained in the process of processing the shortest path of the main query, which greatly improves the query efficiency. Finally, through the constructed query matching strategy, the existing result set is used to quickly obtain the shortest path result of a query, which maximizes the calculation efficiency and reduces the storage cost. BRIEF DESCRIPTION OF THE DRAWINGS
[0075] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0076] Figure 1 A flow chart of a method for batch querying the shortest paths in a road network according to the present invention;
[0077] Figure 2 This is a core flow chart of the shortest path batch query method in the road network in this embodiment;
[0078] Figure 3 Schematic diagram of the data set used in batch shortest path query in this embodiment;
[0079] Figure 4 This is a schematic diagram of query similarity matching in this embodiment;
[0080] Figure 5 Schematic diagram of query subset in this embodiment;
[0081] Figure 6 This is a schematic diagram of querying the estimated shortest path distance in this embodiment;
[0082] Figure 7 is a flowchart of batch shortest path query in this embodiment;
[0083] Figure 8 is a decision block diagram of the secondary query end condition in this embodiment;
[0084] Fig. 9 : is a path table diagram of the query result set Rset in this embodiment;
[0085] Fig.10 is a reverse list diagram of the query result set Rset in this embodiment;
[0086] Fig.11 Schematic diagram of a path subgraph constructed according to the query result set Rset in this embodiment;
[0087] Fig.12 This is a schematic diagram of the query matching strategy constructed in this embodiment. DETAILED DESCRIPTION
[0088] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0089] This embodiment provides a method for batch querying the shortest paths in a road network. Figure 1 to Figure 2 As shown, the following steps are included:
[0090] S1: Obtain a query request about a source vertex and a target vertex in the road network, and perform similarity matching between this query and any result query in a given query result set Rset;
[0091] Determine whether the similarity between this query and the result query meets a preset similarity threshold;
[0092] If it is satisfied, based on the constructed query matching strategy, the shortest path ShortPath(q α )Get the shortest path ShortPath(qi );
[0093] Otherwise, execute step S2;
[0094] S2: put the query into the cache set which is initially empty, and use it as the query set until the cache set reaches the maximum capacity or the maximum storage time;
[0095] S3: Based on the query decomposition strategy, the query set Q is decomposed into several query subsets Q = {Q1, Q2, ..., Q i ,…}; In this embodiment, some similar queries can be assigned to the same subset through the query decomposition strategy, and then the queries in a subset can be solved at the same time, reducing the query time and improving the computing efficiency. Specifically, the following steps are included:
[0096] S31: Given two queries q i =(s i ,t i ) and q j =(s j ,t j ),d max is the distance similarity threshold between two points. If it exceeds the threshold, the two queries are considered dissimilar. The formula for calculating the query similarity of any two queries in the query set Q is:
[0097] S(q i ,q j )=w1DS(q i ,q j )+w2AS(q i ,q j )
[0098]
[0099] AS(q i ,q j )=cosθ
[0100] Where: S(q i ,q j ) represents the query similarity between any two queries, and 0≤S(q i ,q j )≤1;DS(q i ,q j ) represents the distance similarity of two queries; AS(q i ,q j ) represents the angular similarity of the two queries; cosθ represents the cosine value of the smaller angle between the starting point and the end point of the two queries; d max Represents the distance similarity threshold between two points; q i ,qj represents any two queries in the query set Q, and q i =(s i ,t i ), q j =(s j ,t j );s i ,t i Respectively represent the query q i The source and target vertices of s j ,t j Respectively represent the query q j The source vertex and the target vertex of the query; w1, w2 represent the weight coefficients used to adjust the importance of the starting point, the end point and the angle in the similarity calculation. These coefficients are determined according to the actual situation and needs and their sum is 1; if the similarity S(q i ,q j ) is greater than 0, then the two queries are called similar queries, and the closer the value is to 1, the higher the similarity between the two queries;
[0101] S32: construct a similarity scoring function based on the idea of the greedy algorithm to group all queries in the query set Q into similar queries and obtain several query subsets;
[0102] And the expression of the similarity scoring function is
[0103]
[0104] Where: f(Q) represents the similarity scoring function; S(Q i ) represents the value used to measure the query subset Q i An indicator of the similarity between inner queries; Indicates that in the query subset Q i The number of combinations of any two queries in the query set Q; n represents the number of queries in the query set Q; q m ,q n Represents the query subset Q i Any two queries in ;
[0105] In this embodiment, all similar queries in the query set Q are arranged in descending order according to similarity, and these queries are tried to be grouped. A scoring function f(Q) is set to determine whether the queries in each subset have the greatest similarity, and the larger the value of the scoring function f(Q), the better the grouping effect.
[0106] S4: batch processing the query subsets obtained by query decomposition one by one until the shortest path of all queries in the query set is found, that is, the main query and the secondary query of each query subset are obtained in turn;
[0107] The main query is a query with the longest Euclidean distance between the source vertex and the target vertex selected from all queries in the query subset;
[0108] The secondary query is the other query in the query subset except the main query;
[0109] Specifically, in the query subset Q i Among all the queries, select the query with the longest Euclidean distance between the source vertex and the target vertex as the main query, denoted by q main = main ,t main >, where s main represents the source vertex of the main query, t main represents the target vertex of the main query; in the process of finding the shortest path of the main query, it is possible to traverse as many nodes as possible that can be reached by the shortest path of all queries in the query subset, and the query subset Q i The other queries besides the main path query are called secondary queries;
[0110] S5: Add the source vertex of the main query as the path starting point to the defined heap set, obtain a new path based on the constructed path extension strategy, and add the new path to the heap set in increasing order of the estimated shortest path distance to obtain the main query extension heap, specifically including the following steps:
[0111] S51: adding the source vertex of the main query as the path starting point to the defined heap set, confirming and selecting the first heap path in the heap set with the source vertex as the starting point as the processing path path;
[0112] The heap head path is the path starting from the source vertex in the defined heap set;
[0113] S52: determining whether the end point of the processing path path reaches the target vertex of the main query; if the end point of the processing path path does not reach the target vertex of the main query, performing path extension on the processing path path based on the constructed path extension strategy to obtain multiple new paths;
[0114] The path extension strategy is:
[0115] S521: confirm whether the end point v of the processing path path is an extended node in the road network;
[0116] S522: If it is confirmed that the end point v of the processing path path is an unexpanded node, the end point v is used as a source vertex, and all neighboring nodes adjacent to the end point v and not belonging to the processing path path are used as target vertices to obtain multiple new extended paths, and then execute step S53;
[0117] If it is confirmed that the end point v of the processing path path is an expanded node, the processing path path is discarded and not added to the expansion heap;
[0118] The expanded nodes are all neighbor nodes in the acquired road network that are adjacent to the end point v of the processing path path and do not belong to the processing path path, and are used as the next node of the end point v of the processing path path to form an extended path, and the neighbor nodes that are adjacent to the end point v of the processing path path and do not belong to the processing path path are marked as expanded nodes;
[0119] S53: adding each extended new path to the heap set in increasing order of the estimated shortest path distance, so as to update the extended heap to obtain the current main query extended heap;
[0120] Preferably, the calculation formula for the estimated shortest path distance is:
[0121] preDist(path(v i ,v))=Dist(path(v i ,v))+LDist(v,v j )
[0122] Where: preDist(path(v i ,v)) represents the estimated shortest path distance of the new path to the target vertex; v i Indicates the source vertex of the processing path path; v j Represents the target vertex of the main query; path(v i ,v) represents the processing path and path(v i ,v): <v1=(v i ),v2,…,v n =(v)>;Dist(path(v i ,v)) means v i The path distance between v and LDist(v,v j ) represents the current path endpoint v and the target vertex v j The straight-line distance between
[0123] S54: Obtain a new processing path path starting from the source vertex in the current main query expansion heap according to the greedy algorithm; if the end point of the new processing path path is not the target vertex, repeat steps S52 to S53 until the end point of the new processing path path is the target vertex, so as to obtain a complete path from the source vertex to the target vertex to obtain the final main query expansion heap;
[0124] S6: In the process of batch processing the shortest path query, not only the shortest path query should be performed on the main query, but also the secondary query should be processed accordingly, and the shortest path query result can be quickly obtained by constructing the secondary query retention heap. First, initialize the secondary query retention heap, store the source vertex of the secondary query as the path in the secondary query retention heap, and update the secondary query retention heap according to the retention strategy; store the source vertex of the secondary query as the path in the defined retention heap, and obtain the secondary query retention heap based on the constructed path retention strategy;
[0125] In a specific embodiment, the constructed path retention strategy includes a neighbor node retention strategy, an extended node retention strategy, and a deleted path retention strategy in sequence;
[0126] The neighbor node retention strategy: When the main query path is expanded to the neighbor node s i When the neighbor node s i The path distances to all nodes and nodes of the currently processed path are stored in the reserved heap;
[0127] The extended node retention strategy: When the main query path is expanded, the neighbor node s i When expanding, the neighbor node s i To neighbor node s i The path distances of the neighbor nodes are stored in the reserved heap, and the paths with repeated path endpoints v are deleted and the paths with small path distances among the repeated paths are retained;
[0128] The deletion path retention strategy: when there is a deletion path path′(s i ,v) time;
[0129] Then confirm to delete the path path′(s i ,v) and processing path path(s i ,v) path distance size;
[0130] If you delete the path path′(s i ,v) than the processing path path(s i ,v) is small, then the path path′(s i ,v) is stored in the reserved heap, otherwise, the path path(s) is processed i ,v) Store in the retention heap to obtain the secondary query retention heap;
[0131] The deletion path path′(s i ,v) is the processing path path(s) in the main query expansion heap i ,v) Paths with the same first and last nodes;
[0132] S7: Based on the constructed path replacement strategy, the shortest path of all queries in the query set is obtained according to the main query expansion heap and the secondary query retention heap;
[0133] The path replacement strategy constructed is specifically:
[0134] When the main query is expanded to the target vertex of the secondary query, a replacement path is obtained based on all paths in the main query expansion heap based on the path replacement strategy;
[0135] The method for obtaining the replacement path is:
[0136] Given any path in the main query expansion heap, path= main ,…,v j ,…,v i > and the sub-query retains the path path′ in the heap = i ,…,v j >
[0137] Then main ,…,v j ,…,v i >Subpath main ,…,v j >Replace with i ,…,v j >, get the source vertex s in the secondary query retention heap i To all path endpoints v in the main query expansion heap i Path i ,…,v i >, recorded as the secondary query to retain the path path′(s i ,v i )'s replacement path;
[0138] In addition, when the neighbor node of a node extended by the main query is the target node of the secondary query, a path replacement strategy is performed on all paths in the main query extension heap and the replacement paths are stored in the secondary query retention heap. After all paths in the secondary query retention heap are sorted in ascending order according to the estimated shortest distance, if the end point of the first path in the heap is the target node of the secondary query, the secondary query ends and the path is the shortest path of the query.
[0139] If the source vertex s i As a neighbor node in the main query expansion process, at the end of the main query, the source vertex s i The unexpanded ones are still in the reserved heap. The secondary query reserved heap is expanded according to the expansion method of the primary query path to obtain the shortest path. i As an extension node in the main query expansion process, the source vertex s i It has been expanded and according to Theorem 4, during the expansion process, the source vertex s i If the shortest path to the node is not stored in the secondary query reserved heap, it can be obtained by performing a path replacement strategy on the main query's extended heap; and the path replacement strategy is specifically: using the path stored in the extended heap and the path stored in the reserved heap, perform prefix replacement on the path to obtain the shortest path with the secondary query source point as the source point; specifically, the path in the main query extended heap is replaced from the tail node v i Start traversing in reverse order and traverse to the first node v j To keep the tail node v of the path in the heap j , for the main query subpath main ,…,v j > Make the replacement.
[0140] In a specific embodiment, the query matching strategy constructed in S1 is specifically:
[0141] S11: Define a matching heap H match And it is initially an empty set;
[0142] Given a query q = (s, t), and based on the inverted list preset in the query result set Rset, confirm whether there is a path number in the inverted list corresponding to the same source vertex s and target vertex t;
[0143] If there is an identical path number p, then path number p is used as the matching path for query q;
[0144] If there is no identical path number p, obtain the point set of neighbor nodes adjacent to the source vertex s and the target vertex t, and record the point set of neighbor nodes of the source vertex s as the source set S;
[0145] Record the point set of the neighbor nodes of the target vertex t as the destination set T, and obtain multiple identical path numbers in the inverted lists of the source set S and the destination set T;
[0146] According to the path number, obtain the path p′(s′, t′) corresponding to a pair of neighbor nodes (s′, t′) closest to the source vertex s and the target vertex t as the matching path of the query q, and s′∈S, t′∈T;
[0147] And put the matching path of the query q into the matching pile H match middle;
[0148] S12: Obtain the initial processing path path of query q according to query q = (s, t) and the corresponding matching path<s,…,t> ; Where, ... represents the path to be filled;
[0149] Based on the forward expansion strategy and the reverse expansion strategy, the initial processing path path<s,…,t> Perform path filling to obtain forward / reverse extension paths;
[0150] The forward expansion strategy: Get the initial processing path path<s,…,t> The last node before the to-be-filled part is taken as the forward expansion node v;
[0151] Get the node that is adjacent to the forward expansion node v and does not belong to the initial processing path path<s,…,t> All nodes v in neighbor , and take the forward expansion node v as the source vertex, and take the node v neighbor as the target vertex to obtain multiple forward expansion paths;
[0152] The reverse expansion strategy: Get the initial processing path path<s,…,t> The first node after the part to be filled is taken as the reverse expansion node v′;
[0153] Get the node that is adjacent to the reverse expansion node v′ and does not belong to the path<s,…,t> All nodes v in neighbor ′, and take the reverse expansion node v′ as the source vertex, and take the node v neighbor ′ as the target vertex to obtain multiple reverse extension paths;
[0154] S13: Obtaining a plurality of final processing paths according to the random combination of the forward extension path and the reverse extension path;
[0155] Based on the matching estimated shortest path distance calculation formula, the matching estimated shortest path distance mpreDist of each final processing path path is obtained, and each final processing path path is added to the matching pile H in the increasing order of the matching estimated shortest path distance mpreDist match To update the matching heap H match ;
[0156] And according to the updated matching heap H match Get the shortest path corresponding to query q;
[0157] Specifically, the matching estimated shortest path distance calculation formula is:
[0158]
[0159] Where: mpreDist(path(v i ,v)) represents the path path(v i ,v) reaches the target vertex v j The matching estimated shortest path distance; Dist(v i ,v) represents the source vertex vi The path distance from the current path end point v; Dist(v n ,v j ) represents node v n With the target vertex v j The path distance between them; LDist(v,v n ) is the current path endpoint v and node v n The straight-line distance between .
[0160] In this embodiment, Figure 3 The figure shows a schematic diagram of the data set used in the present invention when calculating the batch shortest path query. The traditional A* algorithm is used to find the path from v7 to v 27 , v8 to v 28 and v 17 to v 27 The shortest path of the three queries. We can get path(v7,v 27 )= <v7,v6,v5,v9,v 11 ,v 10 ,v 14 ,v 22 ,v 25 ,v 27 >、path(v8,v 28 )= <v8,v 17 ,v 12 ,v 15 ,v 14 ,v 22 ,v 28 > and path(v 17 ,v 27 )= <v 17 ,v 12 ,v 15 ,v 14 ,v 22 ,v 25 ,v 27 >. Obviously v7 to v 27 、v 17 to v 27 There is a shared path path(v 22 ,v 27 )= <v 22 ,v 25 ,v 27 >, v 17 to v 27 , v8 to v 28 There is a shared path path(v 17 ,v 22 )= <v 17 ,v 12 ,v 15,v 14 ,v 22 >, which is also v 17 to v 22 And when querying v7 to v 27 The shortest path has traversed v 17 , v8 and v 28 Therefore, the sub-path of the shortest path is still the property of the shortest path, and a more efficient algorithm can be used to share the calculation among multiple queries. If these similar queries can be identified in advance and answered in batches, the query time can be reduced and the calculation efficiency can be improved. The query decomposition strategy proposed in this embodiment can assign some similar queries to the same subset, and then the queries in a subset can be solved at the same time. This paper defines a similarity determination formula, Figure 4 For example, in the figure, q=(v1,v9) and q′=(v2,v8) can be regarded as similar queries, and the similarity S(q1,q2)=0.76.
[0161] exist Figure 5 In the example, the seven queries are divided into two query subsets Q1 = {q1, q2, q3, q4}, Q2 = {q5, q6, q7}. Based on this decomposition, we can get the similarity function S(Q1) = 0.51, S(Q2) = 0.58 for each subset. The scoring function f(Q) = 0.545. The scoring functions of other decompositions are all lower than 0.545, so the best decomposition for this query point is Q = {{q1, q2, q3, q4}, {q5, q6, q7}}.
[0162] Figure 6 To calculate v 39 to v 27 Schematic diagram of the estimated shortest path distance. With v7 as the source vertex, v 27 is the target vertex and the obtained path path(v7,v9)=<v7,v6,v5,v9> , the path distance from vertex v7(10,30) to v9(20,37) is Dist(v7,v9)=16, and the path distance from vertex v9(20,37) to v 27 The straight-line distance between (54,47) is LDist(v9,v 27 )=35.4, according to formula (6), we can get path (v7, v9) to reach v 27 The estimated shortest path distance is preDist(path(v7,v 27 ))=Dist(path(v7,v9))+LDist(v9,v 27 )=16+35.4=51.4.
[0163] Figure 7This is the specific process of batch shortest path query. Figure 5 The shortest path of the query subset Q1 in the query. First, find the main query as q main = <v7,v 27 >, source vertex v7 is added to the expansion heap H as the initial path main In the above example, the first element of the heap is taken as the current processing path each time, that is, <v7>If the end point of the path does not reach the target node, the path is extended and all the paths obtained after extension are added to the extension heap H in the order of increasing estimated shortest path distance. main When the neighbor node expanded to node v7 is the source node v8 of the secondary query q1, the shortest subpath is obtained by the replacement strategy according to the neighbor node retention strategy.<v8,v7> Stored in the reserved heap H1 of q1. Processing path<v7,v6> When the neighbor node is v8 again, according to Theorem 1, in the heap H main Delete<v7,v6,v8> Keep Shorter Paths<v7,v8> The main query continues to expand when processing paths<v7,v8> When the extended node is v8, for the main query, v8's neighbor node v6 has been expanded as an extended node in the second row. According to Corollary 1, there is no need to continue to expand the extended path. For the secondary query q1, according to the extended node retention policy, <v8,v 17 >,<v8,v6> , <v8,v 32 >Store it in heap H1. Since there is already<v8,v6> , then delete the duplicate paths. In line 4, the path is processed <v7,v8,v 32 >When expanding to v5, since the main query path has traversed v5, the heap H main The shortest path from the source point to v5 is<v7,v6,v5> , the path distance is 13, and <v7,v8,v 32 ,v5> has a path distance of 20, so the heap H main Delete <v7,v8,v 32 ,v5>. For the secondary query,<v7,v6,v5> The resulting replacement path<v8,v6,v5> The path distance is 16, by deleting the path <v7,v8,v 32 ,v5>The replacement path obtained <v8,v 32 ,v5> has a path distance of 15, which satisfies the deletion path retention strategy. <v8,v 32 ,v5> is stored in heap H1. In line 5 of the figure, the main query processing path is extended to the target node v of q1 28 According to Theorem 4, the shortest path of q1 is <v8,v 17 ,v 12 ,v 15 ,v 14 ,v 22 ,v 28 >, the query q1 ends. In line 6, the main query processing path is extended to the target node v 27 According to Theorem 2, the shortest path of the main query is <v7,v6,v5,v9,v 11 ,v 10 ,v 14 ,v 22 ,v 25 ,v 27 >, the query ends.
[0164] Figure 8 The sub-query end condition is determined. When the main query is extended to the target node v of the sub-query q1 28 , the path replacement strategy is applied to the path stored in the extended heap at this time to obtain the replacement path, and the replacement paths are sorted in ascending order according to the estimated shortest distance. <v8,v 17 ,v 12 ,v 15 ,v 14 ,v 22 ,v 28 >For the secondary query q1=(v8,v 28 )’s shortest path;
[0165] When a query comes, we first determine whether it matches a query in the result set Rset. The result set Rset stores the shortest paths of all main queries after batch processing of the query set. The specific storage structure is as follows. Fig. 9 As shown, suppose there are three shortest paths p1, p2, and p3 in Rset. When p1 is inserted into Rset, the path number is added to Fig.10 In the inverted list of vertices v1, v4, v6 and v7, and the subgraph constructed according to the path is as follows Fig.11 shown.
[0166] The principle of the query matching strategy constructed in this implementation is as follows: For example, when the query q = (v2, v8) arrives, first check that the inverted lists of v2 and v8 do not have the same path, then the query cannot be obtained directly. Fig.11 As shown, circular regions with radius r are made with v2 and v8 as the center, the source set of the region range is S = {v1}, and the destination set is T = {v5, v7}. Check that there is path number p1 in the inverted list of v1 in S, path number p2 in the inverted list of v5 in T, and path numbers p1 and p3 in the inverted list of v7. Since the inverted lists of v1∈S and v7∈T have the same path number p1, path p1 is the matching path of q = (v2, v8).
[0167] like Fig.12 As shown, in the first round, the source point v2 is used as the forward expansion node and the target node v8 is used as the reverse expansion node for expansion. When v2 is expanded to node v4, the forward expansion path is obtained.<v2,v4> , and v4 is located on the matching path p1=<v1,v4,v6,v7> The path subpath can be used to obtain<v2,v4,v6,v7> . Reversely expand node v8 to nodes v7 and v5 to obtain the reverse expansion path<v7,v8> and<v5,v8> , the matching estimated shortest path can be obtained by the forward expansion path and the reverse expansion path, and all matching estimated shortest paths are added to the matching pile in the order of increasing distance of the matching estimated shortest path. For example, the forward expansion path<v2,v4> and reverse extension path<v7,v8> Available paths to be filled<v2,v4,…,v7,v8> Estimate the shortest path for matching. In the second round, take the head of the matching pile for processing and process the path<v2,v4,…,v7,v8> The forward expansion node is v4, and the reverse expansion node is v7. The third round of expansion continues, and the heap head path is the actual path<v2,v4,v6,v7,v8> , the path matching ends, so the shortest path of q=(v2,v8) is<v2,v4,v6,v7,v8> .
[0168] This embodiment provides an efficient batch query shortest path method. Compared with the existing algorithm, this embodiment does not perform a complex decomposition process on the query, nor does it need to construct a large number of caches to match the answer. Instead, it calculates the similarity of the query, uses the greedy idea to quickly group the query, and obtains a group of query results by incremental calculation in a query process, which maximizes the calculation efficiency and reduces the storage cost. In addition, a path matching strategy is adopted to use the obtained result set to quickly obtain the shortest path result of a query. In this embodiment, a query decomposition strategy is first proposed, and a group of query subsets with high similarity are constructed on this basis, and a main query is selected from them. Secondly, a path expansion strategy, a path retention and replacement strategy are proposed. In the process of expanding the main query, some information useful to the secondary query is stored in the retention heap and the path is replaced, so that the shortest path of the secondary query is obtained in the process of processing the shortest path of the main query, further improving the query efficiency.
[0169] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some or all of the technical features therein by equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention.
Claims
1. A method for batch querying the shortest paths in a road network, characterized in that: The following steps are involved: S1: Obtain a query request about a source vertex and a target vertex in the road network, and perform similarity matching between this query and any result query in a given query result set; Determine whether the similarity between this query and the result query meets a preset similarity threshold; If the query is satisfied, then based on the constructed query matching strategy, the shortest path for this query is obtained according to the shortest path corresponding to the result query in the query result set; Otherwise, execute step S2; S2: put the query into the cache set which is initially empty, and use it as the query set until the cache set reaches the maximum capacity or the maximum storage time; S3: based on the query decomposition strategy, decomposing the query set into a number of query subsets; S4: obtaining the main query and the secondary query of each query subset in sequence; The main query is a query with the longest Euclidean distance between the source vertex and the target vertex selected from all queries in the query subset; The secondary query is the other query in the query subset except the main query; S5: Add the source vertex of the main query as the path starting point to the defined heap set, obtain a new path based on the constructed path extension strategy, and add the new path to the heap set in increasing order of the estimated shortest path distance to obtain the main query extension heap; S6: storing the source vertex of the secondary query as the path starting point in the defined retention heap, and obtaining the secondary query retention heap based on the constructed path retention strategy; S7: Based on the constructed path replacement strategy, the shortest path of all queries in the query set is obtained according to the main query expansion heap and the secondary query retention heap.
2. The method for batch querying the shortest paths in a road network according to claim 1, characterized in that: The S3 specifically includes the following steps: S31: Calculate the query similarity for any two queries in the query set Q, and the calculation formula for the query similarity is S(q i ,q j )=w1DS(q i ,q j )+w2AS(q i ,q j ) AS(q i ,q j )=cosθ Where: S(q i ,q j ) represents the query similarity between any two queries, and 0≤S(q i ,q j )≤1;DS(q i ,q j ) represents the distance similarity of two queries; AS(q i ,q j ) represents the angular similarity of the two queries; cosθ represents the cosine value of the smaller angle between the starting point and the end point of the two queries; d max Represents the distance similarity threshold between two points; q i ,q j represents any two queries in the query set Q, and q i =(s i , t i ), q j =(s j , t j );s i , t i Respectively represent the query q i The source and target vertices of s j , t j Respectively represent the query q j The source vertex and target vertex of the grid; w1, w2 represent the weight coefficients used to adjust the importance of the starting point, end point and angle in the similarity calculation; S32: construct a similarity scoring function to group all queries in the query set Q into similar queries and obtain several query subsets; And the expression of the similarity scoring function is Where: f(Q) represents the similarity scoring function; S(Q i ) represents the value used to measure the query subset Q i An indicator of the similarity between inner queries; Indicates that in the query subset Q i The number of combinations of any two queries in the query set Q; n represents the number of queries in the query set Q; q m ,q n Represents the query subset Q i Any two queries in .
3. The method for batch querying the shortest paths in a road network according to claim 2, characterized in that: The S5 specifically includes the following steps: S51: adding the source vertex of the main query as the path starting point to the defined heap set, confirming and selecting the first heap path in the heap set with the source vertex as the starting point as the processing path path; S52: determining whether the end point of the processing path path reaches the target vertex of the main query; if the end point of the processing path path does not reach the target vertex of the main query, performing path extension on the processing path path based on the constructed path extension strategy to obtain multiple new paths; The path extension strategy is: S521: confirm whether the end point v of the processing path path is an extended node in the road network; S522: If it is confirmed that the end point v of the processing path path is an unexpanded node, the end point v is used as a source vertex, and all neighboring nodes adjacent to the end point v and not belonging to the processing path path are used as target vertices to obtain multiple new extended paths, and then execute step S53; If it is confirmed that the end point v of the processing path path is an expanded node, the processing path path is discarded and not added to the expansion heap; The expanded nodes are all neighbor nodes in the acquired road network that are adjacent to the end point v of the processing path path and do not belong to the processing path path, and are used as the next node of the end point v of the processing path path to form an extended path, and the neighbor nodes that are adjacent to the end point v of the processing path path and do not belong to the processing path path are marked as expanded nodes; S53: adding each extended new path to the heap set in increasing order of the estimated shortest path distance, so as to update the extended heap to obtain the current main query extended heap; S54: Obtain a new processing path path starting from the source vertex in the current main query expansion heap according to the greedy algorithm; if the end point of the new processing path path is not the target vertex, repeat steps S52 to S53 until the end point of the new processing path path is the target vertex, so as to obtain a complete path from the source vertex to the target vertex to obtain the final main query expansion heap.
4. The method for batch querying the shortest paths in a road network according to claim 3, characterized in that: The calculation formula for the estimated shortest path distance is preDist(path(v i ,v))=Dist(path(v i ,v))+LDist(v,v j ) Where: preDist(path(v i ,v)) represents the estimated shortest path distance of the new path to the target vertex; v i Indicates the source vertex of the processing path path; v j Represents the target vertex of the main query; path(v i ,v) represents the processing path and path(v i ,v): <v1=(v i ),v2,…,v n =(v)>;Dist(path(v i ,v)) means v i The path distance between v and LDist(v,v j ) represents the current path endpoint v and the target vertex v j The straight-line distance between .
5. The method for batch querying the shortest paths in a road network according to claim 3, characterized in that: The path retention strategy constructed in S6 includes a neighbor node retention strategy, an extended node retention strategy, and a deleted path retention strategy in sequence; The neighbor node retention strategy: When the main query path is expanded to the neighbor node s i When the neighbor node s i The path distances to all nodes and nodes of the currently processed path are stored in the reserved heap; The extended node retention strategy: When the main query path is expanded, the neighbor node s i When expanding, the neighbor node s i To neighbor node s i The path distances of the neighbor nodes are stored in the reserved heap, and the paths with repeated path endpoints v are deleted and the paths with small path distances among the repeated paths are retained; The deletion path retention strategy: when there is a deletion path path′(s i ,v)) when; Then confirm to delete the path path′(s i ,v) and processing path path(s i ,v) path distance size; If you delete the path path′(s i ,v) than the processing path path(s i ,v) is small, then the path path′(s i ,v) is stored in the reserved heap, otherwise, the path path(s) is processed i ,v) Store in the retention heap to obtain the secondary query retention heap; Wherein, the deletion path path′(s i ,v) is the processing path path(s) in the main query expansion heap i ,v) Paths with the same first and last nodes.
6. The method for batch querying the shortest paths in a road network according to claim 4, characterized in that: The path replacement strategy constructed in S7 is specifically: When the main query is expanded to the target vertex of the secondary query, a replacement path is obtained based on all paths in the main query expansion heap based on the path replacement strategy; The method for obtaining the replacement path is: Given any path in the main query expansion heap, path= main ,…,v j ,…,v i > and the path path′ in the secondary query heap = i ,…,v j > Then main ,…,v j ,…,v i >Subpath main ,…,v j >Replace with i ,…,v j >, get the source vertex s in the secondary query retention heap i To all path endpoints v in the main query expansion heap i Path i ,…,v i >, recorded as the secondary query to retain the path path′(s i ,v i )'s replacement path. 7. The method for batch querying the shortest paths in a road network according to claim 1, characterized in that: The query matching strategy constructed in S1 is specifically: S11: Define a matching heap H match And it is initially an empty set; Given a query q = (s, t), and based on the inverted list preset in the query result set Rset, confirm whether there is a path number in the inverted list corresponding to the same source vertex s and target vertex t; If there is an identical path number p, then path number p is used as the matching path for query q; If there is no identical path number p, obtain the point set of neighbor nodes adjacent to the source vertex s and the target vertex t, and record the point set of neighbor nodes of the source vertex s as the source set S; Record the point set of the neighbor nodes of the target vertex t as the destination set T, and obtain multiple identical path numbers in the inverted lists of the source set S and the destination set T; According to the path number, obtain the path p′(s′, t′) corresponding to a pair of neighbor nodes (s′, t′) closest to the source vertex s and the target vertex t as the matching path of the query q, and s′∈S, t′∈T; And put the matching path of the query q into the matching pile H match middle; S12: Obtain the initial processing path path of query q according to query q = (s, t) and the corresponding matching path<s,…,t> ; Where, ... represents the path to be filled; Based on the forward expansion strategy and the reverse expansion strategy, the initial processing path path<s,…,t> Perform path filling to obtain forward / reverse extension paths; The forward expansion strategy: Get the initial processing path path<s,…,t> The last node before the to-be-filled part is taken as the forward expansion node v; Get the node that is adjacent to the forward expansion node v and does not belong to the initial processing path path<s,…,t> All nodes v in neighbor , and take the forward expansion node v as the source vertex, and take the node v neighbor as the target vertex to obtain multiple forward expansion paths; The reverse expansion strategy: Get the initial processing path path<s,…,t> The first node after the part to be filled is taken as the reverse expansion node v′; Get the node that is adjacent to the reverse expansion node v′ and does not belong to the path<s,…,t> All nodes v in neighbor ′, and take the reverse expansion node v′ as the source vertex, and take the node v neighbor ′ as the target vertex to obtain multiple reverse extension paths; S13: Obtaining a plurality of final processing paths according to the random combination of the forward extension path and the reverse extension path; Based on the matching estimated shortest path distance calculation formula, the matching estimated shortest path distance mpreDist of each final processing path path is obtained, and each final processing path path is added to the matching pile H in the increasing order of the matching estimated shortest path distance mpreDist match To update the matching heap H match ; And according to the updated matching heap H match Get the shortest path corresponding to query q.
8. The method for batch querying the shortest paths in a road network according to claim 7, characterized in that: The matching estimated shortest path distance calculation formula in S13 is: mpreDist(path(v i ,v))= Dist(path(v i ,v))+Dist(path(v n ,v j ))+LDist(v,v n ) Where: mpreDist(path(v i ,v)) represents the path path(v i ,v) reaches the target vertex v j The matching estimated shortest path distance; Dist(v i ,v) represents the source vertex v i The path distance from the current path end point v; Dist(v n ,v j ) represents node v n With the target vertex v j The path distance between them; LDist(v,v n ) is the current path endpoint v and node v n The straight-line distance between .
Citation Information
Patent Citations
Set-oriented space keyword query method for road network
CN105868336A
Shortest path query method and system based on approximation algorithm
CN112380460A
Load-aware road network shortest path distance calculation method and device
CN114253975A
Diversity-based Top-k shortest path research method
CN117556974A
Speeding up Stochastic Routing of Vehicles using Tiering
US20240068823A1
