A multi-source shortest path method based on bidirectional spfa
By selecting the node with the largest in-degree as the starting point for preprocessing, constructing a bidirectional graph and optimizing the node scheduling queue, the problem of low efficiency in multi-source shortest path calculation in large-scale graphs is solved, and high-efficiency querying and compatibility with negative weight edges are achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- HANGZHOU DIANZI UNIV
- Filing Date
- 2026-03-05
- Publication Date
- 2026-07-10
AI Technical Summary
Existing multi-source shortest path algorithms are computationally inefficient in large-scale graphs, struggle to handle negative weight edges, and fail to fully utilize preprocessed information, resulting in resource waste and high computational complexity.
A multi-source shortest path method based on bidirectional SPFA is adopted. By selecting the node with the largest in-degree as the starting point of preprocessing, a bidirectional graph is constructed and the node scheduling queue is optimized. The preprocessing information is used for dynamic optimization, and the query efficiency is improved by combining the estimation function array.
It significantly improves the efficiency of multi-source queries on large-scale graphs, reduces the number of invalid node processing operations, increases query efficiency by more than 40%, is compatible with graph structures with negative weight edges, reduces time complexity, and maintains stability.
Smart Images

Figure CN122364565A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of path optimization technology, and in particular to a multi-source shortest path method based on bidirectional SPFA. Background Technology
[0002] The multi-source shortest path algorithm is a core technology in the field of graph theory and network optimization. Its core objective is to calculate the shortest path from all source vertices to the remaining vertices in a weighted graph containing multiple source vertices. It is widely used in scenarios such as traffic route planning, logistics distribution scheduling, and communication network routing optimization. These practical scenarios have rigid requirements for the algorithm's computational efficiency, large-scale graph adaptability, and ability to handle negative edge weights.
[0003] Current mainstream methods for finding the shortest path between multiple sources revolve around improvements to classic algorithms: Multi-source extension methods based on Dijkstra's algorithm initially include all source vertices in a priority queue and use a greedy strategy to update the distances between adjacent vertices, achieving high accuracy in non-negative weighted graphs; the Floyd-Warshall algorithm, based on dynamic programming, directly calculates the shortest path between any two vertices through a triple loop, resulting in concise logic; and the SPFA-based loop method introduces queue optimization on top of the Bellman-Ford algorithm, performing SPFA calculations individually for each source vertex, suitable for graphs containing negative weighted edges (non-negative weighted cycles). Some methods also incorporate preprocessing, bidirectional search, and other optimization strategies to reduce computational complexity in large-scale graph scenarios.
[0004] Existing methods still have significant shortcomings and are difficult to adapt to the needs of large-scale, dynamic multi-source path queries: First, there is a contradiction between computational efficiency and adaptability to large-scale graphs. The Floyd-Warshall algorithm has a time complexity of O(n³), which is too time-consuming in large-scale graphs. The Dijkstra algorithm extension cannot handle negative weight edges, and the traditional SPFA loop-call method is close to brute-force computation in efficiency when source nodes are dense. Second, preprocessing information is not fully utilized. Existing preprocessing techniques are mostly adapted to algorithms such as Dijkstra, and their optimization value for SPFA algorithm queue scheduling has not been fully explored, resulting in wasted resources. Third, it is difficult to balance negative weight edge handling with stability. The Dijkstra algorithm is completely unable to handle negative weight edges, the Bellman-Ford algorithm is extremely inefficient, and the traditional SPFA lacks a targeted queue scheduling strategy, resulting in slow convergence speed. Industry-wide improvements such as layered graph optimization and parallel computing either have poor universality or high deployment costs and have failed to fundamentally solve the problem. Summary of the Invention
[0005] This invention addresses the inefficiency of multiple queries in large-scale graphs during shortest path computation by proposing a multi-source shortest path method based on bidirectional SPFA to solve the aforementioned efficiency problem. This method can effectively handle directed graphs containing negative weight edges but without negative weight cycles, and is suitable for efficient shortest path computation in traffic network graphs under large-scale network environments.
[0006] A multi-source shortest path method based on bidirectional SPFA includes the following steps:
[0007] S1. Construct a directed weighted graph based on the obtained traffic network map; obtain multi-source shortest path query requests;
[0008] S2. Select a specific node as the preprocessing starting point, use the shortest path algorithm to calculate the shortest distance from the preprocessing starting point to all other nodes, and construct and initialize the evaluation function array.
[0009] S3. For each shortest path query request, clear the node scheduling queue used to store nodes to be processed and reset each auxiliary array; dynamically optimize the node scheduling queue based on the evaluation function array, and calculate the shortest distance using the shortest path fast algorithm.
[0010] S4. Iterate through all shortest path query requests and return the query results.
[0011] Preferably, S1 includes:
[0012] S11. Read the number of nodes, number of directed edges, edge weights, multi-source shortest path query requests and number of queries in the traffic network graph;
[0013] S12. Construct a forward adjacency list and a reverse adjacency list based on the traffic network map; initialize the header array of the adjacency list used to store the index of the first edge corresponding to each node; initialize the edge array used to store the endpoint, weight, and index of the next edge.
[0014] Preferably, S2 includes:
[0015] S21. Select the preprocessing starting point;
[0016] S22. Use the shortest path fast algorithm to calculate the shortest distance from the preprocessed starting point to all nodes on the reverse graph, and save the shortest distance to the shortest distance array of the reverse graph.
[0017] S23. Assign all element values of the shortest distance array of the reverse graph to the evaluation function array one by one.
[0018] As a preferred option, the node with the largest in-degree or a fixed node is selected as the starting point for preprocessing.
[0019] Preferably, in S3, the auxiliary array includes a node enqueue marker array vis for marking whether a node is already in the queue, a shortest distance storage array dp for storing the current shortest distance from each node to the source node during the query process, and a node enqueue count statistics array du for detecting negative weight cycles and recording the number of times a node is enqueued.
[0020] Preferably, S3 includes:
[0021] S31. Set the node enqueue marker array vis to 0, the node enqueue count array du to 0, and the shortest distance storage array dp to infinity INF=1e9.
[0022] Enqueue the node starting point of the query into the scheduling queue; set the node enqueue flag of the node starting point of the query to 1 and the shortest distance storage to 0.
[0023] As a preferred option, S3 also includes S32:
[0024] The first loop dynamically optimizes the node scheduling queue based on the evaluation function array, including:
[0025] Pop the current node that is the head of the queue and increment the current node's enqueue count by 1; if the current node's enqueue count is less than the total number of nodes, there is no negative weight cycle and execution continues; otherwise, return -1, indicating that a negative cycle exists.
[0026] Traverse the adjacent edges of the current node. If the shortest distance storage of the adjacent node is greater than the sum of the shortest distance storage of the current node and the weight of the adjacent edge, then update the shortest distance storage of the adjacent node to the weight of the adjacent edge.
[0027] If the neighboring node is not in the node scheduling queue, compare the value of the neighboring node's evaluation function with the value of the current node's evaluation function. If the value of the neighboring node's evaluation function is smaller, insert the neighboring node at the head of the node scheduling queue; otherwise, insert it at the tail of the queue.
[0028] In subsequent iterations, nodes with smaller evaluation function values are processed first, according to the optimized node scheduling queue order, and the shortest distance is updated step by step until the algorithm converges to the endpoint 1.
[0029] As a preferred option, S4 also includes:
[0030] Determine whether all shortest path query requests have been processed. If there are any unprocessed queries, repeat step S3 until all are completed.
[0031] Compared with the prior art, the beneficial effects of the present invention are reflected in:
[0032] 1. Unlike traditional technologies that randomly select or fix a single node as the starting point for preprocessing and have poor coverage of preprocessed information, this invention adopts a technology based on graph structure features to select the node with the largest in-degree as the starting point for preprocessing (the main invention point). This allows the distance information obtained from preprocessing to cover the entire graph structure to the greatest extent, providing more valuable auxiliary basis for subsequent queries, laying the foundation for efficient queries, and increasing the reuse rate of preprocessed information by more than 40%.
[0033] 2. Unlike traditional SPFA algorithms that use a fixed queue order, have slow convergence speed, and do not fully utilize preprocessing information, this invention adopts a combined technical solution of bidirectional graph construction, preprocessing information sharing, and dynamic optimization of the queue head and tail (a secondary inventive point). This reduces the number of invalid node processing times by 40% when handling large-scale graph multi-source queries, and improves the efficiency of a single query by more than 63.8% compared to traditional SPFA. At the same time, it is compatible with graph structures with negative weight edges and can still maintain stability and efficiency in dynamic graph scenarios without repeating the preprocessing process. Attached Figure Description
[0034] Figure 1 This is a flowchart of the method in Embodiment 1 of the present invention. Detailed Implementation
[0035] To make the technical means, inventive features, objectives, and effects of the invention readily understandable, the invention is further described below with reference to specific illustrations. However, the invention is not limited to the embodiments described below.
[0036] It should be noted that the structures, proportions, sizes, etc., illustrated in the accompanying drawings of this specification are only used to complement the content disclosed in the specification for those skilled in the art to understand and read, and are not intended to limit the conditions under which the present invention can be implemented. Therefore, they have no substantial technical significance. Any modifications to the structure, changes in the proportions, or adjustments to the size, without affecting the effects and objectives that the present invention can produce, should still fall within the scope of the technical content disclosed in the present invention.
[0037] This invention first proposes a method for selecting the preprocessing starting point using graph structure features. This method selects the node with the largest in-degree as the preprocessing starting point, obtaining the most representative distance information for the overall graph structure, providing effective preprocessing support for subsequent shortest path queries. Then, by constructing a bidirectional graph structure and a preprocessing strategy, this paper allows multiple shortest path queries to share preprocessing information. This enables the algorithm to fully utilize graph structure features and improve query efficiency. Finally, by introducing a queue head-tail optimization strategy, the SPFA algorithm (Shortest Path Algorithm) can converge faster, thereby further improving query performance. This algorithm supports negative edge processing, significantly improving the efficiency of multiple queries on large-scale graphs while ensuring correctness. The final shortest path query algorithm achieves high query efficiency on large-scale graphs. This method not only solves the problem of low efficiency in multiple queries on large-scale graphs but also avoids redundant computation, reduces time complexity, and maintains good adaptability to graph structures with negative edge weights.
[0038] Example 1:
[0039] like Figure 1 The multi-source shortest path method based on bidirectional SPFA, as shown, includes the following steps:
[0040] S1. Construct a directed weighted graph based on the obtained traffic network map; obtain multi-source shortest path query requests;
[0041] S11. Read the number of nodes in the traffic network map. n Number of edges m and number of queries q;
[0042] In this embodiment, the traffic network diagram contains multiple nodes (corresponding to intersections in the traffic network) and multiple directed edges (corresponding to one-way traffic segments). The edge weight is the travel time of the segment (unit: minutes). Negative weight edges correspond to dedicated traffic diversion channels for specific segments during peak hours, with shorter travel times than regular segments, and are thus represented by negative weights. Multiple sets of multi-source shortest path query requests need to be processed. Taking node 25 as the source point, the objective is to query the shortest travel time from the source point to the other 24 nodes.
[0043] S12. Construct the forward adjacency list and the reverse adjacency list;
[0044] Read the number of nodes n=25, the number of edges m=60, and the number of queries q=3 in the graph. For each directed edge (u,v,w), add an edge from u to v with weight w in the forward graph. For example, edge (3,4,8) indicates that the travel time from node 3 to node 4 is 8 minutes, and edge (12,11,-3) indicates that the travel time from node 12 to node 11 is shortened by 3 minutes. Add an edge from v to u with weight w unchanged in the reverse graph, such as edge (4,3,8) and edge (11,12,-3). At the same time, initialize the head array of the adjacency list, which stores the index of the first edge corresponding to each node, and initialize the edge array edge, which stores the endpoint, weight, and index of the next edge.
[0045] S2. Select a specific node as the preprocessing starting point, use the SPFA algorithm (shortest path algorithm) to calculate the shortest distance from the preprocessing starting point to all other nodes, and construct and initialize the evaluation function array;
[0046] S21. Select the node with the largest in-degree or a fixed node as the starting point for preprocessing.
[0047] S22. Run the basic SPFA algorithm on the reverse graph to calculate the shortest distance from the starting point to all nodes.
[0048] Run the basic SPFA algorithm starting from node 1 on the reverse graph, traverse the reverse adjacency list to calculate the shortest distance from node 1 to all nodes. For example, the shortest distance from node 1 to node 3 in the reverse graph is 22 (corresponding to the estimated shortest distance from node 3 to node 1 in the forward graph). Save these distance data to the shortest distance array a.dp (shortest distance storage array of the reverse graph) corresponding to the reverse graph a.
[0049] S23. Save the shortest distance array as an array of evaluation functions.
[0050] The initialization of the evaluation function array dp1 (query optimization auxiliary array) is achieved by calling the initialization function b.init() (forward graph query parameter initialization function). The assignment code dp1[i] = a.dp[i] (where i is the node number, ranging from 1 to n, and n is the total number of nodes in the graph) is executed. All element values from the preprocessed shortest distance array a.dp of the reverse graph are assigned to the evaluation function array dp1 one by one, completing the initialization. This step provides the core basis for subsequent query queue optimization, and selecting the node with the largest in-degree as the starting point of preprocessing obtains the most representative distance information for the overall graph structure. This is an innovative design of this invention that distinguishes it from traditional technologies.
[0051] S3. For the shortest path query request, clear the node scheduling queue Q used to store the nodes to be processed and reset each auxiliary array, and calculate the shortest distance based on the SPFA algorithm.
[0052] S31. Clear the node scheduling queue Q used to store nodes to be processed and reset each auxiliary array; enqueue the node scheduling queue Q of the query starting point, and mark the node of the query starting point as 1 and the shortest distance as 0.
[0053] Clear queue Q; reset all auxiliary arrays, including the node enqueue marker array vis, the shortest distance storage array dp, and the node enqueue count array du. The node enqueue marker vis is set to 0 to indicate whether a node is already in the queue (0 for not enqueued, 1 for enqueued). The node enqueue count array du is set to 0 to detect negative weight cycles and record the number of times a node has been enqueued. The shortest distance storage array dp is set to infinity (INF=1e9) to store the current shortest distance from each node to the source node during the query process.
[0054] Set the query starting point s, let the shortest distance storage dp[s]=0, enqueue the query node s and mark the node enqueue array vis[s]=1; taking the query request of source node 25 as an example, enqueue node 25 and mark the node enqueue array vis
[25] =1, and the shortest distance storage dp
[25] =0.
[0055] S32. Based on the SPFA algorithm, perform iterative calculations to generate the shortest distance, including:
[0056] First cycle:
[0057] Pop the current node that is the head of the queue and increment the current node's enqueue count by 1; if the current node's enqueue count is less than the total number of nodes, there is no negative weight cycle and execution continues; otherwise, return -1, indicating that a negative cycle exists.
[0058] Traverse the adjacent edges of the current node. If the shortest distance storage of the adjacent node is greater than the sum of the shortest distance storage of the current node and the weight of the adjacent edge, then update the shortest distance storage of the adjacent node to the weight of the adjacent edge.
[0059] If the neighboring node is not in the node scheduling queue, compare the value of the neighboring node's evaluation function with the value of the current node's evaluation function. If the value of the neighboring node's evaluation function is smaller, insert the neighboring node at the head of the node scheduling queue; otherwise, insert it at the tail of the queue.
[0060] Subsequent loop:
[0061] Following the queue optimization order, nodes with smaller evaluation function values are processed first, and the shortest distance is updated step by step until the algorithm converges to the endpoint 1. In this process, the dynamic queue adjustment strategy based on the evaluation function is not an existing technology, breaking through the limitations of traditional SPFA which processes nodes in a fixed order.
[0062] By comparing the valuation function value dp1[Q.front()] of the first node in queue Q with the valuation function value of the node to be enqueued, nodes with smaller valuations are prioritized for processing, reducing the number of invalid node processing times by approximately 40% compared to traditional SPFA.
[0063] S4. Output the query results.
[0064] Example 2:
[0065] This embodiment uses a traffic network map as an example for explanation. The scenario contains 25 nodes (corresponding to intersections in the traffic network) and 60 directed edges (corresponding to one-way traffic segments). The edge weights are the travel times of the traffic segments (unit: minutes), including 5 negative-weight edges (corresponding to dedicated traffic diversion lanes for specific road segments during peak hours, with shorter travel times than regular road segments, hence the negative weights). Three sets of multi-source shortest path query requests need to be processed (the source nodes are node 3, node 12, and node 20, and the objective is to query the shortest travel time from each source node to the remaining 24 nodes). Figure 1 The flowchart for the overall implementation scheme of the algorithm is as follows:
[0066] Step 1: First, prepare the experimental environment and basic data. The experimental hardware configuration is an Intel Core i7-12700H processor and 16GB DDR4 memory. The software environment is Python 3.9. An adjacency list storage graph structure is used to reduce space complexity. The node numbers of the traffic network graph are set to 1~25 according to the network topology. Among them, node 3 corresponds to the eastern passenger transport hub of the city, node 12 corresponds to the central business district of the city, and node 20 corresponds to the western logistics park of the city. The edge weight values range from -5 to 20. Negative weight edges are concentrated around node 12 (temporary diversion channels around the business district). In the preprocessing stage, node 12 with the largest in-degree is selected as the starting point for preprocessing (this node connects 8 directed edges, has an in-degree of 6, and is the core hub in the network. The distance information obtained from its preprocessing has the best coverage of the overall network).
[0067] Step 2: Next, perform graph structure construction and preprocessing operations. The first step is to construct forward and reverse adjacency lists. Read the graph's node count n=25, edge count m=60, and query count q=3. For each directed edge (u,v,w), add an edge from u to v with weight w to the forward graph. For example, edge (3,4,8) indicates a travel time of 8 minutes from node 3 to node 4, and edge (12,11,-3) indicates a reduced travel time of 3 minutes from node 12 to node 11 via a bypass route. Add... From v to u, edges with weights w remain unchanged (such as edge (4,3,8) and edge (11,12,-3)). Simultaneously, initialize the adjacency list's head array (stores the index of the first edge corresponding to each node), edge array (stores the endpoint, weight, and index of the next edge), and initialize auxiliary arrays vis (node enqueue marker, initial value 0), dp (shortest distance storage, initial value set to infinity INF=1e9), and du (node enqueue count statistics, initial value 0). The second step performs preprocessing to generate an estimation function. On the reverse graph, starting from node 12, run the basic SPFA algorithm, traversing the reverse adjacency list to calculate the shortest distance from node 12 to all nodes. For example, the shortest distance from node 12 to node 3 in the reverse graph is 22 (corresponding to the estimated shortest distance from node 3 to node 12 in the forward graph). Save all calculation results as an estimation function array dp1[1..25] for subsequent queue optimization.
[0068] Step 3: Then process the multi-source shortest path query requests. Taking the queries of source nodes 3, 12, and 20 as examples, execute the improved SPFA algorithm in sequence. Taking the query of source node 3 (querying the shortest travel time from node 3 to the other 24 nodes) as an example, the first step is to initialize the query parameters, clear the queue Q, reset vis[1..25]=0, du[1..25]=0, dp[1..25]=INF, set dp[3]=0 (the shortest distance from the source node to itself is 0), enqueue node 3 and mark vis[3]=1. The second step is to execute the improved SPFA algorithm. In the first round of loop, the head node 3 is popped out of the queue, and du[3] is incremented to 1 (less than n=25, no risk of negative cycle). The adjacent edges (3,4,8) and (3,7,12) of node 3 are traversed. For the adjacent node 4, it is judged that dp[4]=INF>dp[3]+8=8, and dp[4]=8 is updated. Since node 4 has not been enqueued, its estimated function value dp1[4]=18 is compared with the head node (the current queue is empty, and subsequent enqueued nodes are sorted according to the estimated value), and node 4 is enqueued. For the adjacent node 7, dp[7]=12 is updated and then enqueued. At this time, the queue state is [4,7] (sorted according to dp1 value 18<21). In subsequent loops, the first node (the node with the smallest value of the evaluation function) is popped each time. For example, after popping node 4, its adjacent edges (4,5,5) and (4,8,9) are traversed, and dp[5]=13 and dp[8]=21 are updated. When enqueuing, dp1[5]=15 and dp1[8]=23 are compared, and the queue order is adjusted to [5,7,8]. Nodes closer to the preprocessing starting point 12 are processed first to accelerate convergence. When processing node 11 (adjacent edge (11,12,-3)) with negative weight edges, dp
[12] =dp
[11] +(-3)=10 is updated. Since node 12 has been enqueued, it is determined that the updated value of dp
[12] is smaller, and its position in the queue is adjusted to the front of the queue to ensure that core nodes are processed first. The shortest travel time from node 3 to node 20 is calculated to be 35 (path: 3→4→5→10→15→20, weight sum 8+5+6+12+4=35), and the shortest travel time to node 12 is 10.
[0069] For queries on source nodes 12 and 20, repeat the above steps. When querying source node 12, since the preprocessing starting point is itself, the evaluation function array dp1 directly matches the distance to the source node, resulting in the highest queue optimization efficiency. The shortest travel time from node 12 to node 3 is 18 (path: 12→11→6→5→4→3, weight sum -3+4+2+5+10=18). When querying source node 20, the path from node 20→15→10→5→12 is processed first using the dp1 array, and the shortest travel time from node 20 to node 3 is finally obtained as 42. After all queries are completed, output dp arrays corresponding to the three source points (store the shortest distance from each source point to all nodes) and verify the correctness of the results: by comparing with the shortest path calculated by the brute-force enumeration method, the results of this algorithm are completely consistent, and the average time for a single query is 0.021 seconds, which is 63.8% more efficient than the traditional SPFA loop call method (0.058 seconds), proving that the algorithm has high efficiency and correctness in the scenario of multi-source query of large-scale graphs with negative weight edges.
[0070] Step 4: Finally, the stability and robustness of the algorithm are verified. In the above traffic network graph, a dynamic edge update is simulated (the edge from node 5 to 10 is deleted, and the edge from node 5 to 9 is added (weight 7)). This algorithm does not need to re-perform preprocessing. It only adjusts the queue optimization strategy based on the historical dp1 array. The shortest path from source node 3 to node 20 is updated to 3→4→5→9→14→19→20 (weight sum 8+5+7+8+6+3=37). The query time only increases by 0.003 seconds, which further proves the adaptability of the algorithm in dynamic graph scenarios and can meet the needs of real-time path query in practical applications.
[0071] Example 3:
[0072] A multi-source shortest path generation system based on bidirectional SPFA includes:
[0073] The data acquisition and preprocessing module is used to construct a directed weighted graph based on the acquired traffic network map and to obtain multi-source shortest path query requests.
[0074] The valuation function construction module is used to select a specific node as the preprocessing starting point, use the shortest path fast algorithm to calculate the shortest distance from the preprocessing starting point to all other nodes, and construct and initialize the valuation function array.
[0075] The queue optimization and shortest distance generation module is used to clear the node scheduling queue used to store nodes to be processed and reset each auxiliary array for each shortest path query request; it dynamically optimizes the node scheduling queue based on the evaluation function array and calculates the shortest distance in combination with the shortest path fast algorithm;
[0076] The results generation module is used to iteratively process all shortest path query requests and return the query results.
Claims
1. A multi-source shortest path method based on bidirectional SPFA, characterized in that, Includes the following steps: S1. Construct a directed weighted graph based on the obtained traffic network map; obtain multi-source shortest path query requests; S2. Select a specific node as the preprocessing starting point, use the shortest path algorithm to calculate the shortest distance from the preprocessing starting point to all other nodes, and construct and initialize the evaluation function array. S3. For each shortest path query request, clear the node scheduling queue used to store nodes to be processed and reset each auxiliary array; dynamically optimize the node scheduling queue based on the evaluation function array, and calculate the shortest distance using the shortest path fast algorithm. S4. Iteratively process all shortest path query requests and return the query results.
2. The multi-source shortest path method based on bidirectional SPFA according to claim 1, characterized in that, S1 includes: S11. Read the number of nodes, number of directed edges, edge weights, multi-source shortest path query requests and query count of the traffic network graph; S12. Construct a forward adjacency list and a reverse adjacency list based on the traffic network map; initialize the header array of the adjacency list used to store the index of the first edge corresponding to each node; initialize the edge array used to store the endpoint, weight, and index of the next edge.
3. The multi-source shortest path method based on bidirectional SPFA according to claim 1, characterized in that, S2 include: S21. Select the preprocessing starting point; S22. Use the shortest path fast algorithm to calculate the shortest distance from the preprocessed starting point to all nodes on the reverse graph, and save the shortest distance to the shortest distance array of the reverse graph. S23. Assign all element values of the shortest distance array of the reverse graph to the evaluation function array one by one.
4. The multi-source shortest path method based on bidirectional SPFA according to claim 3, characterized in that, Choose the node with the largest in-degree or a fixed node as the starting point for preprocessing.
5. The multi-source shortest path method based on bidirectional SPFA according to claim 1, characterized in that, In S3, the auxiliary arrays include a node enqueue marker array vis for marking whether a node is already in the queue, a shortest distance storage array dp for storing the current shortest distance from each node to the source node during the query process, and a node enqueue count statistics array du for detecting negative weight cycles and recording the number of times a node is enqueued.
6. The multi-source shortest path method based on bidirectional SPFA according to claim 5, characterized in that, S3 include: S31. Set the node enqueue marker array vis to 0, the node enqueue count array du to 0, and the shortest distance storage array dp to infinity INF=1e9. Enqueue the node starting point of the query into the scheduling queue; set the node enqueue flag of the node starting point of the query to 1 and the shortest distance storage to 0.
7. The multi-source shortest path method based on bidirectional SPFA according to claim 6, characterized in that, S3 also includes S32: The first loop dynamically optimizes the node scheduling queue based on the evaluation function array, including: Pop the current node that is the head of the queue and increment the current node's enqueue count by 1; if the current node's enqueue count is less than the total number of nodes, there is no negative weight cycle and execution continues; otherwise, return -1, indicating that a negative cycle exists. Traverse the adjacent edges of the current node. If the shortest distance storage of the adjacent node is greater than the sum of the shortest distance storage of the current node and the weight of the adjacent edge, then update the shortest distance storage of the adjacent node to the weight of the adjacent edge. If the neighboring node is not in the node scheduling queue, compare the value of the neighboring node's evaluation function with the value of the current node's evaluation function. If the value of the neighboring node's evaluation function is smaller, insert the neighboring node at the head of the node scheduling queue; otherwise, insert it at the tail of the queue. In subsequent iterations, nodes with smaller evaluation function values are processed first, according to the optimized node scheduling queue order, and the shortest distance is updated step by step until the algorithm converges to the endpoint 1.
8. The multi-source shortest path method based on bidirectional SPFA according to claim 1, characterized in that, S4 also includes: Determine whether all shortest path query requests have been processed. If there are any unprocessed queries, repeat step S3 until all are completed.