A parallel graph traversal method for single-source shortest paths
By dividing the graph data into subgraphs and sorting adjacent edges, and using an improved delta stepping algorithm for traversal, the problem of redundant memory access and atomic operations in the parallel SSSP algorithm is solved, and the computational efficiency and performance of graph traversal are improved.
Patent Information
- Application Number
- CN202210521780.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-05-13
- Publication Date
- 2024-09-24
- Estimated Expiration
- 2042-05-13
AI Technical Summary
The existing SSSP algorithm has problems with redundant memory access and atomic operations in parallel graph traversal, resulting in low performance and difficulty in meeting the computing needs of large-scale graph data.
By dividing the graph data into multiple subgraphs, reordering the adjacent edges in each subgraph, and using an improved delta stepping algorithm to traverse, it avoids frequent memory access and judgment of light edges or heavy edges, and directly based on the number of light edges Determine the position of the edge to update.
It significantly improves the computing efficiency of graph traversal, reduces memory access and computing overhead, improves algorithm performance, and solves the performance bottleneck caused by redundant operations and atomic operations.
Smart Images

Figure CN115049103B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of graph computing, specifically to the field of graph data traversal technology, and more specifically to a method for traversing graph data. Background Art
[0002] With the development of the Internet, society has entered an era of explosive data growth, and graph computing, which aims to explore the potential connections and values in graph data (graph), has emerged. Graph data not only contains the information of the unit data (i.e., nodes) itself, but also contains the connections between the data (i.e., edges). Graph traversal algorithms use graph data as input and are widely used in social network analysis, network security analysis, knowledge graphs, autonomous driving, web search, protein structure prediction and other fields. Among them, the Single Source Shortest Path algorithm (SSSP algorithm for short) is a classic and basic graph traversal algorithm used to calculate the shortest path from one node to other nodes in graph data.
[0003] The SSSP algorithm selects a node from the graph data as the root node (or source node) and finds the shortest path distance from the root node to all other nodes. Typical SSSP algorithms include the Dijkstra algorithm (hereinafter referred to as the Dijkstra algorithm) and the Bellman-Ford algorithm (hereinafter referred to as the Bellman-Ford algorithm). Among them, the Dijkstra algorithm only selects one optimal point as the active node in each round and processes it, so there is no redundant update, but it requires multiple rounds of iterations and is not convenient for parallel optimization. The Bellman-Ford algorithm selects multiple points as active nodes in each round, the total number of iterations is small, and each round of iteration can be parallelized, so the overall parallelism is better, but there are more redundant update operations and the processing time may be longer.
[0004] In 2003, Meyer and Sanders proposed the Delta-Stepping algorithm (also known as the Δ-Stepping algorithm), where Δ is an adjustable parameter. By comparing Δ and edge weights, the edges in the graph data can be divided into light edges (hereinafter referred to as light edges) and heavy edges (hereinafter referred to as heavy edges). For graph data where all edge weights are positive integers, when Δ=1, a variant of the Dijkstra algorithm is obtained, and when Δ=∞, a variant of the Bellman-Ford algorithm is obtained. The Δ-Stepping algorithm combines the advantages and disadvantages of the Dijkstra algorithm and the Bellman-Ford algorithm. By setting the Δ value in the range of [1,∞] to balance parallelism and the total number of iterations, algorithms with different processing times and degrees of parallelism can be obtained.
[0005] The core operation of the SSSP algorithm is the relaxation operation, which is to determine whether the data needs to be updated by comparing the existing shortest path distance and the newly calculated distance. If necessary, it will be updated; otherwise, no operation will be performed.
[0006] For graph data partitioning, the current main method is node-based partitioning, and most of them are partitioned according to the source nodes of the edges. In a shared memory multi-threaded programming environment, the nodes and all their outgoing edges are divided into the same thread. Unlike the breadth-first search (BFS) in which each node updates the access status at most once, the shortest path distance of the same node in the SSSP algorithm may be updated multiple times. During the execution of the parallel SSSP algorithm based on shared memory, there may be multiple threads where the source nodes are located that update the same destination node data unit at the same time. In this case, in order to ensure the correct result, atomic operations need to be used, and the traditional solution is to use critical sections or locks to ensure that only one thread operates the data unit at the same time. However, this solution makes this part of the operation unable to play the advantages of multi-threading, becoming the bottleneck of the parallel algorithm, greatly reducing the efficiency of the algorithm, thereby causing the SSSP algorithm to be limited by the atomic problem and poor performance.
[0007] In terms of memory access, the Δ-Stepping algorithm divides all nodes into different buckets according to the distance from the root node to other nodes, and processes each bucket in order of distance. The processing of each bucket is divided into two stages. The first stage is to relax the light edges of all active nodes in the current bucket, and the second stage is to relax the heavy edges of all nodes processed in the first stage. Among them, the operation of relaxing light adjacent edges is the most time-consuming, because for each active node in the current bucket, it is necessary to determine whether all its adjacent edges are light edges (each time, the weight of the corresponding adjacent edge is accessed and compared with the delta parameter Δ, and the adjacent edge with a weight less than Δ is a light edge, otherwise it is a heavy edge), and new active nodes may also be generated in this stage and fall into the current bucket, which involves a lot of redundant memory access and judgment. For the second stage of processing, it is necessary to first determine whether the adjacent edges of all nodes processed in the first stage are heavy edges, which also involves a lot of redundant memory access.
[0008] In practical applications, the SSSP algorithm has strong data dependence, low computational memory access ratio, poor parallel efficiency, and many redundant operations, making it difficult to achieve good performance. As the scale of graph data continues to grow, the traditional serial SSSP algorithm is no longer sufficient to meet the increasing performance requirements, and the existing parallel Δ-Stepping algorithm has a large number of redundant memory accesses and atomic operations, which affects the performance of the SSSP parallel algorithm and has poor scalability.
[0009] Therefore, it is necessary to improve the existing technology to solve the problem overhead of redundant memory access and atomic operations, further improve the efficiency of graph computing, and improve the performance of graph traversal algorithms to save computing resources and reduce energy consumption. Summary of the invention
[0010] Therefore, the purpose of the present invention is to overcome the defects of the above-mentioned prior art and provide a method for traversing graph data.
[0011] The objective of the present invention is achieved through the following technical solutions:
[0012] According to a first aspect of the present invention, a method for traversing graph data is provided, comprising: obtaining graph data to be processed; obtaining the number of threads in a processor, and evenly distributing all nodes recorded in a column array of the graph data to each thread according to the number of threads and the number of nodes in the graph data according to the node number, so as to obtain a plurality of first subgraphs; for each first subgraph, taking each node recorded in a row array as a sorting unit, reordering each adjacent edge according to the weight of the adjacent edge of the node, so as to obtain a corresponding second subgraph, and determining the number of light edges of each node recorded in the row array in each second subgraph; performing a graph traversal on the corresponding second subgraph based on an improved delta walking algorithm and a selected root node by each thread, wherein the improved delta walking algorithm determines the position of the light edge or heavy edge of the node in the second subgraph according to the number of light edges of the corresponding node when traversing the light edge or heavy edge of the corresponding node; and obtaining a traversal result of the graph data according to the sub-traversal results of the second subgraphs of all threads, which indicates the shortest path from the selected root node to other nodes and / or the shortest distance corresponding to the shortest path.
[0013] In some embodiments of the present invention, compared to the original delta walking algorithm, the improved delta walking algorithm no longer determines whether the neighboring edge of the currently traversed node is a light edge or a heavy edge by comparing the weight of the neighboring edge with the size of the delta parameter each time.
[0014] In some embodiments of the present invention, the nodes in each second subgraph for which the shortest distance to the root node needs to be determined do not overlap with each other; and, compared with the original delta-walking algorithm, the improved delta-walking algorithm no longer performs atomic operations.
[0015] In some embodiments of the present invention, the second subgraph is stored in a compressed sparse matrix row format, which includes: a row array, a column array, and a value array; the row array records the position of the first neighbor node of each node recorded in the row array in the second subgraph in the column array; the column array records the neighbor nodes of each node recorded in the row array in the second subgraph, wherein the neighbor nodes of each node are arranged from small to large according to the weight of the corresponding adjacent edge; the value array records the weight of the adjacent edge of each node.
[0016] In some embodiments of the present invention, the position of the light edge or heavy edge of the node in the second subgraph is determined based on the number of light edges of the node and the position of the first neighbor node of each node in the column array, so as to update the intermediate sub-traversal result by reading the weight in the corresponding value array.
[0017] In some embodiments of the present invention, the preprocessing method includes: removing isolated nodes, renumbering the nodes after the isolated nodes are removed and establishing a mapping relationship between the renumbered numbers and the original numbers, removing duplicate edges with relatively large weights, or a combination thereof.
[0018] In some embodiments of the present invention, the preprocessing method includes: deleting the edge between two directly connected nodes that meets a predetermined deletion condition, wherein the predetermined deletion condition is that the weight of the edge is greater than the sum of the weights of all edges from the two nodes to the nearest neighboring common node.
[0019] According to a second aspect of the present invention, there is provided a method for determining a riding route, comprising: obtaining graph data, wherein nodes represent corresponding bus stops, edges represent roads between corresponding bus stops, and the weight of an edge represents the distance between two nodes connected thereto, wherein the distance is a spatial distance and / or a temporal distance; processing the graph data using the method for traversing graph data described in the first aspect to obtain corresponding traversal results; and querying the traversal results according to a starting station and a destination station input by a user to obtain a corresponding riding route.
[0020] According to a third aspect of the present invention, an electronic device is provided, comprising: one or more processors; and a memory, wherein the memory is used to store executable instructions; the one or more processors are configured to implement the steps of the method described in the first aspect or the second aspect by executing the executable instructions.
[0021] Compared with the prior art, the advantages of the present invention are:
[0022] In order to improve the computational efficiency of graph traversal, after dividing the graph data into multiple first subgraphs, the present invention will use each node as a sorting unit in each first subgraph, reorder each adjacent edge according to the weight of the node's adjacent edge, obtain multiple second subgraphs, and determine the number of light edges of each node in each second subgraph. Subsequently, in each thread, the corresponding second subgraph is traversed based on the improved delta step algorithm and the selected root node, wherein the improved delta step algorithm directly determines the location of the light edge or heavy edge of the node in the second subgraph according to the number of light edges of the corresponding node when traversing the light edge or heavy edge of the corresponding node. In this way, frequent memory access and judgment of whether each adjacent edge is a light edge or a heavy edge can be avoided, a large amount of memory access and computational overhead can be saved, and the computational efficiency of graph traversal is improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] The embodiments of the present invention are further described below with reference to the accompanying drawings, in which:
[0024] Figure 1 A schematic diagram of a flow chart of a method for traversing graph data according to an embodiment of the present invention;
[0025] Figure 2 A schematic diagram of graph data, a corresponding adjacency matrix, and a CSR format according to an example of the present invention;
[0026] Figure 3 A schematic diagram of the principle of data pruning according to an embodiment of the present invention;
[0027] Figure 4 A schematic diagram of allocating a first sub-graph according to an example of the present invention;
[0028] Figure 5 Schematic diagram of the CSR format before and after adjacent edge reordering and determination of the number of light edges according to an example of the present invention. DETAILED DESCRIPTION
[0029] In order to make the purpose, technical solutions and advantages of the present invention more clearly understood, the present invention is further described in detail below through specific embodiments in conjunction with the accompanying drawings. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention.
[0030] As mentioned in the background technology section, the Δ-Stepping algorithm accesses the weight of the corresponding neighbor edge and the delta parameter Δ each time and compares them to determine whether the neighbor edge is a light edge or a heavy edge, which will bring a lot of memory access overhead (reading the weight of the neighbor edge and the delta parameter Δ) and computational overhead (comparing the sizes of the two), which will lead to low computational efficiency of graph traversal, resulting in waste of computing resources and poor user experience. Therefore, in order to improve the computational efficiency of graph traversal, after dividing the graph data into multiple first subgraphs, the present invention will use each node as a sorting unit in each first subgraph, reorder each neighbor edge according to the weight of the node's neighbor edge, obtain multiple second subgraphs, and determine the number of light edges of each node in each second subgraph. Subsequently, in each thread, the corresponding second subgraph is traversed based on the improved delta stepping algorithm and the selected root node, wherein the improved delta stepping algorithm directly determines the location of the light edge or heavy edge of the node in the second subgraph according to the number of light edges of the corresponding node when traversing the light edge or heavy edge of the corresponding node. In this way, frequent memory accesses and judgment of whether each adjacent edge is a light edge or a heavy edge can be avoided, which can save a lot of memory access and computing overhead, thereby improving the computational efficiency of graph traversal.
[0031] First, some of the terms used in the present invention are explained as follows:
[0032] The compressed sparse matrix row format (CSR format) is a format for compressing and storing graph data. The graph data and subgraphs of the present invention are stored in the compressed sparse matrix row format.
[0033] A row array that records the position of the first neighbor node of each node in the graph in the column array.
[0034] The column array records the nodes connected to each node in the row array, that is, the neighbor nodes of each node in the row array.
[0035] The value array records the weight of the edge connecting each node in the row array with the corresponding node in the column array. That is, the weight of the adjacent edge of each node in the row array.
[0036] According to one embodiment of the present invention, a method for traversing graph data is provided, such as Figure 1 As shown, it includes steps S1, S2, S3, S4, and S5. In order to better understand the present invention, each step is described in detail below in conjunction with specific embodiments.
[0037] Step S1: Obtain graph data to be processed.
[0038] According to an embodiment of the present invention, after the graph data is obtained, the process can directly proceed to step S2. It should be understood that although the efficiency of subsequent traversal is slightly worse than that of the pre-processed graph data, it is still a feasible solution.
[0039] However, before formally traversing the graph data, corresponding preprocessing methods can also be used to improve the efficiency of subsequent graph traversal.
[0040] According to an embodiment of the present invention, first graph data is obtained and preprocessed to obtain second graph data. The first graph data may be original graph data; the second graph data is graph data obtained after preprocessing. In some embodiments, the second graph data corresponds to the graph data to be processed.
[0041] According to an embodiment of the present invention, the first graph data and the second graph data are graph data, and the graph data includes a plurality of nodes and edges, wherein a node represents a corresponding object, an edge represents a relationship between two nodes, and a weight of an edge indicates a distance between the two nodes. The distance is, for example, one of a time distance, a spatial distance, or an intimate distance.
[0042] In order to avoid the influence of isolated nodes, according to an embodiment of the present invention, the preprocessing method includes: removing isolated nodes.
[0043] In order to avoid the impact of discontinuous numbering after removing isolated nodes on traversal efficiency, according to an embodiment of the present invention, the preprocessing method includes: removing isolated nodes and remapping the numbers of nodes after the isolated nodes are removed. Wherein, an isolated node refers to a node that has no node connected to it.
[0044] In order to avoid the influence of duplicate edges on traversal efficiency, according to one embodiment of the present invention, the preprocessing method includes: removing duplicate edges with relatively large weights.
[0045] In order to reduce the impact of some redundant edges on the efficiency of graph traversal and to improve the efficiency of subsequent traversal in a further step, the preprocessing method includes: deleting the edges between two directly connected nodes that meet the predetermined deletion condition, wherein the predetermined deletion condition is that the weight of the edge is greater than the sum of the weights of all edges from the two nodes to the nearest neighboring common node (the two nodes may pass through one or more edges with the nearest neighboring common node).
[0046] According to an embodiment of the present invention, the preprocessing method includes: a combination of the above preprocessing methods.
[0047] According to one embodiment of the present invention, step S1 further comprises:
[0048] 1.1) Get the first graph data; use the official Graph500 benchmark program to get the Rmat generated graph (graph data generated based on the Recursive MATrix model, which is used as the first graph data for illustration, and the actual graph data will be larger) and store it in the Compressed Sparse Row (CSR) format, such as Figure 2 As shown in the figure, a column array (hereinafter also called Column array) is used to store the IDs of all neighbor nodes of each node, a value array (hereinafter also called Value array) is used to store the weights of the edges between each node and its neighbor nodes, and a row array (hereinafter also called Row array) is used to store the index subscript value of the first neighbor node of each node in the Column array. Figure 2 For example, Figure 2 a represents the original graph data, which has 5 nodes and 7 undirected edges. The nodes include 0, 1, 2, 3, and 4. There is an edge with a weight of 4 between nodes 0 and 1, and an edge with a weight of 1 between nodes 0 and 4. The others are similar and will not be described here. The corresponding adjacency matrix is expressed as follows: Figure 2 b, where a weight of 0 indicates that there is no direct edge connecting the two nodes, and the remaining non-zero values indicate the weight of the edge connecting the two nodes, as shown in Figure 2 The 4th column of row 0 of b indicates that there is an edge with a weight of 4 connecting nodes 0 and 4. The rest is similar and will not be described here. Figure 2 c lists the corresponding CSR structure. Taking node 0 as an example, its neighbor nodes are node 1 and node 4, and the corresponding edge weights are 6 and 1 respectively. Therefore, the values of the elements with subscripts 0 and 1 in the Column array are 1 and 4 respectively, and the values of the elements with subscripts 0 and 1 in the Value array are 6 and 1 respectively. The element with subscript 0 in the Row array represents the subscript of the first neighbor node of node 0 (node 1) in the column array, which is 0. The element with subscript 1 in the Row array is 2, indicating that the neighbor nodes of node 0 end at the element with subscript 1 in the Column array, and start from the element with subscript 2 in the Column array, which corresponds to the neighbor nodes of the next node. Others are similar and will not be repeated here.
[0049] 1.2) Sort all nodes in the graph in ascending order according to degree, delete nodes with degree zero, and renumber the remaining nodes to obtain new index IDs; since points with degree zero will not be accessed during the SSSP algorithm, but these points still exist in the CSR structure, occupying memory space, resulting in reduced data locality, it is necessary to delete zero-degree nodes (corresponding to isolated nodes) and renumber all non-zero-degree nodes to establish a mapping relationship between new and old node serial numbers.
[0050] 1.3) For each node, sort its adjacent edge table according to the indexes of all its neighboring nodes and delete duplicate edges. There may be multiple edges in the same node pair in the generated graph. During the SSSP processing, these redundant edges will increase unnecessary memory access and update operations for the same node data. Therefore, only the edge with the smallest weight needs to be retained between the same node pair, and other redundant edges need to be deleted. In the actual algorithm running process, redundant memory access, judgment and update operations can be reduced; in other words, for multiple edges between the same node pair, since only the edge with the smallest weight will eventually work in the process of finding the single-source shortest path distance, only the edge with the smallest weight is retained between the same node pair, and the remaining duplicate edges are deleted to reduce redundant graph data and traversal.
[0051] 1.4) Randomly select a node as the root node and perform edge data pruning. This greatly reduces redundant graph data. The edge data pruning here corresponds to the above preprocessing method of deleting the edges between two directly connected nodes that meet the predetermined deletion conditions. Figure 3As shown in the figure, assume that node s is selected as the root node for pruning. If (d(u) - d(z)) + (d(v) - d(z)) < w(uv), then edge <u, v> is deleted, where node z represents the nearest common node of nodes u and v in the spanning tree with node s as the root node (some documents also refer to it as the nearest common ancestor node, the nearest common parent node, etc.), d(u) - d(z) represents the distance between node z and node u, and d(v) - d(z) represents the distance between node v and z. Since the connection relationship of each node and its relationship with the root node also need to be considered to determine whether the predetermined deletion condition is satisfied, an existing SSSP algorithm can be run once first to improve the overall efficiency of subsequent traversal with different nodes as the root node. However, it should be understood that other methods can also be used to delete the edges that satisfy the predetermined deletion condition between two directly connected nodes, and the present invention does not make any restrictions on this.
[0052] Step S2: Obtain the number of threads in the processor, and evenly distribute all the nodes recorded in the column array of the graph data to each thread according to the number of threads and the number of nodes in the graph data, obtaining multiple first subgraphs.
[0053] According to an embodiment of the present invention, the second graph data is divided into multiple first subgraphs, and the nodes (also referred to as target nodes) whose shortest distances to the root node need to be determined in each first subgraph do not overlap. Thus, during subsequent processing by different threads, each thread will separately traverse the shortest distances from the root node to different target nodes, avoiding the atomic conflict problem. Preferably, during actual allocation, a polling allocation method can be used. Assume that the number of threads is num_threads, and the number of nodes (referring to the total number of nodes) in the second graph data is num_vertices. Then each thread is assigned num_vertices / num_threads or num_vertices / num_threads + 1 nodes. For example, according to a preset granularity, the nodes and their incoming edges of the graph data are sequentially allocated to the subgraphs (corresponding to the first subgraphs) corresponding to different threads in a polling manner, and at the same time, the incoming edges of these nodes are allocated to the corresponding threads. Finally, each thread obtains a non-overlapping set of nodes and the corresponding set of incoming edges, and each thread has num_vertices / num_threads or num_vertices / num_threads + 1 nodes. Through subgraph partitioning, the atomic conflict problem of multiple threads operating on the same node data unit can be avoided, improving the algorithm efficiency.
[0054] According to an example of the present invention, assume that for Figure 4The nodes in the graph data shown in a are allocated. The total number of nodes is 5 and the number of threads is 2. The nodes are allocated to the subgraphs corresponding to the threads in a round-robin manner with a granularity of 1. At the same time, the incoming edges of these nodes are allocated to the corresponding threads. The positions of the nodes allocated to the two threads in the adjacency matrix are shown in the figure below. Figure 4 As shown in b, all nodes recorded in the column array before allocation, including nodes 0-4, are evenly allocated according to the node number (i.e., node ID). Finally, the subgraph corresponding to thread 0 has nodes 0, 2, and 4 in the column array; in other words, Figure 4 As shown in d, the subgraph corresponding to thread 0 has destination nodes 0, 2, and 4 and the corresponding incoming edges. The subgraph corresponding to thread 1 has nodes 1 and 3 in the column array; in other words, Figure 4 As shown in e, the subgraph corresponding to thread 1 has destination nodes 1 and 3 and corresponding incoming edges, and the CSR structures of the two first subgraphs are recalculated. Figure 4 The original CSR structure corresponding to the graph data of a is as follows Figure 4 c, the corresponding meaning can be referred to Figure 2 The explanation is omitted here. Taking the subgraph corresponding to thread 0 as an example, node 0's neighbor node 4 falls within the scope of thread 0, so the value of the element with subscript 0 in the Column array is 4, the value of the element with subscript 0 in the Value array is 1, and the element with subscript 0 in the Row array stores the subscript of the first neighbor node (node 4) of node 0 in the subgraph corresponding to thread 0 in the column array, which is 0. It can be seen that the neighbor nodes of each node in the current first subgraph are still sorted by number size, and the structure of the first subgraph is not conducive to directly determining whether each adjacent edge is a light edge or a heavy edge.
[0055] Step S3: For each first subgraph, take each node recorded in the row array as a sorting unit, reorder each adjacent edge according to the weight of the node's adjacent edge to obtain the corresponding second subgraph, and determine the number of light edges of each node recorded in the row array in each second subgraph.
[0056] According to one embodiment of the present invention, the second subgraph is stored in a compressed sparse matrix row format, which includes: a row array, a column array and a value array; a row array, which records the position of the first neighbor node of each node in the second subgraph in the column array. A column array, which records the neighbor nodes of each node in the second subgraph, wherein the neighbor nodes of each node are arranged from small to large according to the weight of the corresponding neighbor edge; a value array, which records the weight of the neighbor edge of each node. Since the second subgraph uses each node in the first subgraph as a sorting unit, each neighbor edge is reordered according to the weight of the neighbor edge of the node, and the number of light edges of each node in each row array is determined (determined according to the delta parameter, the weight of the edge is less than the delta as a light edge, otherwise it is a heavy edge). Therefore, the position of the light edge can be directly determined and read according to the starting point of the neighbor node of each node in the column array and the number of light edges, without the need to access the weight of the corresponding neighbor edge and the delta parameter Δ each time and compare to determine whether the neighbor edge is a light edge or a heavy edge as in the existing Δ-Stepping algorithm, which can greatly reduce the memory access overhead and improve the calculation efficiency. In other words, the present invention sorts and counts the adjacent edges of each node in the first subgraph, which can greatly reduce the redundant memory access of the SSSP algorithm to the graph data and improve the algorithm performance.
[0057] According to an example of the present invention, before the adjacent edges are reordered and the number of light edges is determined, the CSR structures corresponding to the first subgraphs of threads 0 and 1 are respectively as follows: Figure 5 a and Figure 5 As shown in b, for each node in the first subgraph, the adjacent edges are reordered and the number of light edges (or adjacent edge sorting count) is determined, so that the adjacent edges of each node are arranged in ascending order according to the edge weight, and the number of light edges of each node in the row array of each second subgraph is calculated and stored in the light edge (Light Edge Nums, hereinafter referred to as LENums) array. For example, when Δ is 6, taking node 1 in the first subgraph 0 corresponding to thread 0 as an example, its neighbor nodes are 0, 2, and 4, and the edge weights are 6, 5, and 2, respectively, which are stored in the Column array and Value array subscripts 1, 2, and 3 positions; after the adjacent edges are reordered and the number of light edges is determined, as shown in Figure 5 c and Figure 5 As shown in d, in the second subgraph, the values corresponding to the subscripts 1, 2, and 3 in the Column array are 4, 2, and 0 respectively, and the values corresponding to the subscripts 1, 2, and 3 in the Value array are 2, 5, and 6 respectively. Since there are 2 edges with weights less than 6, the number of light edges of node 1 is recorded as 2. The others are similar and will not be elaborated here.
[0058] Step S4: Each thread traverses the corresponding second subgraph based on the improved delta walking algorithm and the selected root node, wherein the improved delta walking algorithm determines the location of the light edge or heavy edge of the node in the second subgraph according to the number of light edges of the corresponding node when traversing the light edge or heavy edge of the corresponding node.
[0059] The improved delta-walking algorithm (also called incremental walking algorithm in some literature) of the present invention is consistent with the original delta-walking algorithm in the updating principle of the relaxation operation. The main difference is that, compared with the original delta-walking algorithm, the improved delta-walking algorithm no longer determines whether the neighboring edge is a light edge or a heavy edge by comparing the weight of the neighboring edge of the currently traversed node with the size of the delta parameter each time. According to one embodiment of the present invention, the second subgraph is stored in a compressed sparse matrix row format, which includes: a row array, a column array, and a value array; the row array records the position of the first neighboring node of each node in the second subgraph in the column array; the column array records the neighboring nodes of each node in the second subgraph, wherein the neighboring nodes of each node are arranged from small to large according to the weight of the corresponding neighboring edge; the value array records the weight of the neighboring edge of each node. In order to avoid determining whether an edge is a light edge or a heavy edge by constantly comparing the weight of the edge with the size of the delta parameter, according to one embodiment of the present invention, the location of the light edge or heavy edge of the node in the second subgraph is determined according to the number of light edges of the node and the position of the first neighbor node of each node in the column array, and the weight in the corresponding value array is read to update the intermediate sub-traversal result. In other words, the improved delta stepping algorithm determines the location of the light edge or heavy edge of the node through the position of the first neighbor node of the node recorded in the row array in the second subgraph in the column array and the number of light edges of the node, and directly reads the weight of the corresponding edge for updating the intermediate sub-traversal result. For example, referring to Figure 5 b. Assuming that thread 0 is updating the result corresponding to node 2 of the second subgraph, the neighbor nodes of node 1 can be determined according to the element with subscript 1 in the row array, starting from the element with subscript 1 in the column array. In addition, since the number of light edges of each node recorded in the row array is predetermined, it can be obtained that the number of light edges of node 1 is 2. Then, it is directly determined that the edges connecting the neighbor nodes with subscripts 1-2 in the column array and the node are light edges, thereby directly determining the positions of the light edges for use by the improved delta walking algorithm, without having to judge edge by edge in the original way, which greatly reduces the memory access and computing overhead and improves the efficiency of the graph traversal algorithm.
[0060] According to an embodiment of the present invention, the nodes in each second subgraph that need to determine the shortest distance to the root node do not overlap with each other; and compared with the original delta-walking algorithm, the improved delta-walking algorithm no longer performs atomic operations. Since the nodes in each second subgraph that need to determine the shortest distance to the root node do not overlap with each other, there is no possibility that different threads operate on the same node, so the atomic operation step in the original delta-walking algorithm can be cancelled to improve computing efficiency.
[0061] According to one embodiment of the present invention, the selected root node is one or more nodes of the second graph data; wherein, when the selected root node includes multiple nodes of the second graph data, each of the multiple nodes is used as a root node to perform a graph traversal through an improved delta walking algorithm to determine its shortest distance to other nodes.
[0062] According to one embodiment of the present invention, step S4 includes processing each root node in the following manner:
[0063] S41: Randomly select a node from multiple unprocessed root nodes as the root node currently being processed, run the improved Delta Stepping algorithm (Δ-Stepping algorithm, a single-source shortest path algorithm), process the points in the current bucket in sequence according to the traversal order, and update the shortest path distance and parent node index from the root node to other nodes in the relaxation operation. The relaxation operation is to determine whether the data needs to be updated by comparing the existing shortest path distance with the newly calculated distance. If necessary, the shortest distance and parent node index of the node are updated; otherwise, no operation is performed. The relaxation operation is existing in the original Delta Stepping algorithm, and the definition of the original Delta Stepping algorithm can be referred to. The present invention does not impose any restrictions on this.
[0064] S42: Perform a Relaxation operation on the light edges of all active nodes in the current layer to update the intermediate sub-traversal results of the second subgraph, and then go to S43. Among them, the improved delta step algorithm also updates different buckets in turn, and for a bucket, first use the light edges in it to update the intermediate sub-traversal results; for any node v in the current bucket, after using the neighbor edge reordering and determining the number of light edges, only the first LENums[v] neighbor edges of the node v need to be processed, reducing redundant memory access and judgment. New active nodes may be generated that fall into the current bucket. Since each thread is responsible for processing different destination node data after the subgraph partitioning step, there will be no atomic conflict problem when updating the results of the shortest path distance and parent node index.
[0065] S43: Perform relaxation operations on all the heavy edges of the nodes processed in the previous stage. The improved delta step algorithm also updates different buckets in sequence, and for a bucket, first uses all the light edges in it to update the intermediate sub-traversal results, and then uses the heavy edges in it to update the intermediate sub-traversal results; for any node v in the current bucket, after using the neighboring edges to reorder and determine the number of light edges, among all the neighboring edges of node v, the neighboring edges starting from LENums[v]+1 of the node are heavy edges, so it is only necessary to directly read the corresponding heavy edges from here to update the results, reducing redundant memory access and judgment.
[0066] S44: Repeat steps S42 and S43 to process the next bucket until all buckets have been processed and no new nodes are generated and fall into the buckets.
[0067] Step S5: According to the sub-traversal results of the second subgraph of all threads, a traversal result of the graph data is obtained, which indicates the shortest path from the selected root node to other nodes and / or the shortest distance corresponding to the shortest path.
[0068] According to one embodiment of the present invention, since each thread only obtains the traversal sub-result of the corresponding second sub-graph, that is, the shortest path and / or shortest distance from the selected root node to some other nodes, the traversal sub-results of the sub-graphs of all threads can be summarized to obtain the final traversal result. The traversal result includes the shortest distance from the selected root node to other nodes.
[0069] The following is an illustrative application scenario involving the single-source shortest path algorithm:
[0070] The bus route network of a city is established as a graph. Users who take the bus hope to query the most time-saving path or the shortest distance path from a certain starting station to the destination station.
[0071] 1. Consider establishing different stations as nodes in the graph data, and different bus routes as edges, with the weight of the edge being the distance. Specifically, different stations can be abstracted as different nodes in the graph, and the nodes corresponding to two stations connected by bus routes are connected by edges. The weight of the edge is the time or space distance from one station to another. The problem is then converted into finding the shortest path and the shortest path distance between two given nodes.
[0072] 2. After establishing the graph model, data preprocessing is performed, and data preprocessing, subgraph partitioning, and adjacent edge sorting and counting processes are executed to reduce redundant data, atomic conflicts, and redundant memory accesses.
[0073] 3. The method of traversing graph data of the present invention is executed once for each node in the graph, and the shortest distance from each site to the other sites and the corresponding shortest path can be obtained.
[0074] 4. When customers make inquiries, they only need to give the starting point and destination point to get the shortest path and the shortest time.
[0075] According to one embodiment of the present invention, a method for determining a riding route is provided, including obtaining graph data, wherein the nodes thereof represent corresponding bus stops, the edges represent roads between corresponding bus stops, and the weight of the edges represents the distance between the two nodes connected thereto, wherein the distance is a spatial distance and / or a temporal distance; processing the graph data using the method for traversing graph data of the aforementioned embodiment to obtain a corresponding traversal result; querying the traversal result according to the starting station and the destination station input by the user to obtain a corresponding riding route. Since the method for traversing graph data of the present invention uses the SSSP algorithm for graph traversal, the riding route includes the shortest path and / or the distance corresponding to the shortest path. The technical solution of this embodiment can at least achieve the following beneficial technical effects: the shortest distance and the corresponding route (shortest path) can be calculated more efficiently, the calculation process can be saved, and the user experience can be improved. Although the present invention provides a method for determining a riding route as an illustrative use scenario, it should be understood that it can be extended to a variety of application scenarios, and any graph traversal scenario that requires calculating the shortest distance from the root node to the corresponding node can be used, thereby improving the calculation efficiency of the graph traversal in the application scenario. For example, in a scenario of determining a driving route, the nodes of the graph data represent locations, the edges represent lanes between locations, and the shortest path and / or shortest distance between the locations input by the user is calculated.
[0076] It should be noted that although the above describes the various steps in a specific order, it does not mean that the various steps must be executed in the above specific order. In fact, some of these steps can be executed concurrently or even in a different order as long as the required functions can be achieved.
[0077] The present invention may be a system, a method and / or a computer program product. The computer program product may include a computer-readable storage medium carrying computer-readable program instructions for causing a processor to implement various aspects of the present invention.
[0078] Computer readable storage medium can be a tangible device that holds and stores instructions used by an instruction execution device. Computer readable storage medium can include, for example, but is not limited to, an electrical storage device, a magnetic storage device, an optical storage device, an electromagnetic storage device, a semiconductor storage device, or any suitable combination thereof. More specific examples (non-exhaustive list) of computer readable storage medium include: a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a static random access memory (SRAM), a portable compact disk read-only memory (CD-ROM), a digital versatile disk (DVD), a memory stick, a floppy disk, a mechanical encoding device, for example, a punch card or a protruding structure in a groove on which instructions are stored, and any suitable combination thereof.
[0079] The embodiments of the present invention have been described above, and the above description is exemplary, not exhaustive, and is not limited to the disclosed embodiments. Many modifications and variations will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the described embodiments. The selection of terms used herein is intended to best explain the principles of the embodiments, practical applications, or technical improvements in the market, or to enable other persons of ordinary skill in the art to understand the embodiments disclosed herein.
Claims
1. A method for traversing graph data, It is characterized in that include: Get the graph data to be processed; Obtaining the number of threads in the processor, and evenly distributing all nodes recorded in the column array of the graph data to each thread according to the node number according to the number of threads and the number of nodes in the graph data, to obtain multiple first subgraphs; For each first subgraph, each node recorded in the row array is used as a sorting unit, and each adjacent edge is reordered according to the weight of the node's adjacent edge to obtain the corresponding second subgraph, and the number of light edges of each node recorded in the row array in each second subgraph is determined, wherein the second subgraph is stored in a compressed sparse matrix row format, which includes: a row array, a column array, and a value array; the row array records the position of the first neighbor node of each node recorded in the row array in the second subgraph in the column array; the column array records the neighbor nodes of each node recorded in the row array in the second subgraph, wherein the neighbor nodes of each node are arranged from small to large according to the weight of the corresponding adjacent edge; the value array records the weight of the adjacent edge of each node; Each thread performs graph traversal on the corresponding second subgraph based on the improved delta walking algorithm and the selected root node, wherein the improved delta walking algorithm determines the position of the light edge or heavy edge of the node in the second subgraph according to the number of light edges of the corresponding node when traversing the light edge or heavy edge of the corresponding node; According to the sub-traversal results of the second subgraph of all threads, the traversal results of the graph data are obtained, which indicate the shortest path from the selected root node to other nodes and / or the shortest distance corresponding to the shortest path.
2. The method according to claim 1, It is characterized in that Compared with the original delta-walking algorithm, the improved delta-walking algorithm no longer determines whether the neighboring edge of the currently traversed node is a light edge or a heavy edge by comparing the weight of the neighboring edge with the size of the delta parameter each time.
3. The method according to claim 1, It is characterized in that The nodes in each second subgraph whose shortest distance to the root node needs to be determined do not overlap with each other; and, compared with the original delta-walking algorithm, the improved delta-walking algorithm no longer performs atomic operations.
4. The method according to claim 3, It is characterized in that The position of the light edge or heavy edge of the node in the second subgraph is determined according to the number of light edges of the node and the position of the first neighbor node of each node in the column array, and the weight in the corresponding value array is read to update the intermediate sub-traversal result.
5. The method according to any one of claims 1 to 4, It is characterized in that Before graph traversal, the graph data is preprocessed. The preprocessing methods include: removing isolated nodes, renumbering the nodes after the isolated nodes are removed and establishing a mapping relationship between the renumbered numbers and the original numbers, removing duplicate edges with relatively large weights, or a combination thereof.
6. The method according to any one of claims 1 to 4, It is characterized in that Before graph traversal, the graph data is preprocessed, and the preprocessing method includes: deleting the edges between two directly connected nodes that meet the predetermined deletion condition, wherein the predetermined deletion condition is the sum of the weights of all edges from the two nodes to the nearest neighbor common node.
7. The method according to claim 5, It is characterized in that Before graph traversal, the graph data is preprocessed, and the preprocessing method includes: deleting the edges between two directly connected nodes that meet the predetermined deletion condition, wherein the predetermined deletion condition is the sum of the weights of all edges from the two nodes to the nearest neighbor common node.
8. A method for determining a ride path, It is characterized in that include: Obtain graph data, where nodes represent corresponding bus stops, edges represent roads between corresponding bus stops, and the weight of an edge represents the distance between two connected nodes, where the distance is a spatial distance and / or a temporal distance; Processing the graph data using the method for traversing graph data described in any one of claims 1 to 7 to obtain corresponding traversal results; According to the starting station and the destination station input by the user, the traversal result is queried to obtain the corresponding riding path.
9. A computer-readable storage medium, It is characterized in that A computer program is stored thereon, and the computer program can be executed by a processor to implement the steps of the method according to any one of claims 1 to 8.
10. An electronic device, It is characterized in that include: one or more processors; and a memory, wherein the memory is used to store executable instructions; The one or more processors are configured to implement the steps of the method of any one of claims 1 to 8 by executing the executable instructions.
Citation Information
Patent Citations
Large-scale uncertain graph database-oriented subgraph query method
CN102073708A
Graph query processing method based on massive data
CN104699698A
Graph data handling method, device and system
CN106354729A
Graph data processing method applied to distributed computing node cluster and medium
CN111737540A
