Shortest path solving method, system and device and storage medium
By combining the Dijkstra algorithm and the bmsLS algorithm, using probability sampling and optimal restart strategies, the optimality problem of solving the shortest path problem of large-scale required point constraints is solved, and efficient and globally optimal path optimization is achieved.
Patent Information
- Application Number
- CN202510129240.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-05
- Publication Date
- 2025-05-30
AI Technical Summary
The prior art is difficult to effectively solve the problem of large-scale point-constrained shortest paths, especially when the optimality of high computational complexity reconciliation cannot be guaranteed.
The Dijkstra algorithm is used to generate the shortest sequence between the necessary points, and the local search algorithm bmsLS of the fusion probability sampling strategy is optimized to find the solution with the smallest total path weight.
It improves the solution efficiency of large-scale point-constrained shortest path problems, ensures the finding of global optimal solutions, and reduces the computational complexity.
Smart Images

Figure CN120069016A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the technical field of shortest path solving, and particularly to a shortest path solving method, system, device and storage medium. Background Art
[0002] The problem of the shortest path with required waypoints has extensive applications in the fields of transportation and logistics. Its solving algorithms can be divided into two categories: exact algorithms and heuristic algorithms. Exact algorithms, such as dynamic programming and integer programming, can find the optimal solution to the problem, but their computational complexity is high and memory consumption is large. Especially in large-scale problems, it often leads to too long solving time and is difficult to meet the requirements of real-time applications. Heuristic algorithms such as greedy algorithms, genetic algorithms, A* algorithms and simulated annealing, improve the computational efficiency by sacrificing global optimality or using heuristic functions. Such algorithms can find approximate optimal solutions in a relatively short time and are suitable for dealing with large-scale problems. However, their disadvantages are that the optimality and convergence of the solutions cannot be guaranteed, they are prone to falling into local optima, and the quality of the solutions may depend on the design of the heuristic function and parameter tuning.
[0003] Therefore, there is currently a lack of a method for solving the shortest path with required waypoints on a large scale, so as to achieve the purpose of improving the solving efficiency of the algorithm. Summary of the Invention
[0004] This application provides a shortest path solving method, system, device and storage medium to solve the above technical problems.
[0005] On the one hand, this application provides a shortest path solving method, and the method includes the following steps:
[0006] Step S1: Use the Dijkstra algorithm to generate the shortest sequence between required waypoints;
[0007] Step S2: Randomly generate an initial solution;
[0008] Step S3: Based on the local search algorithm bmsLS with a fusion probability sampling strategy, search for the optimal solution;
[0009] Step S4: When the bmsLS algorithm falls into a local optimal trap, execute the preference restart strategy to help the bmsLS algorithm escape from the local optimal trap. When the bmsLS algorithm reaches the maximum running time, end the process.
[0010] In an implementation manner of the present application, before the step S1, the method further includes: constructing an undirected graph, and abstracting each node in the area where the path is located as a node in the undirected graph; wherein, the node set includes a starting point, an ending point, and several cells, and the edge set represents the road connections between the nodes, and each edge has a weight, and the weight represents the distance between the nodes; initializing the undirected graph and constructing an adjacency matrix, wherein the adjacency matrix represents the distance between the nodes.
[0011] In an implementation manner of the present application, the step S1 specifically includes:
[0012] Step S11: Initialize the Dijkstra algorithm;
[0013] Step S12: Calculate the Dijkstra algorithm path;
[0014] Step S13: Determine that the termination condition is reached and execute the result output.
[0015] In an implementation manner of the present application, the step S11 is specifically: initializing a distance array and creating a priority queue.
[0016] In an implementation manner of the present application, the step S12 is specifically: selecting the node of the current shortest path, updating the paths of adjacent nodes, and marking the visited nodes.
[0017] In an implementation manner of the present application, the step S13 is specifically: when the priority queue is empty, it means that the shortest paths of all nodes have been found and the algorithm terminates; output the shortest path.
[0018] In an implementation manner of the present application, in the step S4, the optimal restart strategy is specifically: when after multiple iterations, the current solution path_current cannot be further improved, that is, when it falls into a local optimal solution, the bmsLS algorithm introduces an optimal restart strategy to generate a new initial solution, and the bmsLS algorithm starts the next round of search from the new initial solution.
[0019] The present application also provides a shortest path solving system, and the system includes:
[0020] A sequence generation unit, configured to generate the shortest sequence between the necessary points by using the Dijkstra algorithm;
[0021] An initial solution generation unit, configured to randomly generate an initial solution;
[0022] A local search unit, configured to search for the optimal solution based on a local search algorithm of a fusion probability sampling strategy;
[0023] An optimized restart unit is used to execute an optimized restart strategy to help the bmsLS algorithm escape from the local optimal trap. When the algorithm reaches the maximum running time, the process ends.
[0024] The present application also provides a shortest path solving device, which includes:
[0025] At least one processor; and,
[0026] A memory communicatively connected to the at least one processor; wherein,
[0027] The memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can complete the aforementioned shortest path solving method.
[0028] The present application also provides a non-volatile computer storage medium for shortest path solving, which stores computer executable instructions, and the computer executable instructions are executed by a processor to implement the aforementioned shortest path solving method.
[0029] A shortest path solving method, system, device and storage medium provided by the present application simplify the problem scale by applying the Dijkstra algorithm, providing a good foundation for subsequent local search; the bmsLS algorithm further optimizes the path through probability sampling and optimized restart strategy, and finally outputs a solution with the smallest total path weight. This algorithm has broad application prospects in the fields of urban logistics, traffic planning and network communication. BRIEF DESCRIPTION OF THE DRAWINGS
[0030] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation to the present application. In the drawings:
[0031] Figure 1 is a flowchart of a shortest path solving method provided by an embodiment of the present application;
[0032] Figure 2 is a composition diagram of a shortest path solving system provided by an embodiment of the present application;
[0033] Figure 3 is a schematic diagram of a shortest path solving device provided by an embodiment of the present application. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0034] To make the objectives, technical solutions, and advantages of this application clearer, the technical solutions of this application will be clearly and completely described below in conjunction with specific embodiments of this application and the corresponding drawings. Obviously, the described embodiments are only a part of the embodiments of this application, rather than all of the embodiments. All other embodiments obtained by those of ordinary skill in the art based on the embodiments in this application without creative efforts belong to the scope of protection of this application.
[0035] The embodiments of this application provide a shortest path solving method, system, device, and storage medium. The proposed algorithm consists of two algorithm modules, namely the Dijkstra algorithm and the bmsLS algorithm. These two algorithms play different roles when solving large-scale application examples of the must-pass point constrained shortest path problem: The Dijkstra algorithm calculates the shortest paths between must-pass nodes and between must-pass nodes and the starting point and the ending point. On this basis, the bmsLS algorithm is applied to find a sequence of must-pass nodes with the lowest total path weight, thereby effectively solving this problem. The following will describe in detail the solving processes of the two algorithms and the role played by the optimization strategy designed by the present invention for large-scale application examples during the solving process. The technical solutions proposed in the embodiments of this application will be described in detail below with reference to the drawings.
[0036] Figure 1 This is a flowchart of a shortest path solving method provided by an embodiment of this application. As Figure 1 shown, the method mainly includes the following steps:
[0037] First, construct an undirected graph, specifically: (1) Definition of nodes and edges. Each area (starting point, ending point, and community) in the distribution network is abstracted as a node in the undirected graph. The node set V includes the starting point S, the ending point T, and N communities (C1, C2,..., CN). The edge set E represents the road connections between nodes. Each edge (u, v) has a weight w(u, v), which represents the distance from node u to node v. If there is no direct path between two nodes, the weight of the edge is set to ∞ (infinity). (2) Initialize the undirected graph. Construct an adjacency matrix A, where A[i][j] = w(i, j) represents the distance from node i to node j. If there is no direct connection between node i and node j, then A[i][j] = ∞.
[0038] Further, initialize the Dijkstra algorithm as follows: (1) Initialize the distance array. Create an array d[] of length N + 2 to record the shortest path lengths from the starting point S to each node. The initial settings are as follows: d[S] = 0 (the distance from the starting point to itself is 0). For other nodes v ≠ S, initialize d[v] = ∞ (unknown path initially). (2) Create a priority queue. Use a min-heap (priority queue) data structure to dynamically select the node with the minimum distance. Initially, add the starting point S and its distance d[S] = 0 to the priority queue.
[0039] Further, the path calculation of the Dijkstra algorithm is as follows: (1) Select the node with the current shortest path. Take out the node u with the minimum distance from the priority queue as the current node. If the node u has been visited, skip this node. If the node u = T (the termination point), the algorithm can be terminated early, and the shortest path is output. (2) Update the paths of adjacent nodes. Obtain the set of all adjacent nodes {v 1 , v 2 ,..., v k} of the node u, traverse each adjacent node v, and calculate the new distance from the starting point S to the node v: new distance = d(u) + w(u, v). If the new distance is less than the currently known shortest path d(v), perform the following operations: update d(v) = d(u) + w(u, v), and add the node v and its new distance to the priority queue for subsequent calculations. (3) Mark the visited nodes. Mark the node u as visited to ensure that it will not be processed repeatedly. Repeat steps (1) and (2) until the priority queue is empty, that is, all nodes have been processed.
[0040] Further, the termination condition and result output are as follows: (1) Algorithm termination. When the priority queue is empty, it means that the shortest paths of all nodes have been found, and the algorithm terminates. If the shortest path of the termination point T has been found during the processing, the algorithm can be terminated early. (2) Output the shortest path. Output the shortest path lengths d[i] from the starting point S to the termination point T and all cells Ci. At the same time, record the path information between each node for subsequent queries.
[0041] The Dijkstra algorithm can efficiently calculate the shortest path from the initial node S to the terminal node T. In the algorithm implementation, this application uses a priority queue to accelerate the path calculation, which can significantly improve the computational efficiency of the algorithm and reduce the calculation time. The present invention uses the Dijkstra algorithm to calculate the shortest paths of the combination of necessary nodes, the starting point and all combinations of necessary points, and the terminal point and all combinations of necessary points, providing a calculation basis for the bmsLS algorithm to solve the problem of the shortest path with necessary point constraints. The bmsLS algorithm ensures finding the globally optimal path under the necessary point constraints through two core optimization strategies. The first is the BMS (Best from Multiple Selections) strategy. When selecting neighbor nodes, the bmsLS algorithm does not find a new neighbor solution by traversing all neighbor solution spaces, because traversing in the face of large-scale application instances will cause the time of a single iteration to be too long. In each iteration, the BMS strategy randomly selects several neighbor solutions from all neighbor solutions, and then selects an optimal neighbor solution from these several neighbor solutions as the new current solution. The second is the optimal restart strategy. When the algorithm falls into a local optimum, the optimal restart strategy does not perturb the current solution that has fallen into the local optimum, but perturbs the optimal solution found during the algorithm search process to obtain a new initial solution as the current solution of the algorithm, and starts a new round of search.
[0042] Furthermore, initialize the path and parameters. Specifically: Input the initially generated path solution path0, where the path starts from the starting point S, passes through all necessary points (P1, P2,..., Pk), and finally reaches the terminal point T. Initialize the current solution pathcurrent = path0, and record the initial solution as the current optimal solution best_solution = path0. Set the maximum running time max_time, and when the algorithm runs to this time, output the optimal solution found.
[0043] Furthermore, perform iterative local search. (1) Select neighbor solutions. Neighbor solutions are solutions generated by adjusting the current path path_current. The adjustment operation is to exchange the order of necessary points. Randomly select two necessary points (Pi, Pj) in the path and exchange their access order. Among all the generated neighbor solutions, instead of trying all solutions one by one, the BMS strategy is adopted. This strategy avoids the exhaustive search of all neighbor solutions, thereby improving the algorithm efficiency and exploring in a larger search space to reduce the possibility of falling into a local optimum solution. (2) Accept the solution. If the path length of the selected neighbor solution is better than the current solution path_current, accept this neighbor solution (path_current = path_neighbor). If the new solution is better than the currently recorded optimal solution, update the optimal solution best_solution = path_current.
[0044] Furthermore, the perturbation processing when falling into the local optimum. Specifically, when after multiple iterations, the current solution path_curren cannot be further improved, that is, when falling into the local optimal solution, the bmsLS algorithm introduces a preference restart strategy to generate a new initial solution, and the bmsLS algorithm starts the next round of search from the new initial solution.
[0045] Furthermore, the termination condition is: when the running time reaches the maximum running time max_time, the bmsLS algorithm ends the operation and outputs the discovered optimal solution.
[0046] To better understand the solution process of the combination of the bmsLS algorithm and the Dijkstra algorithm, this application takes a simplified urban logistics distribution problem as an example for illustration. Assume that this application has an urban logistics distribution network, which includes the following locations: warehouse (starting point S), customer A (mandatory point P1), customer B (mandatory point P2), customer C (mandatory point P3), and finally customer D (ending point T). The roads between each location have different distances, specifically as follows: S→P1 (10 kilometers), S→P2 (15 kilometers), S→P3 (20 kilometers), P1→P2 (8 kilometers), P1→P3 (7 kilometers), P2→P3 (5 kilometers), P2→T (10 kilometers), P3→T (12 kilometers).
[0047] The goal is to find the shortest path starting from the warehouse S, passing through customer A, customer B, and customer C, and finally reaching customer D. First, use the Dijkstra algorithm to calculate the shortest path from S to each mandatory point, the shortest path from each mandatory point to the ending point T, and the shortest path between each mandatory point. The obtained results are as follows: S→P1 (10 kilometers), S→P2 (15 kilometers), S→P3 (20 kilometers), P1→P2 (8 kilometers), P1→P3 (7 kilometers), P2→P3 (5 kilometers), P2→T (10 kilometers), P3→T (12 kilometers).
[0048] Based on these shortest paths, a simplified graph G' is constructed with nodes including S, P1, P2, P3, and T, and the weights of the edges are the above-mentioned path lengths. On this simplified graph G', the bmsLS algorithm starts to search. Suppose the initial path generated by the algorithm is S→P1→P2→P3→T, and the total path length is 10 + 8 + 5 + 12 = 35 kilometers. The algorithm first uses neighborhood search to explore the possibility of improving the current path. During this process, instead of traversing all possible neighbor solutions, the bmsLS algorithm randomly generates multiple neighbor solutions through a probability sampling strategy and quickly selects one of the optimal solutions for update. For example, in one sampling, the algorithm may generate the following three neighbor solutions. Solution 1: S→P1→P3→P2→T, with a total path length of 10 + 7 + 5 + 10 = 32 kilometers. Solution 2: S→P2→P1→P3→T, with a total path length of 15 + 8 + 7 + 12 = 42 kilometers. Solution 3: S→P3→P1→P2→T, with a total path length of 20 + 7 + 8 + 10 = 45 kilometers.
[0049] By evaluating these three solutions, the algorithm finds that Solution 1 has the minimum path length, so it selects Solution 1 as the current solution for update. In this way, the algorithm can efficiently complete an iteration in a short time and maintain the exploration of the solution space. Suppose that in several consecutive iterations, the algorithm does not find a solution better than the current path S→P1→P3→P2→T (32 kilometers). At this time, the algorithm triggers the best-improving restart strategy. The algorithm will select the current optimal solution S→P1→P3→P2→T and perform targeted perturbation on this basis. For example, the algorithm may swap the order of P1 and P3 to generate a new path S→P3→P1→P2→T, with a total path length of 20 + 7 + 8 + 10 = 45 kilometers. Although this new path is not better than the current solution, it creates a new exploration direction through perturbation. Through this purposeful perturbation, the algorithm attempts to jump out of the current local optimal region and enter a new region in the solution space. Subsequently, the bmsLS algorithm continues to perform neighborhood search on the newly generated path in order to find a better path. If the new path does not provide a better solution, the algorithm may choose another perturbation method and continue the search. After multiple iterations and restarts, suppose the algorithm finds a new path S→P2→P1→P3→T, with a total path length of 30 kilometers after a certain perturbation. At this time, the algorithm takes it as the current solution and continues to optimize. If a shorter path is found during neighborhood search, such as S→P2→P3→P1→T, with a total path length of 28 kilometers, the algorithm will update the current solution again.
[0050] In the further optimization process, the algorithm may continuously apply probability sampling strategies and optimal restart strategies to find the global optimal solution. Finally, after the preset termination conditions are met, the algorithm outputs the optimal path currently found. The method combining the Dijkstra algorithm and the bmsLS algorithm can effectively reduce the computational complexity of large-scale graphs. The Dijkstra algorithm first simplifies the problem, reducing the number of nodes and edges that need to be processed, while the bmsLS algorithm optimizes on the simplified graph, making the overall calculation process more efficient.
[0051] The algorithm proposed in this application can efficiently solve large-scale point-constrained shortest path problems. The Dijkstra algorithm is applied to simplify the problem scale, providing a good foundation for subsequent local search; the bmsLS algorithm further optimizes the path through probability sampling and optimal restart strategy, and finally outputs the solution with the minimum total path weight. This algorithm has broad application prospects in urban logistics, transportation planning, network communications and other fields.
[0052] The above is a shortest path solving method provided by an embodiment of the present application. Based on the same inventive concept, an embodiment of the present application also provides a shortest path solving system. Figure 2 A diagram of the composition of a shortest path solving system provided in an embodiment of the present application, such as Figure 2 As shown, the system mainly includes: a sequence generation unit 201, which uses the Dijkstra algorithm to generate the shortest sequence between the necessary points; an initial solution generation unit 202, which is used to randomly generate an initial solution; a local search unit 203, which is used to search for the optimal solution based on the local search algorithm bmsLS based on the fusion probability sampling strategy; a preferential restart unit 204, which is used to execute the preferential restart strategy to help the bmsLS algorithm escape from the local optimal trap, and end the process when the algorithm reaches the maximum running time.
[0053] The above is a shortest path solving system provided by an embodiment of the present application. Based on the same inventive concept, an embodiment of the present application also provides a shortest path solving device. Figure 3 A schematic diagram of a shortest path solving device provided in an embodiment of the present application is shown as follows: Figure 3 As shown, the device mainly includes: at least one processor 301; and a memory 302 communicatively connected to the at least one processor; wherein the memory 302 stores instructions that can be executed by the at least one processor 301, and the instructions are executed by the at least one processor 301 so that the at least one processor 301 can complete the aforementioned shortest path solving method.
[0054] In addition, an embodiment of the present application also provides a non-volatile computer storage medium for solving the shortest path, storing computer-executable instructions, and the computer-executable instructions are executed by a processor to implement the foregoing method for solving the shortest path.
[0055] The present invention is described with reference to the flowcharts and / or block diagrams of methods, apparatuses (systems), and computer program products according to embodiments of the present invention. It should be understood that each flow and / or block in the flowcharts and / or block diagrams, and the combination of flows and / or blocks in the flowcharts and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to the processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing devices to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing devices generate a machine for implementing the function specified in one Figure 1 flow or multiple flows and / or blocks Figure 1 or a device for the function specified in multiple blocks.
[0056] These computer program instructions can also be stored in a computer-readable memory that can direct a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer-readable memory generate a manufactured article including an instruction device, and the instruction device implements the function specified in one Figure 1 flow or multiple flows and / or blocks Figure 1 or a device for the function specified in multiple blocks.
[0057] These computer program instructions can also be loaded onto a computer or other programmable data processing device, so that a series of operation steps are executed on the computer or other programmable device to generate a computer-implemented process, and thus the instructions executed on the computer or other programmable device provide steps for implementing the function specified in one Figure 1 flow or multiple flows and / or blocks Figure 1 or a device for the function specified in multiple blocks.
[0058] In a typical configuration, a computing device includes one or more processors (CPUs), an input / output interface, a network interface, and a memory.
[0059] Each embodiment in the present application is described in a progressive manner. The same or similar parts among the embodiments can be referred to each other, and the differences between each embodiment and other embodiments are emphasized. In particular, for the apparatus embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can refer to the partial description of the method embodiment.
[0060] It should also be noted that the term "comprise", "include" or any other variant thereof is intended to cover non-exclusive inclusion, such that a process, method, commodity or device comprising a series of elements not only includes those elements but also includes other elements not expressly listed, or further includes elements inherent to such process, method, commodity or device. Without further limitation, an element defined by the phrase "comprising an..." does not exclude the presence of additional identical elements in the process, method, commodity or device comprising said element.
[0061] The above are only examples of the present application and are not intended to limit the present application. For those skilled in the art, various changes and modifications can be made to the present application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included within the scope of the claims of the present application.
Claims
1. A shortest path solving method, characterized in that: The method comprises the following steps: Step S1: Generate the shortest sequence between the necessary points using Dijkstra algorithm; Step S2: randomly generate an initial solution; Step S3: Searching for the optimal solution using the local search algorithm bmsLS algorithm that integrates the probability sampling strategy; Step S4: When the bmsLS algorithm falls into a local optimal trap, the optimal restart strategy is executed, and the process ends when the algorithm reaches the maximum running time.
2. A shortest path solving method according to claim 1, characterized in that: Before step S1, the method further includes: constructing an undirected graph, abstracting each node in the path area as a node in the undirected graph; wherein the node set includes a starting point, an end point and a number of cells, and the edge set represents the road connection between the nodes, and each edge has a weight, and the weight represents the distance from node to node; initializing the undirected graph, and constructing an adjacency matrix, wherein the adjacency matrix represents the distance from node to node.
3. A shortest path solving method according to claim 1, characterized in that: The step S1 specifically includes: Step S11: Initialize Dijkstra algorithm; Step S12: Calculate the Dijkstra algorithm path; Step S13: Determine that the termination condition is met and output the execution result.
4. A shortest path solving method according to claim 3, characterized in that: The step S11 specifically includes: initializing the distance array and creating a priority queue.
5. A shortest path solving method according to claim 3, characterized in that: The step S12 specifically includes: selecting a node of the current shortest path, updating the paths of adjacent nodes, and marking the visited nodes.
6. A shortest path solving method according to claim 3, characterized in that: The step S13 is specifically as follows: when the priority queue is empty, it means that the shortest paths of all nodes have been found, and the algorithm terminates; and the shortest path is output.
7. A shortest path solving method according to claim 1, characterized in that: In step S4, the optimal restart strategy is specifically: when the current solution path_curren cannot be further improved after multiple iterations, that is, it falls into a local optimal solution, the bmsLS algorithm introduces the optimal restart strategy to generate a new initial solution, and the bmsLS algorithm starts the next round of search from the new initial solution.
8. A shortest path solving system, characterized in that: The system comprises: A sequence generation unit, used to generate the shortest sequence between the necessary points based on the fusion algorithm of Dijkstra and bmsLS local search; An initial solution generating unit, used for randomly generating an initial solution; A local search unit is used to execute a local search algorithm based on a fusion probability sampling strategy to avoid being trapped in a local optimal solution; The optimal restart unit is used to execute the optimal restart strategy and end the process after reaching the maximum running time.
9. A shortest path solving device, characterized in that: The device comprises: at least one processor; and, a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can complete the shortest path solving method described in any one of claims 1-7.
10. A non-volatile computer storage medium for solving a shortest path, storing computer executable instructions, characterized in that: The computer executable instructions are executed by a processor to implement a shortest path solving method as described in any one of claims 1-7.