Path planning method and device, computer device and storage medium
By reading the path graph and constructing a multi-way tree at once, the storage space and efficiency problems of traditional path planning algorithms in handling negative weights are solved, and the shortest path is determined efficiently with minimal space overhead.
Patent Information
- Application Number
- CN202310953519.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-07-31
- Publication Date
- 2026-01-23
- Estimated Expiration
- 2043-07-31
AI Technical Summary
Traditional path planning algorithms, such as Dijkstra's algorithm, require a large amount of storage space when dealing with negative weights and have limited applicability, making them inefficient for solving path planning problems.
By reading the feature values of road segments in the path graph at once, a multi-way tree is constructed to determine the feature values of the connecting path between positive and negative road segment feature values, and the shortest path is determined with minimal space overhead.
With the inclusion of positive and negative road segment feature values, the shortest path can be efficiently determined with minimal space overhead, significantly reducing time complexity and outperforming traditional algorithms.
Smart Images

Figure CN116989812B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the network technical field, in particular to a path planning method and device, computer equipment and storage medium. BACKGROUND
[0002] With the development of network technology, there are traffic planning, robot motion control, game AI, unmanned aerial vehicle route planning, logistics distribution, electronic map and navigation and other application scenarios, which need to plan a path, for example, to determine the shortest path.
[0003] In the traditional technology, Dijkstra algorithm and other algorithms are used to realize path planning.
[0004] However, the data storage space required by Dijkstra algorithm and other algorithms is high, and it does not support negative weight. Not only more space is needed, but also the applicable scenarios are limited.
[0005] It should be noted that the information disclosed in the above background section is only used to strengthen the understanding of the background of the present application, and therefore can include information that does not constitute prior art known to those of ordinary skill in the art. SUMMARY
[0006] Therefore, it is necessary to provide a path planning method, device, computer equipment and storage medium capable of supporting positive and negative weights with smaller space overhead to solve the above technical problems.
[0007] A path planning method, the method comprising:
[0008] reading a to-be-analyzed path graph from memory at one time and extracting the road segment feature values carried by each road segment line in the to-be-analyzed path graph; the to-be-analyzed path graph is a connection graph composed of a plurality of nodes and road segment lines connecting the plurality of nodes, and the to-be-analyzed path graph contains at least one path from a target starting node to a target ending node; the road segment feature value has positive and negative values;
[0009] determining a current road segment line between a current starting node and each current ending node, and obtaining the road segment feature value of the current road segment line; the current ending node is a node having a connection relationship with the current starting node;
[0010] determining a connection line path feature value from the target starting node to the current ending node based on the road segment feature value of the current road segment line, and determining a minimum connection line path feature value in the connection line path feature value;
[0011] If the current end node corresponding to the minimum connection path characteristic value is the target end node, a target shortest path is determined according to the path corresponding to the minimum connection path characteristic value, and the target shortest path is output.
[0012] In an optional embodiment, after the current link line between the current start node and each current end node is determined and the link characteristic value of the current link line is obtained, the method further comprises:
[0013] If the current start node is the root node, a multi-way tree is constructed with the current end node as a child node of the root node.
[0014] If the current start node is not the root node, a multi-way tree is constructed with the current start node as a child node of the previous node and the current end node as a child node of the current start node.
[0015] Correspondingly, the determination of the connection path characteristic value from the target start node to the current end node based on the link characteristic value of the current link line comprises:
[0016] The sum of each link characteristic value from the root node to the current end node is determined to obtain the connection path characteristic value from the target start node to the current end node.
[0017] In an optional embodiment, if the current end node corresponding to the minimum connection path characteristic value is the target end node, the target shortest path is determined according to the path corresponding to the minimum connection path characteristic value, which comprises:
[0018] If there is only positive link characteristic value in the path graph to be analyzed, or if there is negative link characteristic value in the path graph to be analyzed and the relative shortest path needs to be output, the path corresponding to the minimum connection path characteristic value is determined as the target shortest path.
[0019] If there is negative link characteristic value in the path graph to be analyzed and the absolute shortest path needs to be output, it is determined whether the current end node corresponding to the minimum connection path characteristic value has a child node, and the target shortest path is determined according to the determination result.
[0020] In an optional embodiment, the determination of whether the current end node corresponding to the minimum connection path characteristic value has a child node and the determination of the target shortest path according to the determination result comprise:
[0021] If it is determined that the current end node has a child node, the current end node corresponding to the minimum connection path characteristic value is taken as the current start node, and the step of determining the minimum connection path characteristic value is continued until there is no child node in the current end node.
[0022] If it is determined that the current end node has no child node, the path corresponding to the minimum link path characteristic value is determined as the target shortest path.
[0023] In an optional embodiment, the determining the sum of the characteristic values of each path segment from the root node to the current end node to obtain the link path characteristic value from the target start node to the current end node comprises:
[0024] If there is a negative path segment characteristic value in the path graph to be analyzed and the calculation mode is the positive path segment characteristic value calculation mode, the sum of the absolute values of the characteristic values of each path segment from the root node to the current end node is determined to obtain the link path characteristic value from the target start node to the current end node.
[0025] In an optional embodiment, after the multi-way tree is constructed or adjusted each time, the method further comprises:
[0026] If there are at least two same leaf nodes in the constructed or adjusted multi-way tree, the link path characteristic values of the paths between the root node and the leaf nodes are determined, and only the path with the minimum link path characteristic value is retained in the multi-way tree.
[0027] In an optional embodiment, if there is a negative path segment characteristic value in the path graph to be analyzed, after the path with the minimum link path characteristic value is retained in the multi-way tree, the method further comprises:
[0028] For any one leaf node, the leaf node is taken as a target leaf node;
[0029] It is determined whether there is a target parent node with the same content as the target leaf node in the remaining paths of the multi-way tree;
[0030] If there is, the link path characteristic values of the paths between the root node and the target leaf node and between the root node and the target parent node are respectively determined;
[0031] If the link path characteristic value corresponding to the target parent node is longer than the link path characteristic value corresponding to the target leaf node, all the child nodes under the target parent node are moved to be child nodes of the target leaf node.
[0032] A path planning device, the device comprising:
[0033] The path graph reading module is configured to read a path graph to be analyzed from the memory at one time and extract a road segment characteristic value carried by each road segment line in the path graph to be analyzed; the path graph to be analyzed is a connection graph composed of a plurality of nodes and road segment lines connecting the plurality of nodes, and the path graph to be analyzed contains at least one path from a target starting node to a target ending node; the road segment characteristic value has positive and negative values;
[0034] The characteristic value obtaining module is configured to determine a current road segment line between a current starting node and each current ending node, and obtain a road segment characteristic value of the current road segment line; the current ending node is a node having a connection relationship with the current starting node;
[0035] The minimum characteristic value determining module is configured to determine a connection line path characteristic value from the target starting node to the current ending node based on the road segment characteristic value of the current road segment line, and determine a minimum connection line path characteristic value in the connection line path characteristic value;
[0036] The shortest path determining module is configured to determine a target shortest path according to a path corresponding to the minimum connection line path characteristic value if the current ending node corresponding to the minimum connection line path characteristic value is the target ending node, and output the target shortest path.
[0037] A computer device includes a memory and a processor, the memory stores a computer program, and the processor implements the following steps when executing the computer program:
[0038] The path graph reading module is configured to read a path graph to be analyzed from the memory at one time and extract a road segment characteristic value carried by each road segment line in the path graph to be analyzed; the path graph to be analyzed is a connection graph composed of a plurality of nodes and road segment lines connecting the plurality of nodes, and the path graph to be analyzed contains at least one path from a target starting node to a target ending node; the road segment characteristic value has positive and negative values;
[0039] The characteristic value obtaining module is configured to determine a current road segment line between a current starting node and each current ending node, and obtain a road segment characteristic value of the current road segment line; the current ending node is a node having a connection relationship with the current starting node;
[0040] The minimum characteristic value determining module is configured to determine a connection line path characteristic value from the target starting node to the current ending node based on the road segment characteristic value of the current road segment line, and determine a minimum connection line path characteristic value in the connection line path characteristic value;
[0041] The shortest path determining module is configured to determine a target shortest path according to a path corresponding to the minimum connection line path characteristic value if the current ending node corresponding to the minimum connection line path characteristic value is the target ending node, and output the target shortest path.
[0042] A computer readable storage medium, having stored thereon a computer program, the computer program being executed by a processor to implement the following steps:
[0043] reading a to-be-analyzed path graph from the memory at one time and extracting a link feature value carried by each link in the to-be-analyzed path graph; the to-be-analyzed path graph is a connection graph composed of a plurality of nodes and link lines connecting the plurality of nodes, and the to-be-analyzed path graph contains at least one path from a target starting node to a target ending node; the link feature value has positive and negative values;
[0044] determining a current link line between a current starting node and each current ending node, and obtaining a link feature value of the current link line; the current ending node is a node having a connection relationship with the current starting node;
[0045] based on the link feature value of the current link line, determining a link path feature value from the target starting node to the current ending node, and determining a minimum link path feature value in the link path feature value;
[0046] if the current ending node corresponding to the minimum link path feature value is the target ending node, determining a target shortest path according to a path corresponding to the minimum link path feature value, and outputting the target shortest path.
[0047] The above path planning method reads a to-be-analyzed path graph and extracts a link feature value carried by each link in the to-be-analyzed path graph; determines a current link line between a current starting node and each current ending node, and obtains a link feature value of the current link line; based on the link feature value of the current link line, determines a link path feature value from the target starting node to the current ending node, and determines a minimum link path feature value in the link path feature value; if the current ending node corresponding to the minimum link path feature value is the target ending node, determines a target shortest path according to a path corresponding to the minimum link path feature value, and outputs the target shortest path. In the case of containing positive and negative link feature values, only a small amount of space overhead is required to efficiently determine the shortest path. Correspondingly, the path planning device, equipment and storage medium provided by the present application also have the above technical effects. BRIEF DESCRIPTION OF DRAWINGS
[0048] Figure 1 a flowchart of a path planning method in one embodiment;
[0049] Figure 2 a schematic diagram of a to-be-analyzed path graph in one embodiment;
[0050] Figure 3 a schematic diagram of constructing a multi-way tree in one embodiment;
[0051] Figure 4 A schematic diagram for constructing a multi-way tree in another embodiment;
[0052] Figure 5 A schematic diagram for constructing a multi-way tree in another embodiment;
[0053] Figure 6 A schematic diagram for node migration in an embodiment;
[0054] Figure 7 A structural block diagram of a path planning device in an embodiment;
[0055] Figure 8 An internal structural diagram of a computer device in an embodiment. DETAILED DESCRIPTION
[0056] In order to make the purposes, technical solutions and advantages of the present application clearer, further detailed description will be made to the present application in combination with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application, and are not used to limit the present application.
[0057] In an embodiment, as shown in Figure 1 A path planning method is provided, and the embodiment is exemplified by the method applied to a terminal. It should be understood that the method can also be applied to a server, and can also be applied to a system including a terminal and a server, and is realized through the interaction of the terminal and the server. The terminal can be, but is not limited to, various personal computers, notebook computers, smart phones, tablet computers and portable wearable devices, and the server can be realized by an independent server or a server cluster composed of multiple servers.
[0058] In the embodiment, the method includes the following steps:
[0059] S101, reading a to-be-analyzed path graph from the memory at one time and extracting road segment characteristic values carried by each road segment line in the to-be-analyzed path graph; the to-be-analyzed path graph is a connection graph composed of multiple nodes and road segment lines connecting the multiple nodes, and the to-be-analyzed path graph contains at least one path from a target starting node to a target ending node; the road segment characteristic values have positive and negative values.
[0060] To achieve optimal computational performance and improve performance within massive loop calculations, this application employs the following techniques: 1) Allocate memory all at once, avoiding or even completely eliminating dynamic memory allocation, even on the stack; 2) Minimize the number of loops; 3) Find conditions to terminate loops early; 4) Minimize operations, comparisons, and assignments; 5) Use priority queues instead of traversal. Nodes can be allocated all at once. Although it's a multi-branch tree, each node is unique, so only one memory allocation is needed. During computation, only updating node pointers is required. Therefore, this application's embodiment directly reads the path graph to be analyzed from memory all at once when path planning is needed. This improves both data storage and data retrieval performance, thereby increasing path planning efficiency.
[0061] A schematic diagram of the path to be analyzed is shown below. Figure 2 As shown, the path diagram to be analyzed contains six nodes: A, B, C, D, E, and F. These nodes are connected by lines, which are road segment lines. Each road segment line carries a road segment feature value. The road segment feature value is the weight on the connecting line, and can be either positive or negative. Figure 2 All road segment feature values are positive. Optionally, road segments may or may not include direction. When road segments include direction, the path graph to be analyzed is a directed graph; when road segments do not include direction, the path graph to be analyzed is an undirected graph. The direction of road segments has practical meaning in its application scenarios. For example, A→E represents a one-way road segment from A to E, and its corresponding road segment feature value can represent the distance traveled from A to E. If the travel is from E to A, the road segment feature value may be different. Figure 2 Each road segment in the middle includes directions, therefore Figure 2 The path graph to be analyzed is a directed graph.
[0062] In an optional embodiment, after reading the path graph to be analyzed from memory all at once, the method further includes: identifying isolated nodes from the path graph to be analyzed, and filtering out the isolated nodes from the path graph to be analyzed; wherein, the isolated node is a node in the path graph to be analyzed that has one or fewer road segments. Figure 2 As shown, there is a road segment connecting node F to node E, which is an isolated node and will be filtered out and not considered in the subsequent process of determining the shortest path.
[0063] For ease of explanation, the following description will use the target starting node as A and the target ending node as D as an example. That is, unless otherwise specified, the objective of this embodiment is to determine the shortest path from A to D.
[0064] S102, determine the current road segment line between the current starting node and each current ending node, and obtain the road segment feature value of the current road segment line; the current ending node is a node that has a connection relationship with the current starting node.
[0065] like Figure 3 As shown, assuming the current starting node is A, then nodes B / D / E that are connected to it are the current ending nodes. The feature values of these three road segments are 30 / 100 / 50 respectively.
[0066] Optionally, the current ending node can be a child node of the current starting node, but cannot be the parent node. Furthermore, in a directed graph, the current ending node can be a child node pointed to by the current starting node.
[0067] S103, based on the segment feature value of the current road segment, determine the connection path feature value from the target starting node to the current ending node, and determine the minimum connection path feature value among the connection path feature values.
[0068] If the current starting node is the same as the target starting node, such as Figure 3 As shown, the corresponding connection path feature value is the segment feature value of the current road segment, i.e., 30 / 100 / 50. If the current starting node is not the target starting node, then each road segment from the target starting node to the current ending node can be determined. Based on the segment feature values of these road segments, the connection path feature value is obtained, and the minimum connection path feature value is determined by comparing the numerical values.
[0069] S104, if the current end node corresponding to the minimum connection path feature value is the target end node, then determine the target shortest path according to the path corresponding to the minimum connection path feature value, and output the target shortest path.
[0070] If the current end node corresponding to the feature value of the shortest path is the target end node, it means that a path from the target start node to the target end node has been found, and this path is the shortest path among all the paths found. Therefore, this path is determined as the target shortest path and output.
[0071] Optionally, the shortest path to the target can be output via images, audio, video, or other means. Furthermore, the shortest path can be output based on the specific application scenario. For example, in a navigation scenario, after obtaining the shortest path, corresponding navigation guidance can be displayed on the screen to guide the user from point A to point D as quickly as possible.
[0072] Optionally, the number of path nodes can be considered when determining the shortest path to the target. If a target endpoint exists at the node level corresponding to the number of path nodes, the path corresponding to that endpoint is directly considered the shortest path to the target. Furthermore, if the minimum number of path nodes is required, any path from the target start node to the target end node can be found and output as the shortest path to the target. This approach can effectively simplify the computation when there are many node levels.
[0073] In the above path planning method, the path graph to be analyzed is read and the segment feature values carried by each road segment line in the path graph are extracted; the current road segment line between the current starting node and each current ending node is determined, and the segment feature value of the current road segment line is obtained; based on the segment feature value of the current road segment line, the feature value of the connecting path from the target starting node to the current ending node is determined, and the minimum connecting path feature value is determined from the connecting path feature values; if the current ending node corresponding to the minimum connecting path feature value is the target ending node, then the target shortest path is determined according to the path corresponding to the minimum connecting path feature value, and the target shortest path is output. Even with positive and negative road segment feature values, its space complexity is node-level, meaning only the number of nodes is determined, without complex logic such as loop processing, requiring very little space overhead to efficiently determine the shortest path. Moreover, this scheme can also effectively reduce the time complexity, achieving a time complexity of O(N), where N is the number of nodes.
[0074] In an optional embodiment, after determining the current road segment line between the current starting node and each current ending node, and obtaining the road segment feature value of the current road segment line, the method further includes: if the current starting node is the root node, then constructing a multi-way tree with the current ending node as a child node of the root node; if the current starting node is not the root node, then constructing a multi-way tree with the current starting node as a child node of the previous node and the current ending node as a child node of the current starting node; correspondingly, determining the connection path feature value from the target starting node to the current ending node based on the road segment feature value of the current road segment line includes: determining the sum of the feature values of each road segment from the root node to the current ending node to obtain the connection path feature value from the target starting node to the current ending node.
[0075] like Figure 3 As shown, if the current starting node is A, and A is also the target starting node, then a multi-way tree can be constructed directly with A as the root node and B / D / E as child nodes. For example... Figure 4As shown, given that the multi-way tree corresponding to node A has already been analyzed and the current starting node is B, B is designated as a child node of A, and C and E, which are connected to B, are designated as child nodes of B, thus constructing the multi-way tree. Optionally, this embodiment of the application can achieve layer-by-layer path filtering by constructing the multi-way tree layer by layer. The shortest path can be determined during the construction of the multi-way tree, resulting in high path planning efficiency.
[0076] Furthermore, based on the constructed multi-way tree, the characteristic values of the connecting path from the target starting node to the current ending node are determined. For example... Figure 3 As shown, the characteristic values of the path connecting the target starting node to the current ending node are A→B / A→D / A→E: 30 / 100 / 50. Figure 4 As shown, the characteristic values of the connecting path from the target starting node to the current ending node are A→B→C / A→D / A→E: 70 / 100 / 50.
[0077] In an optional embodiment, the step of determining the target shortest path based on the path corresponding to the minimum connecting path feature value if the current ending node corresponding to the minimum connecting path feature value is the target ending node includes: if the path graph to be analyzed contains only positive road segment feature values, or if the path graph to be analyzed contains negative road segment feature values and a relative shortest path needs to be output, then the path corresponding to the minimum connecting path feature value is determined as the target shortest path; if the path graph to be analyzed contains negative road segment feature values and an absolute shortest path needs to be output, then it is determined whether the current ending node corresponding to the minimum connecting path feature value has child nodes, and the target shortest path is determined based on the determination result.
[0078] In an optional embodiment, the step of determining whether the current end node corresponding to the minimum connecting path feature value has child nodes, and determining the target shortest path based on the determination result, includes: if it is determined that the current end node has child nodes, then taking the current end node corresponding to the minimum connecting path feature value as the current starting node and continuing to determine the minimum connecting path feature value, until there are no child nodes in the current end node; if it is determined that the current end node has no child nodes, then determining the path corresponding to the minimum connecting path feature value as the target shortest path.
[0079] Optionally, the step of further determining the minimum connecting path feature value is to continue performing the following steps: determine the current road segment line between the current starting node and each current ending node, and obtain the road segment feature value of the current road segment line; the current ending node is a node that has a connection relationship with the current starting node; based on the road segment feature value of the current road segment line, determine the connecting path feature value from the target starting node to the current ending node, and determine the minimum connecting path feature value among the connecting path feature values.
[0080] The path map to be analyzed supports negative road segment feature values. Furthermore, the path map to be analyzed has positive road segment feature values by default, while negative road segment feature values are sometimes present and sometimes absent. This application embodiment supports negative road segment feature values and performs different targeted processing for the presence and absence of negative road segment feature values to ensure accurate and reliable path division.
[0081] Optionally, embodiments of this application provide the following calculation method:
[0082] 1) Supports relative shortest paths (Note: In a directed graph with only positive weights, this mode obtains the absolute shortest path);
[0083] 2) Supports absolute shortest path (Note: In directed graphs with only positive weights, try not to use this mode, otherwise it will bring meaningless additional overhead).
[0084] The concept of relative shortest path is explained as follows: As described above regarding the algorithm's calculation mode, relative shortest path applies to directed graphs that support negative weights. For directed graphs with positive weights, the absolute shortest path is obtained (in a directed graph with positive weights, once a shortest path is found, there is no better solution, therefore it is the optimal solution). The relative shortest path for a directed graph supporting negative weights can be understood as follows: In a certain result set, a shortest path has been obtained, but in subsequent calculations, there may still be better solutions. However, further calculations are not performed; instead, the current best result is used as the path planning result.
[0085] Optional, such as Figure 5 As shown, with the current starting point E, a multi-way tree is constructed. The shortest path in the tree is A→E→D: 60. Since the destination has been reached and this is the shortest path in the tree (less than other branches, A→B→C: 70), no further radiating is needed, and the pathfinding ends. In cases supporting negative weights, if a relative shortest path is required, the process can also end; however, if an absolute shortest path is needed, radiating must continue until no more nodes can be added.
[0086] In an optional embodiment, determining the sum of the feature values of each road segment from the root node to the current end node to obtain the feature value of the connecting path from the target start node to the current end node includes: if there are negative road segment feature values in the path graph to be analyzed and the calculation mode is the positive road segment feature value calculation mode, then determining the sum of the absolute values of the feature values of each road segment from the root node to the current end node to obtain the feature value of the connecting path from the target start node to the current end node.
[0087] The positive segment feature value calculation mode refers to the mode in which the positive and negative signs of all segment feature values are ignored and all are treated as positive segment feature values.
[0088] Because there are differences in the support for positive and negative weights, to avoid situations where a directed graph in the parameters contains negative weights but the calculation mode is specified as positive, the default approach does not distinguish between positive and negative weights and runs using a uniform algorithm. In scenarios involving positive weights, this approach does not incur additional overhead.
[0089] In an optional embodiment, after each construction or adjustment of the multi-way tree, the method further includes: if there are at least two identical leaf nodes in the constructed or adjusted multi-way tree, then determining the path feature values of the connecting paths from the root node to these leaf nodes respectively, and retaining only the path with the smallest connecting path feature value in the multi-way tree.
[0090] like Figure 3 As shown, after constructing the multi-way tree, each path is analyzed to determine the shortest path as A→B. Starting from point B, the path continues to radiate outwards (without radiating to the parent node), as follows... Figure 4 As shown, point E is visited twice (A→B→E and A→E), but the cost of A→B→E is greater than that of A→E, so the branch A→B→E is discarded.
[0091] The shortest branch in the tree is A→E, therefore, we radiate from point E. For example... Figure 5 As shown, points E have already been radiated to B and D, which are paths that have already appeared. According to the previous rule, the paths A→D and A→E→B will be discarded: A→D is greater than A→E→D, and A→E→B is greater than A→B. The shortest path in the tree is then A→E→D: 60. Since the destination has been reached and it is the shortest path in the tree (less than other branches, A→B→C: 70), no further radiation is needed, and the pathfinding ends.
[0092] In an optional embodiment, if negative road segment feature values exist in the path graph to be analyzed, then after retaining only the path with the smallest connecting path feature value in the multi-way tree, the method further includes: for any leaf node, taking it as the target leaf node; determining whether there is a target parent node with the same content as the target leaf node in the remaining paths of the multi-way tree; if so, determining the connecting path feature values of the paths from the root node to the target leaf node and to the target parent node respectively; if the connecting path feature value corresponding to the target parent node is longer than the connecting path feature value corresponding to the target leaf node, then moving all child nodes under the target parent node to become child nodes of the target leaf node.
[0093] In this embodiment of the application, some information is cached and updated during execution, such as the weight of the root node and the weight of the child nodes. Based on the cached weight of the root node and the weight of the child nodes, the corresponding data can be grafted. For example Figure 6 As shown, starting from point E, radiating to point B results in point B being duplicated. Since A→B: 80 is greater than A→E→B: 70, and point B originally had a subtree, we can move the subtree of point B to the new point B. If we find that A→D is already the shortest path in the tree, we can end the radiating process; the shortest path is A→D: 100. However, while it's easy to see that this situation wouldn't occur in a directed graph with positive weights, it is possible in a directed graph that supports negative weights.
[0094] This application also provides a path planning method, including the following steps:
[0095] 1) Based on this Figure 2 For example: Find the shortest path from A to D.
[0096] 2) First, the reachable destinations from A are B, D, and E. These can be arranged as follows: Figure 3 The small image on the right shows a multi-branch tree.
[0097] 3) It can be observed that point D has been reached from point A, but this may not be the optimal path (it is not the shortest path in the tree at this point; if the algorithm's calculation mode is set to minimum number of nodes, the process could have ended when adding node D, at which point the path would be A→D). In this case, the shortest path is A→B. Therefore, continuing to radiate from point B yields the following... Figure 4 The middle inset shows a multi-way tree. Point E is visited twice, but the cost of A→B→E is greater than that of A→E. Therefore, the branch A→B→E is discarded, resulting in... Figure 4 The rightmost small image shows a multi-branch tree.
[0098] 4) At this point, the shortest branch in the tree is A→E. Therefore, radiating outwards from point E yields the following results: Figure 5The small diagram in the middle shows a multi-way tree. We can see that points E have already been traversed to B and D. According to the previous rule, the paths A→D and A→E→B will be discarded: A→D is greater than A→E→D, and A→E→B is greater than A→B. Therefore... Figure 5 The rightmost small image shows a multi-branch tree.
[0099] 5) The shortest path in the tree after this is A→E→D: 60. Since the destination has been reached and it is the shortest path in the tree (shorter than other branches, A→B→C: 70), no further radiation is needed, and the pathfinding ends here. In cases where negative weights are supported, if a relative shortest path is required, the process can also end; however, if an absolute shortest path is required, radiation must continue until no more nodes can be added.
[0100] For exceptional cases, if the following occurs: Figure 6 Given the situation shown, how should we prune the branches?
[0101] That is, if starting from point E, radiating to point B results in point B being duplicated, and A→B: 80 is greater than A→E→B: 70, and point B originally had a subtree. In this embodiment, the subtree of point B can be moved to the new point B. At this point, it is found that A→D is already the shortest path in the tree, so the radiating can end. The shortest path is A→D: 100.
[0102] The performance of the above embodiments is compared with other solutions:
[0103] Implement the above-described solution, Dijkstra's algorithm, and a priority queue optimization of Dijkstra's algorithm using Golang. Comparison method: Randomly generate 10,000 nodes, each with [0, 16) edges. Then compare the performance of several algorithms. For the same directed graph, randomly generate 20 pairs of nodes (start point + end point). For each algorithm, solve for the shortest path of these 20 pairs of nodes and record the time consumption. Since Dijkstra does not support negative weights, the randomly generated map does not contain negative weights. The time consumption statistics are as follows: This algorithm takes 140ms, Dijkstra's algorithm takes 9805ms, and the priority queue optimization of Dijkstra's algorithm takes 2687ms. That is: the priority queue optimization version of Dijkstra saves 77.29% of the time cost compared to the non-optimized version; this algorithm saves 93.71% of the time cost compared to the priority queue optimization version of Dijkstra; this algorithm saves 98.57% of the time cost compared to the non-optimized version of Dijkstra. As the amount of data increases, the performance of this algorithm far surpasses that of Dijkstra's algorithm and its optimized versions.
[0104] Furthermore, this scheme requires only O(E*N) space to store data, where N is the number of nodes and E is the average number of edges per node; the space complexity is O(N), and the time complexity is O(N). In most application scenarios, E tends to be constant, such as at traffic intersections, where each node typically has 4 edges, and even in more complex scenarios, it generally has a maximum of 8 edges. The following verifies that the time complexity of this algorithm tends to O(N).
[0105] Verification scheme: For a certain number of nodes, randomly select edges in the range [0, 16) and calculate the shortest distance between any two random points. Test several sets of data sequentially, setting the number of nodes to 10000, 20000, 40000, and 100000. The results are as follows:
[0106] Data Volume Time Consuming Statistics 10,000 10ms 20,000 31ms 40,000 50ms 100,000 184ms
[0107] As can be seen, with 100,000 nodes, this solution can solve the shortest path between any two random nodes in less than 200ms, and the time cost is indeed close to O(N) to a certain extent. Based on the data above, it can be deduced that solving the shortest path between any two points in 1 million nodes can be completed in just a few seconds.
[0108] It should be understood that although the steps in the flowchart above are shown sequentially as indicated by the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowchart above may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the steps or stages in other steps.
[0109] Based on the same idea as the path planning method in the above embodiments, the present invention also provides a path planning apparatus, which can be used to execute the above path planning method. For ease of explanation, the structural schematic diagram of the path planning apparatus embodiment only shows the parts related to the embodiments of the present invention. Those skilled in the art will understand that the illustrated structure does not constitute a limitation on the apparatus, and may include more or fewer components than illustrated, or combine certain components, or have different component arrangements.
[0110] In one embodiment, such as Figure 7 As shown, a path planning device 700 is provided. This device can be a software module, a hardware module, or a combination of both as part of a computer device. Specifically, the device includes:
[0111] The path graph reading module 701 is used to read the path graph to be analyzed from memory at one time and extract the road segment feature values carried by each road segment line in the path graph to be analyzed; the path graph to be analyzed is a connection graph composed of multiple nodes and road segment lines connecting the multiple nodes, and the path graph to be analyzed contains at least one path from the target start node to the target end node; the road segment feature values have positive and negative values;
[0112] The feature value acquisition module 702 is used to determine the current road segment line between the current starting node and each current ending node, and to acquire the road segment feature value of the current road segment line; the current ending node is a node that has a connection relationship with the current starting node;
[0113] The minimum feature value determination module 703 is used to determine the connection path feature value from the target starting node to the current ending node based on the road segment feature value of the current road segment line, and to determine the minimum connection path feature value among the connection path feature values;
[0114] The shortest path determination module 704 is used to determine the target shortest path based on the path corresponding to the feature value of the minimum connecting path if the current end node corresponding to the feature value of the minimum connecting path is the target end node, and output the target shortest path.
[0115] In the aforementioned path planning device, the following steps are taken: First, the device reads the path map to be analyzed and extracts the segment feature values carried by each road segment line. Second, it determines the current road segment lines between the current starting node and each current ending node, and obtains the segment feature values of these current road segment lines. Third, based on the segment feature values of the current road segment lines, it determines the characteristic values of the connecting path from the target starting node to the current ending node, and identifies the minimum connecting path characteristic value among these. Fourth, if the current ending node corresponding to the minimum connecting path characteristic value is the target ending node, it determines the target shortest path based on the path corresponding to the minimum connecting path characteristic value and outputs the target shortest path. Even with both positive and negative road segment feature values, the shortest path can be efficiently determined with minimal space overhead.
[0116] In an optional embodiment, the apparatus further includes: a first multi-branch tree construction module, configured to construct a multi-branch tree with the current ending node as a child node of the root node if the current starting node is the root node; a second multi-branch tree construction module, configured to construct a multi-branch tree with the current starting node as a child node of the previous node and the current ending node as a child node of the current starting node if the current starting node is not the root node; correspondingly, the minimum feature value determination module is further configured to determine the sum of the feature values of each segment from the root node to the current ending node, thereby obtaining the feature value of the connecting path from the target starting node to the current ending node.
[0117] In an optional embodiment, the shortest path determination module includes: a first shortest path determination submodule, configured to determine the path corresponding to the minimum connecting path feature value as the target shortest path if the path graph to be analyzed contains only positive road segment feature values, or if the path graph to be analyzed contains negative road segment feature values and a relative shortest path needs to be output; and a second shortest path determination submodule, configured to determine whether the current end node corresponding to the minimum connecting path feature value has child nodes if the path graph to be analyzed contains negative road segment feature values and an absolute shortest path needs to be output, and to determine the target shortest path based on the determination result.
[0118] In an optional embodiment, the second shortest path determination submodule includes: a child node existence unit, configured to, if it is determined that the current end node has child nodes, take the current end node corresponding to the minimum connected path feature value as the current starting node and continue to determine the minimum connected path feature value until there are no child nodes in the current end node; and a child node non-existence unit, configured to, if it is determined that the current end node has no child nodes, determine the path corresponding to the minimum connected path feature value as the target shortest path.
[0119] In an optional embodiment, the minimum feature value determination module is further configured to determine the sum of the absolute values of each segment feature value from the root node to the current end node if there are negative segment feature values in the path graph to be analyzed and the calculation mode is a positive segment feature value calculation mode, so as to obtain the connection path feature value from the target starting node to the current end node.
[0120] In an optional embodiment, after each construction or adjustment of the multi-way tree, the method further includes: a path deletion module, which is used to determine the path feature values of the connecting paths from the root node to these leaf nodes if there are at least two identical leaf nodes in the constructed or adjusted multi-way tree, and retain only the path with the smallest connecting path feature value in the multi-way tree.
[0121] In an optional embodiment, if negative road segment feature values exist in the path graph to be analyzed, the device further includes: for any leaf node, taking it as a target leaf node; a parent node determination module, used to determine whether there is a target parent node with the same content as the target leaf node in the remaining paths of the multi-way tree; a feature value determination module, used to determine the connecting path feature values of the paths from the root node to the target leaf node and to the target parent node respectively, if they exist; and a child node moving module, used to move all child nodes under the target parent node as child nodes of the target leaf node if the connecting path feature value corresponding to the target parent node is longer than the connecting path feature value corresponding to the target leaf node.
[0122] For specific limitations regarding the path planning device, please refer to the limitations of the path planning method above, which will not be repeated here. Each module in the aforementioned path planning device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in or independent of the processor in a computer device in hardware form, or stored in the memory of a computer device in software form, so that the processor can call and execute the operations corresponding to each module.
[0123] In one embodiment, a computer device is provided, which may be a terminal, and its internal structure diagram may be as follows: Figure 8 As shown, the computer device includes a processor, memory, communication interface, display screen, and input devices connected via a system bus. The processor provides computing and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system and computer programs. The internal memory provides an environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The communication interface is used for wired or wireless communication with external terminals; wireless communication can be achieved through Wi-Fi, carrier networks, NFC (Near Field Communication), or other technologies. When executed by the processor, the computer program implements a path planning method. The display screen can be an LCD screen or an e-ink screen. The input devices can be a touch layer covering the display screen, buttons, a trackball, or a touchpad on the computer device's casing, or an external keyboard, touchpad, or mouse.
[0124] Those skilled in the art will understand that Figure 8 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0125] In one embodiment, a computer device is also provided, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps in the above method embodiments.
[0126] In one embodiment, a computer-readable storage medium is provided storing a computer program that, when executed by a processor, implements the steps in the above method embodiments.
[0127] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the methods described above. Any references to memory, storage, databases, or other media used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, or optical storage, etc. Volatile memory can include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM), etc.
[0128] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0129] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are relatively specific and detailed, they should not be construed as limiting the scope of the invention patent. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this patent application should be determined by the appended claims.
Claims
1. A path planning method, characterized in that, The method includes: The path graph to be analyzed is read from memory at once, and the road segment feature values carried by each road segment line in the path graph to be analyzed are extracted; the path graph to be analyzed is a connection graph composed of multiple nodes and road segment lines connecting the multiple nodes, and the path graph to be analyzed contains at least one path from the target start node to the target end node; the road segment feature values have positive and negative values; Determine the current road segment line between the current starting node and each current ending node, and obtain the road segment feature value of the current road segment line; the current ending node is a node that has a connection relationship with the current starting node; Based on the segment feature value of the current road segment, determine the connection path feature value from the target starting node to the current ending node, and determine the minimum connection path feature value among the connection path feature values; If the current end node corresponding to the minimum connection path feature value is the target end node, then the target shortest path is determined according to the path corresponding to the minimum connection path feature value, and the target shortest path is output. If the current end node corresponding to the feature value of the minimum connection path is the target end node, then determining the target shortest path based on the path corresponding to the feature value of the minimum connection path includes: If the path to be analyzed contains only positive road segment feature values, or if the path to be analyzed contains negative road segment feature values and the shortest relative path needs to be output, then the path corresponding to the minimum connecting path feature value is determined as the target shortest path. If the path graph to be analyzed contains negative road segment feature values and the absolute shortest path needs to be output, then it is determined whether the current end node corresponding to the minimum connecting path feature value has child nodes, and the target shortest path is determined based on the judgment result.
2. The method according to claim 1, characterized in that, After determining the current road segment line between the current starting node and each current ending node, and obtaining the road segment feature value of the current road segment line, the method further includes: If the current starting node is the root node, then a multi-way tree is constructed with the current ending node as a child node of the root node; If the current starting node is not the root node, then the current starting node is taken as the child node of the previous node, and the current ending node is taken as the child node of the current starting node to construct a multi-way tree. Accordingly, determining the connection path feature value from the target starting node to the current ending node based on the road segment feature value of the current road segment includes: The sum of the feature values of each segment from the root node to the current end node is determined to obtain the feature value of the connecting path from the target starting node to the current end node.
3. The method according to claim 1, characterized in that, The step of determining whether the current end node corresponding to the feature value of the minimum connection path has child nodes, and determining the target shortest path based on the determination result, includes: If it is determined that the current end node has child nodes, then the current end node corresponding to the minimum connection path feature value is taken as the current start node and the step of determining the minimum connection path feature value continues until there are no child nodes in the current end node. If it is determined that the current end node has no child nodes, then the path corresponding to the minimum connection path feature value is determined as the target shortest path.
4. The method according to claim 2, characterized in that, The step of determining the sum of feature values of each road segment from the root node to the current end node to obtain the feature values of the connecting path from the target starting node to the current end node includes: If the path graph to be analyzed contains negative road segment feature values and the calculation mode is the positive road segment feature value calculation mode, then the sum of the absolute values of each road segment feature value from the root node to the current end node is determined to obtain the connection path feature value from the target starting node to the current end node.
5. The method according to any one of claims 2 to 4, characterized in that, After each construction or adjustment of the multi-way tree, the following is also included: If there are at least two identical leaf nodes in the constructed or adjusted multi-way tree, then determine the path characteristic values of the connecting paths from the root node to these leaf nodes respectively, and retain only the path with the smallest connecting path characteristic value in the multi-way tree.
6. The method according to claim 5, characterized in that, If the path graph to be analyzed contains negative road segment feature values, then after retaining only the path with the smallest connecting path feature value in the multi-way tree, the method further includes: For any leaf node, take it as the target leaf node; Determine whether there exists a target parent node in the remaining paths of the multi-way tree that has the same content as the target leaf node; If they exist, then determine the path feature values of the connecting paths from the root node to the target leaf node and to the target parent node, respectively. If the path feature value corresponding to the target parent node is longer than the path feature value corresponding to the target leaf node, then all child nodes under the target parent node are moved to become child nodes of the target leaf node.
7. A path planning device, characterized in that, The device includes: The path graph reading module is used to read the path graph to be analyzed from memory at one time and extract the road segment feature values carried by each road segment line in the path graph to be analyzed; the path graph to be analyzed is a connection graph composed of multiple nodes and road segment lines connecting the multiple nodes, and the path graph to be analyzed contains at least one path from the target start node to the target end node; the road segment feature values have positive and negative values; The feature value acquisition module is used to determine the current road segment line between the current starting node and each current ending node, and to acquire the road segment feature value of the current road segment line; the current ending node is a node that has a connection relationship with the current starting node; The minimum feature value determination module is used to determine the connection path feature value from the target starting node to the current ending node based on the road segment feature value of the current road segment line, and to determine the minimum connection path feature value among the connection path feature values; The shortest path determination module is used to determine the target shortest path based on the path corresponding to the feature value of the minimum connected path if the current end node corresponding to the feature value of the minimum connected path is the target end node, and output the target shortest path; if the path graph to be analyzed only contains positive road segment feature values, or if the path graph to be analyzed contains negative road segment feature values and a relative shortest path needs to be output, then the path corresponding to the feature value of the minimum connected path is determined as the target shortest path; if the path graph to be analyzed contains negative road segment feature values and an absolute shortest path needs to be output, then it is determined whether the current end node corresponding to the feature value of the minimum connected path has child nodes, and the target shortest path is determined based on the determination result.
8. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1 to 6.
9. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 6.
Citation Information
Patent Citations
Shortest path planning method based on unidirectional searching model
CN108827335A