Directed graph processing method, device, electronic device, storage medium and program product
By decomposing the directed graph into a normal sub-graph and a dynamic sub-graph and saving it in different recycling unit groups, the problem of more garbage disposal in directed graph processing is solved, and the storage performance of solid-state memory is improved.
Patent Information
- Application Number
- CN202411180186.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-27
- Publication Date
- 2025-03-11
- Estimated Expiration
- 2044-08-27
AI Technical Summary
In the prior art, a large amount of garbage is easily generated during directed graph processing, resulting in poor storage performance of the hard disk.
The generation and processing of garbage data are reduced by decomposing the directed graph into a constant normal sub-graph and a dynamic sub-graph that changes at any time, and saving them to different groups of recycling units defined by the customizable data arrangement interface.
It effectively reduces the generation and processing of garbage data and improves the overall storage performance of solid-state memory.
Smart Images

Figure CN118689787B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a directed graph processing method, device, electronic device, storage medium and program product. Background Art
[0002] Solid-state drives (SSDs) have been widely used in recent years. They are different from traditional mechanical hard disks (HHDs) in many aspects, such as performance, power consumption, and reliability. From the operational characteristics of flash memory, the difference between it and HHD lies mainly in the processing of write operations. SSDs cannot perform overwrite operations on any physical address like HHDs. They can only erase the entire block of data in units of blocks. In the process of directed graph processing, a large amount of garbage processing is easily generated, and the storage performance of hard disks is poor. Summary of the invention
[0003] The present invention provides a directed graph processing method, device, electronic device, storage medium and program product, which are used to solve the defects of the prior art that a large amount of garbage processing is easily generated during the directed graph processing process and the storage performance of the hard disk is poor, thereby reducing the generation and processing of garbage data and improving the overall storage performance of the solid-state memory.
[0004] The present invention provides a directed graph processing method, comprising the following steps: decomposing a directed graph into a constant normal subgraph and a dynamic subgraph that changes at any time; and saving the normal subgraph and the dynamic subgraph respectively into different recycling unit groups defined by a customizable data arrangement interface.
[0005] According to a directed graph processing method provided by the present invention, the nodes in the normal subgraph are normal nodes, and the method further includes: for the normal subgraph, pre-given normal node numbers of each normal node in the normal node set, and storing the edges connected to each normal node in sequence according to the normal node numbers; wherein, when storing the edges connected to each normal node, the incoming edges are stored first, and then the outgoing edges are stored; and the edges are numbered according to the storage order of the edges in the normal subgraph.
[0006] According to a directed graph processing method provided by the present invention, the data storage structure of the normal subgraph is defined with the following fields: a value n, a value m, an array spos, an array edge, an array edge_inv, an array cost, an array root and an array leaf; wherein: the value n represents the number of nodes of the normal subgraph; the value m represents the number of edges of the normal subgraph; the array spos is used to store the number of the first edge of the node in sequence according to the number of the node, wherein the first edge of the node refers to the edge with the smallest number connected to the node; the array edge is used to record the point number of each edge; wherein for the incoming edge, the starting point number is recorded; for the outgoing edge, the end point number is recorded; the array edge_inv is used to record the number of the reverse edge of each edge; the array cost is used to record the consumption value on each edge; the array root is used to record the number of the root node; the array leaf is used to record the number of the leaf node.
[0007] According to a directed graph processing method provided by the present invention, the process of obtaining the data storage structure of the normal subgraph includes: presetting the number of nodes of the normal subgraph, and adding a corresponding number of nodes to the graph according to the number of nodes; receiving the user's operation of adding edges, updating the two-dimensional array storing the start and end points of the edges according to the user's operation of adding edges, updating the array storing the consumption values of the edges according to the consumption values of the edges added by the user, and updating the number of edges at the same time; after the edge adding operation is completed, converting the number of nodes, the number of edges, the two-dimensional array and the array storing the consumption values of the edges into the data storage structure of the normal subgraph.
[0008] According to a directed graph processing method provided by the present invention, the nodes in the dynamic subgraph are dynamic nodes, and the method also includes: for the dynamic subgraph, maintaining a dynamic node resource pool of added nodes and unadded nodes, assigning dynamic node numbers in a dynamic node set to the dynamic nodes, and assigning resource positions in sequence, using a linked list structure to manage the deletion of the added nodes and the addition of the unadded nodes; the number of the dynamic nodes is pre-set.
[0009] According to a directed graph processing method provided by the present invention, the method also includes: using an association matrix to save information of dynamic edges; wherein: the association matrix is a 0-1 matrix, the association matrix is a square matrix, the row nodes of the association matrix include the normal nodes and the dynamic nodes, and the column nodes of the association matrix include the normal nodes and the dynamic nodes; the row nodes and column nodes of the association matrix are arranged and numbered in the same order, the numbers of the normal nodes in the association matrix establish a mapping relationship with the normal node numbers, and the numbers of the dynamic nodes in the association matrix establish a mapping relationship with the dynamic node numbers; the elements with a value of 1 in the association matrix indicate that there is a valid edge pointing from the corresponding row node of the association matrix to the corresponding column node; for each row of the association matrix, the elements with a value of 1 establish a link structure through a valid edge chain list, and the order of links is established according to the order in which the elements are set to 1; for each column of the association matrix, the elements with a value of 1 establish a link structure through a valid edge chain list, and the order of links is established according to the order in which the elements are set to 1.
[0010] According to a directed graph processing method provided by the present invention, the method also includes: maintaining a root node resource pool for storing root nodes in the dynamic nodes, and using a root node linked list to manage the addition and deletion of the root nodes; maintaining a leaf node resource pool for storing leaf nodes in the dynamic nodes, and using a leaf node linked list to manage the addition and deletion of the leaf nodes.
[0011] According to a directed graph processing method provided by the present invention, the method also includes: in response to receiving a processing request for adding a dynamic edge from node i in the association matrix to node j to the directed graph, performing the following operations: setting the element in the i-th row and j-th column of the association matrix to 1; adding the element (i, j) to the end of the valid edge list in the i-th row of the association matrix, and updating the relevant links and head and tail pointers of the valid edge list; adding the element (i, j) to the end of the valid edge list in the j-th column of the association matrix, and updating the relevant links and head and tail pointers of the valid edge list; if node i is a leaf node, deleting i from the leaf node resource pool, and updating the relevant links and head and tail pointers of the leaf node list; if node j is a root node, deleting j from the root node resource pool, and updating the relevant links and head and tail pointers of the root node list.
[0012] According to a directed graph processing method provided by the present invention, the method also includes: in response to receiving a processing request to delete the edge pointing from node i to node j in the association matrix, performing the following operations: deleting edge (i, j) from the valid edge list of the i-th row of the association matrix, and updating the relevant links and head and tail pointers of the valid edge list; deleting edge (i, j) from the valid edge list of the j-th column of the association matrix, and updating the relevant links and head and tail pointers of the valid edge list; setting the elements of the i-th row and j-th column of the association matrix to 0; if the i-th row of the association matrix is all zero, adding node i to a leaf node resource pool, and updating the relevant links and head and tail pointers of the leaf node list; if the j-th column of the association matrix is all zero, adding node j to a root node resource pool, and updating the relevant links and head and tail pointers of the root node list.
[0013] According to a directed graph processing method provided by the present invention, the method also includes: in response to receiving a processing request to add a dynamic node to the directed graph, performing the following operations: marking the corresponding resource position in the dynamic node resource pool as occupied according to the dynamic node number of the dynamic node; adding the dynamic node to the tail of the added node linked list, updating the relevant links and head and tail pointers of the added node linked list; deleting the dynamic node in the unadded node linked list, updating the relevant links and head and tail pointers of the unadded node linked list; adding the dynamic node to the root node resource pool, updating the relevant links and head and tail pointers of the root node linked list; adding the dynamic node to the leaf node resource pool, updating the relevant links and head and tail pointers of the leaf node linked list.
[0014] According to a directed graph processing method provided by the present invention, the method also includes: in response to receiving a processing request to delete a dynamic node from the directed graph, performing the following operations: determining the number of the dynamic node in the association matrix according to the mapping relationship between the dynamic node number of the dynamic node and the number of the dynamic node in the association matrix; setting the elements of the corresponding row and the corresponding column in the association matrix to 0, and clearing the valid edge list; adding the dynamic node to the end of the unadded node list, updating the relevant links and head and tail pointers of the unadded node list; deleting the dynamic node from the added node list, updating the relevant links and head and tail pointers of the added node list; marking the resource position corresponding to the dynamic node in the dynamic node resource pool as unoccupied; if the dynamic node is in the root node resource pool, deleting the dynamic node from the root node resource pool; if the dynamic node is in the leaf node resource pool, deleting the dynamic node from the leaf node resource pool.
[0015] According to a directed graph processing method provided by the present invention, the method further includes: in response to receiving a processing request for traversing subsequent outgoing edges of node i based on the valid edge from node i to node j in the association matrix, performing the following operations: traversing subsequent outgoing edges of node i by tracking the valid edge linked list of the i-th row in the association matrix; if node i is a normal node, determining the normal node number k of node i according to the mapping relationship between the normal node number and the number of the normal node in the association matrix, and performing [spos[k 2+1],spos[k 2+2]) to traverse the edges between them.
[0016] According to a directed graph processing method provided by the present invention, the method further includes: in response to receiving a processing request for traversing subsequent incoming edges of node j based on the valid edge from node i to node j in the association matrix, performing the following operations: traversing the subsequent incoming edges of node j by tracking the valid edge linked list of the jth column in the association matrix; if node j is a normal node, determining the normal node number s of node j according to the mapping relationship between the normal node number and the number of the normal node in the association matrix, and performing [spos[s 2],spos[s 2+1]) to traverse the edges between them.
[0017] According to a directed graph processing method provided by the present invention, the method also includes: in response to receiving a root node traversal request, traversing the root node resource pool and the nodes in the array root; in response to receiving a leaf node traversal request, traversing the leaf node resource pool and the nodes in the array leaf.
[0018] According to a directed graph processing method provided by the present invention, the method also includes: initializing an empty task queue; in response to receiving a parallel task scheduling request, initializing an empty task queue, and looping the following operations until the task queue is empty: traversing the root node and adding the root node to the task queue; taking out the nodes in the task queue and scheduling them in parallel; wherein, after executing each task corresponding to a node, traversing the child nodes of the node, if the child node has only one parent node, adding the child node to the task queue and deleting the node that has currently completed the task; if the child node has two or more parent nodes, only deleting the node that has currently completed the task.
[0019] The present invention also provides a directed graph processing device, comprising the following modules: a decomposition module, used to decompose a directed graph into a normal subgraph that remains unchanged and a dynamic subgraph that changes at any time; a storage module, used to save the normal subgraph and the dynamic subgraph respectively into different recycling unit groups defined by a customizable data arrangement interface.
[0020] The present invention also provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the directed graph processing method described above is implemented.
[0021] The present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the directed graph processing method as described in any one of the above is implemented.
[0022] The present invention also provides a computer program product, comprising a computer program, wherein when the computer program is executed by a processor, the directed graph processing method described above is implemented.
[0023] The directed graph processing method, device, electronic device, storage medium and program product provided by the present invention reduce the generation and processing of garbage data and improve the overall storage performance of the solid-state memory by decomposing a directed graph into a normal subgraph that remains unchanged and a dynamic subgraph that changes at any time, and respectively save the normal subgraph and the dynamic subgraph into different recycling unit groups defined by a customizable data arrangement interface. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] In order to more clearly illustrate the technical solutions in the present invention or the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0025] Figure 1 It is a flow chart of the directed graph processing method provided by the present invention.
[0026] Figure 2 It is a schematic diagram of a normal subgraph in the directed graph processing method provided by the present invention.
[0027] Figure 3 It is a schematic diagram of the storage structure of dynamic nodes in the directed graph processing method provided by the present invention.
[0028] Figure 4 It is a schematic diagram of the association matrix in the directed graph processing method provided by the present invention.
[0029] Figure 5 It is a structural schematic diagram of the directed graph processing device provided by the present invention.
[0030] Figure 6 It is a structural schematic diagram of the electronic device provided by the present invention. DETAILED DESCRIPTION
[0031] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the drawings of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0032] Explanation of symbolic terms:
[0033] SSD: Solid State Drive, refers to solid state drive.
[0034] NVME: A communication interface between a host and non-volatile memory, commonly used for communication between a host and an SSD.
[0035] FDP: An extended interface defined by NVME's TP4146 technical proposal that allows user applications to more freely choose the location of data in the storage medium.
[0036] RU: An erasure unit is the smallest erasure unit defined by the FDP extension proposal.
[0037] RUG: In FDP, RUs are divided into several RUGs, and RUs in different RUGs will adopt different garbage collection strategies.
[0038] Namespace: A primary storage unit defined in the NVME interface. Different Namespaces can use different storage settings, including power supply, capacity information, lifespan, write granularity, etc.
[0039] Formatting: refers to initializing the hard disk to a blank disk state without any data and preparing it for all user operations.
[0040] Graph: A basic data structure consisting of nodes and edges.
[0041] Directed Graph: If each edge in the graph has a direction specified, then it is a directed graph.
[0042] A cycle in a directed graph: Starting from a node, move along any directed edge, traversing the nodes along the path. If you eventually return to the starting point and there are no repeated nodes in the path, it is called a cycle.
[0043] DAG: Directed Acyclic Graph. If there is no cycle in a directed graph, it is called DAG.
[0044] In the NVME interface standard, a whole block of data that can be erased is called a RU (Reclaim Unit). The NVME interface standard is currently adopted by many SSD products. The TP4146 technical proposal for this standard proposes a function called FDP (Flexible Data Placement, customizable data arrangement). In this function, the SSD controller (firmware) can classify all garbage-recoverable data blocks according to different RUGs (Reclaim Unit Groups). RUs located in different RUGs can adopt different garbage collection strategies. Each user write command can specify the RU to which the data belongs. In this way, if the controller defines different recovery strategies for different RUGs and informs the user, each user's application can select the appropriate RUG according to its dedicated storage characteristics to complete the storage of specific functional modules.
[0045] In addition, FDP also provides a mechanism to selectively ensure that data belonging to different user applications can be stored in different RUs. This can avoid different applications mixing the same RU and causing additional garbage data. Each application can choose a specific garbage collection strategy based on its own characteristics without affecting the recycling strategy of other applications. When all the data of an application needs to be completely deleted, the entire RU can be erased directly without generating garbage data. An NVME Namespace can define the above policy selections for multiple applications in advance. Therefore, the FDP function can provide a suitable functional interface for SSD products with specialized application functions.
[0046] Graph computing is a type of algorithm widely used in computer software. It belongs to the field of combinatorial optimization in applied mathematics, and the basic objects processed are various types of graphs. There are many types of algorithms on graphs, most of which can be attributed to linear programming or integer programming problems. From the perspective of computability, all graph algorithms can be divided into two basic categories: P problems and NP problems. In layman's terms, it refers to whether the problem can be solved in polynomial time. Regardless of the type of algorithm, a basic storage data structure is required to save the object of the calculation. In order to achieve better computing performance, it is necessary to design a specific underlying storage data structure according to the computing requirements of different algorithms.
[0047] Figure 1 is a flow chart of a directed graph processing method provided by the present invention. The method is applied to a solid-state memory supporting a customizable data arrangement interface, such as Figure 1As shown, the method includes:
[0048] Step S1, decomposing a directed graph into a normal subgraph that remains unchanged and a dynamic subgraph that changes at any time;
[0049] Step S2: Save the normal sub-graph and the dynamic sub-graph respectively into different recycling unit groups defined by the customizable data arrangement interface.
[0050] The customizable data arrangement interface (FDP interface) is an extended interface defined by the TP4146 technical proposal of NVME. The present invention is specifically designed for SSD products with FDP functional interface, and a storage method and storage data structure dedicated to directed graph calculation are designed. The main idea is to decompose a directed graph into a normal structure part that remains unchanged and a dynamic structure part that can change at any time, and save different parts into different RUGs defined by FDP. Such a design is mainly based on the consideration that the normal structure will not change, no garbage data will be generated, and no garbage collection is required. Therefore, garbage collection can be performed only for dynamic data, and the amount of garbage data can be reduced as a whole, thereby improving the overall storage performance.
[0051] The directed graph processing method provided by the present invention reduces the generation and processing of garbage data and improves the overall storage performance of the solid-state memory by decomposing a directed graph into a normal subgraph that remains unchanged and a dynamic subgraph that changes at any time, and respectively saves the normal subgraph and the dynamic subgraph into different recycling unit groups defined by a customizable data arrangement interface.
[0052] According to a directed graph processing method provided by the present invention, the nodes in the normal subgraph are normal nodes, and the method further includes: for the normal subgraph, pre-given normal node numbers of each normal node in the normal node set, and storing the edges connected to each normal node in sequence according to the normal node numbers; wherein, when storing the edges connected to each normal node, the incoming edges are stored first, and then the outgoing edges are stored; and the edges are numbered according to the storage order of the edges in the normal subgraph.
[0053] Since the graph structure of the normal part (normal subgraph) remains unchanged, the structure can be saved in a column-compressed manner to reduce space usage. Column-compressed storage means that a node order is given in advance, and then the edges connected to each node are arranged in sequence according to the order. These edges are divided into two categories and arranged in the following order:
[0054] 1. All incoming edges: that is, directed edges with this node as the end point.
[0055] 2. All outgoing edges: that is, directed edges starting from this node.
[0056] All incoming edges of each node are sorted before all outgoing edges. After sorting one node, the next node is sorted. In this way, two clear sequence numbers are given to each fixed directed edge. One number is used as the incoming edge of the end point, and the other number is used as the outgoing edge of the starting point.
[0057] The directed graph processing method provided by the present invention pre-assigns a normal node number to the normal subgraph, and stores the edges connected to each of the normal nodes in sequence according to the normal node number. When storing the edges connected to each of the normal nodes, all the incoming edges are stored first, and then all the outgoing edges are stored. The edges are numbered according to the storage order of the edges in the normal subgraph, thereby reducing the space occupied by the normal subgraph.
[0058] According to a directed graph processing method provided by the present invention, the data storage structure of the normal subgraph is defined with the following fields: a value n, a value m, an array spos, an array edge, an array edge_inv, an array cost, an array root and an array leaf; wherein: the value n represents the number of nodes of the normal subgraph; the value m represents the number of edges of the normal subgraph; the array spos is used to store the number of the first edge of the node in sequence according to the number of the node, wherein the first edge of the node refers to the edge with the smallest number connected to the node; the array edge is used to record the point number of each edge; wherein for the incoming edge, the starting point number is recorded; for the outgoing edge, the end point number is recorded; the array edge_inv is used to record the number of the reverse edge of each edge; the array cost is used to record the consumption value on each edge; the array root is used to record the number of the root node; the array leaf is used to record the number of the leaf node.
[0059] A data storage structure of a normal subgraph in the directed graph processing method provided by the present invention is:
[0060] type Graph struct {
[0061] n int / / points
[0062] min int / / number of sides
[0063] spos []int / / The first edge number of each point
[0064] edge []int / / The point number of each edge
[0065] edge_inv []int / / The reverse edge number of each edge
[0066] cost []int / / The cost value of each outgoing edge in the shortest path problem, and zero for the incoming edge
[0067] root []int / / Record all root nodes
[0068] leaf []int / / Record all leaf nodes
[0069] }
[0070] The data storage structure is a data storage structure described in the Go language. The data storage structure of the normal subgraph is defined with the following fields: value n, value m, array spos, array edge, array edge_inv, array cost, array root, and array leaf. The array spos is used to store the number of the first edge of the node in sequence according to the node number. To facilitate data processing, the last element of the array can be set to 2m, so the dimension of the array spos is 2. n+1, the arrangement order is {the first incoming edge of node 1, the first outgoing edge of node 1, the first incoming edge of node 2, the first outgoing edge of node 2, ... 2m}.
[0071] The three arrays edge, edge_inv and cost are used to record edge information, and their size is 2 m, whose subscript is the number of the edge arranged according to the above rules. Among them, edge records the number of the point of each edge. For the incoming edge, it records the starting point number, and for the outgoing edge, it records the end point number. edge_inv records the number of the reverse edge of each edge. The reverse edge of the incoming (outgoing) edge must be the outgoing (incoming) edge. cost records the cost value on each edge, which is only valid for the outgoing edge and takes zero value for the incoming edge. This field is only valid in the shortest path algorithm.
[0072] Figure 2 It is a schematic diagram of a normal subgraph in the directed graph processing method provided by the present invention. The partial results of saving the normal subgraph according to the column compression storage structure are:
[0073] n = 9
[0074] m = 15
[0075] spos = {0, 1, 3, 4, 6, 8, 12, 13, 15, 17, 17, 19, 21, 23, 24, 27,28,29, 30}
[0076] edge = {3, 1, 2, 0, 2, 4, 0, 1, 3, 6, 7, 5, 2, 0, 6, 1, 5, 2, 8, 4,7,3, 2, 7, 2, 5, 6, 8, 7, 5}
[0077] edge_inv = {13, 3, 6, 1, 7, 15, 2, 4, 12, 22, 24, 17, 8, 0, 21, 5,19,11, 29, 16, 25, 14, 9, 26, 10, 20, 23, 28, 27, 18}
[0078] The result is Figure 2 The following are some results of the normal subgraph saved in the column compression storage structure. Among them, the node numbered 4 has no outgoing edges, and the number of the first outgoing edge of the node is set to its first incoming edge plus the number of edges connected to node 4, that is, 17. At the same time, the number of the first incoming edge of node 5 is also 17, which further shows that node 4 has no outgoing edges.
[0079] The directed graph processing method provided by the present invention facilitates the data processing of the normal subgraph by designing the data storage structure of the normal subgraph.
[0080] According to a directed graph processing method provided by the present invention, the process of obtaining the data storage structure of the normal subgraph includes: presetting the number of nodes of the normal subgraph, and adding a corresponding number of nodes to the graph according to the number of nodes; receiving the user's operation of adding edges, updating the two-dimensional array storing the start and end points of the edges according to the user's operation of adding edges, updating the array storing the consumption values of the edges according to the consumption values of the edges added by the user, and updating the number of edges at the same time; after the edge adding operation is completed, converting the number of nodes, the number of edges, the two-dimensional array and the array storing the consumption values of the edges into the data storage structure of the normal subgraph.
[0081] An IGraph data structure in the directed graph processing method provided by the present invention is:
[0082] type IGraph struct {
[0083] n int / / points
[0084] min int / / number of sides
[0085] edge [][2]int / / [2] The starting and ending points of all edges, arranged in the order in which users join
[0086] cost []int / / The cost of all edges, arranged in the order in which users join
[0087] }
[0088] For the normal graph part, this embodiment allows the user to add nodes and edges to the graph, but does not allow the user to delete the nodes and edges that have been added. For this reason, the IGraph data structure is designed to store the edges added by the user.
[0089] Here, all the points with default numbers [0, n) have been added to the graph, so the user does not need to add nodes to the graph. Only the user is supported to add edges. Every time the user adds an edge, it is recorded in the edge array of the above IGraph data structure, and the number of edges m of the normal graph is updated. When the user has finished adding all edges, the system controller will be notified. At this time, the controller will start the graph sorting process and convert the IGraph structure into a Graph structure. The specific conversion method is as follows:
[0090] 1. Initialize m and n in Graph and allocate enough space for spos, edge, and edge_inv arrays.
[0091] 2. By traversing the edge array in IGraph, calculate the number of incoming and outgoing edges for each point.
[0092] 3. Add nodes with zero incoming edges to the root array, and add nodes with zero outgoing edges to the leaf array.
[0093] 4. Assign a value to spos of Graph according to the number of incoming and outgoing edges of each vertex.
[0094] 5. Traverse the edge array in IGraph again, and provide a dummy variable number for each node to track each incoming and outgoing edge of the node, and execute
[0095] (a) According to the starting and ending point information in IGraph.edge, assign values to the edge and edge_inv arrays in Graph.
[0096] (b) Assign a value to Graph.cost based on the consumption value information in IGraph.cost.
[0097] The directed graph processing method provided by the present invention generates an initial data structure according to the user's operation of adding edges, and then converts it into a data storage structure of a normal subgraph, which facilitates user operation and improves interactive performance.
[0098] According to a directed graph processing method provided by the present invention, the nodes in the dynamic subgraph are dynamic nodes, and the method also includes: for the dynamic subgraph, maintaining a dynamic node resource pool of added nodes and unadded nodes, assigning dynamic node numbers in a dynamic node set to the dynamic nodes, and assigning resource positions in sequence, using a linked list structure to manage the deletion of the added nodes and the addition of the unadded nodes; the number of the dynamic nodes is pre-set.
[0099] Since users are allowed to add and delete points and edges to the dynamic subgraph at any time, the storage structure design of the dynamic subgraph needs to ensure that the above addition and deletion operations are completed in constant time, regardless of the scale of the graph.
[0100] Figure 3 Schematic diagram of the storage structure of dynamic nodes in the directed graph processing method provided by the present invention. Figure 3 As shown in the figure, the links in the upper part of the strip form a linked list of added nodes, and the links in the lower part of the strip form a linked list of unadded nodes. The filled rectangle indicates that the node has been added to the dynamic graph. During initialization, the user needs to specify the total number of dynamic nodes that can be allocated. In this way, it is possible to add, delete a node, and traverse the next node in constant time.
[0101] The directed graph processing method provided by the present invention realizes adding and deleting a node and traversing the next node in a constant time by reasonably designing the storage structure of dynamic nodes, thereby improving data processing efficiency.
[0102] According to a directed graph processing method provided by the present invention, the method also includes: using an association matrix to save information of dynamic edges; wherein: the association matrix is a 0-1 matrix, the association matrix is a square matrix, the row nodes of the association matrix include the normal nodes and the dynamic nodes, and the column nodes of the association matrix include the normal nodes and the dynamic nodes; the row nodes and column nodes of the association matrix are arranged and numbered in the same order, the numbers of the normal nodes in the association matrix establish a mapping relationship with the normal node numbers, and the numbers of the dynamic nodes in the association matrix establish a mapping relationship with the dynamic node numbers; the elements with a value of 1 in the association matrix indicate that there is a valid edge pointing from the corresponding row node of the association matrix to the corresponding column node; for each row of the association matrix, the elements with a value of 1 establish a link structure through a valid edge chain list, and the order of links is established according to the order in which the elements are set to 1; for each column of the association matrix, the elements with a value of 1 establish a link structure through a valid edge chain list, and the order of links is established according to the order in which the elements are set to 1.
[0103] Figure 4 Schematic diagram of the association matrix in the directed graph processing method provided by the present invention. Figure 4 As shown, the present invention uses a linked 0-1 matrix structure (incidence matrix) to store the information of dynamic edges. Figure 4As shown. The row index of the matrix represents the starting point of an edge, and the column index of the matrix represents the end point of an edge. A filled rectangle indicates that there is a directed edge from the row where the rectangle is located to the column where the rectangle is located. For each row (column) of the matrix, all filled (set to 1) elements establish a link structure through a linked list, and the order of the links is established according to the order in which the elements are set to 1. (For the sake of clarity in the figure, only the case where the order of setting 1 for each row (column) is consistent with the order of the size of the node numbers is shown, but the present invention supports inconsistent situations). Figure 4 In the table, H represents the head pointer and T represents the tail pointer.
[0104] The above association matrix is a square matrix, and its size should include all normal nodes and all dynamic nodes available for allocation (the number is specified during initialization).
[0105] The directed graph processing method provided by the present invention can realize the deletion and addition of dynamic edges in a constant time by using an association matrix to store the information of dynamic edges, thereby improving the data processing efficiency.
[0106] According to a directed graph processing method provided by the present invention, the method also includes: maintaining a root node resource pool for storing root nodes in the dynamic nodes, and using a root node linked list to manage the addition and deletion of the root nodes; maintaining a leaf node resource pool for storing leaf nodes in the dynamic nodes, and using a leaf node linked list to manage the addition and deletion of the leaf nodes.
[0107] In addition, in order to realize the traversal of all root nodes and leaf nodes, it is necessary to maintain a root node resource pool and a leaf node resource pool. The structures of the two resource pools are similar to Figure 3 The above is similar, except that the linked list with no added nodes at the bottom is removed. In this way, it is possible to add or delete a root node or leaf node in constant time, and to traverse the next root node or leaf node in constant time.
[0108] The following operations can be completed in constant time:
[0109] (1) Add a node to the graph.
[0110] (2) Add an edge to the graph.
[0111] (3) Delete an edge from the graph.
[0112] (4) Traverse the next incoming edge of a node in the order in which they were added.
[0113] (5) Traverse the next outgoing edge of a node in the order in which they were added.
[0114] (6) Traverse the next node.
[0115] (7) Traverse the next root node.
[0116] (8) Traverse the next leaf node.
[0117] The computational effort to delete a node from a graph is proportional to the number of edges connected to the node.
[0118] The directed graph processing method provided by the present invention maintains a root node resource pool for storing the root nodes in the dynamic nodes, and adopts a root node linked list to manage the addition and deletion of the root nodes, maintains a leaf node resource pool for storing the leaf nodes in the dynamic nodes, and adopts a leaf node linked list to manage the addition and deletion of the leaf nodes, thereby realizing the addition or deletion of a root node or leaf node in a constant time, and traversing the next root node or leaf node in a constant time, thereby improving data processing efficiency.
[0119] According to a directed graph processing method provided by the present invention, the method also includes: in response to receiving a processing request for adding a dynamic edge from node i in the association matrix to node j to the directed graph, performing the following operations: setting the element in the i-th row and j-th column of the association matrix to 1; adding the element (i, j) to the end of the valid edge list in the i-th row of the association matrix, and updating the relevant links and head and tail pointers of the valid edge list; adding the element (i, j) to the end of the valid edge list in the j-th column of the association matrix, and updating the relevant links and head and tail pointers of the valid edge list; if node i is a leaf node, deleting i from the leaf node resource pool, and updating the relevant links and head and tail pointers of the leaf node list; if node j is a root node, deleting j from the root node resource pool, and updating the relevant links and head and tail pointers of the root node list.
[0120] The row and column indices of the association matrix mentioned in this embodiment all refer to the row or column corresponding to the node to be operated. Because the row and column indices of the association matrix not only cover all dynamic nodes, but also cover all normal nodes, its row and column indices are not necessarily strictly equal to the dynamic node number or normal node number to be operated, and there may be a mapping relationship between them. However, the normal node and the dynamic node can be continuously mapped to the association matrix respectively. Therefore, the calculation of the above mapping can be realized by only one step of integer operation.
[0121] The operation flow of adding a dynamic edge from node i to node j in the association matrix to the graph is as follows:
[0122] (1) Set the element in the i-th row and j-th column of the incidence matrix to 1.
[0123] (2) Add the element (i, j) to Figure 4 The tail of the valid edge list of the i-th row is shown, and the relevant links and head and tail pointers are updated.
[0124] (3) Add the element (i, j) to Figure 4 The tail of the valid edge list in the jth column is shown, and the relevant links and head and tail pointers are updated.
[0125] (4) If i is a leaf node, delete i from the leaf node resource pool and update the relevant links and head and tail pointers.
[0126] (5) If j is the root node, delete j from the root node resource pool and update the relevant links and head and tail pointers.
[0127] Among them, i is the row number of the incidence matrix, and j is the column number of the incidence matrix.
[0128] The directed graph processing method provided by the present invention realizes the addition of dynamic edges in a constant time and improves data processing efficiency.
[0129] According to a directed graph processing method provided by the present invention, the method also includes: in response to receiving a processing request to delete the edge pointing from node i to node j in the association matrix, performing the following operations: deleting edge (i, j) from the valid edge list of the i-th row of the association matrix, and updating the relevant links and head and tail pointers of the valid edge list; deleting edge (i, j) from the valid edge list of the j-th column of the association matrix, and updating the relevant links and head and tail pointers of the valid edge list; setting the elements of the i-th row and j-th column of the association matrix to 0; if the i-th row of the association matrix is all zero, adding node i to a leaf node resource pool, and updating the relevant links and head and tail pointers of the leaf node list; if the j-th column of the association matrix is all zero, adding node j to a root node resource pool, and updating the relevant links and head and tail pointers of the root node list.
[0130] The process of deleting the edge from node i to node j in the association matrix is as follows:
[0131] (1) From Figure 4 Delete the edge (i, j) from the valid edge list of row i as shown, and update the related links and head and tail pointers.
[0132] (2) From Figure 4 Delete the edge (i, j) from the valid edge list in the jth column as shown, and update the related links and head and tail pointers.
[0133] (3) Set the element in the i-th row and j-th column of the incidence matrix to 0.
[0134] (4) If the i-th row of the association matrix is all zero, add node i to the leaf node resource pool and update the relevant links and head and tail pointers.
[0135] (5) If the jth column of the association matrix is all zero, add node j to the root node resource pool and update the relevant links and head and tail pointers.
[0136] Among them, i is the row number of the incidence matrix, and j is the column number of the incidence matrix.
[0137] The directed graph processing method provided by the present invention realizes the deletion of dynamic edges in a constant time and improves the data processing efficiency.
[0138] According to a directed graph processing method provided by the present invention, the method also includes: in response to receiving a processing request to add a dynamic node to the directed graph, performing the following operations: marking the corresponding resource position in the dynamic node resource pool as occupied according to the dynamic node number of the dynamic node; adding the dynamic node to the tail of the added node linked list, updating the relevant links and head and tail pointers of the added node linked list; deleting the dynamic node in the unadded node linked list, updating the relevant links and head and tail pointers of the unadded node linked list; adding the dynamic node to the root node resource pool, updating the relevant links and head and tail pointers of the root node linked list; adding the dynamic node to the leaf node resource pool, updating the relevant links and head and tail pointers of the leaf node linked list.
[0139] The operation flow of adding a dynamic node k (k represents the dynamic node number) to the graph is as follows:
[0140] (1) Figure 3 The kth resource position in the resource pool shown is marked as occupied.
[0141] (2) Add node k to the end of the linked list of added nodes and update the related links and head and tail pointers.
[0142] (3) Delete node k from the linked list of unadded nodes and update the related links and head and tail pointers.
[0143] (4) Add node k to the root node resource pool and update related links and head and tail pointers.
[0144] (5) Add node k to the leaf node resource pool and update related links and head and tail pointers.
[0145] The directed graph processing method provided by the present invention realizes adding dynamic nodes in a constant time and improves data processing efficiency.
[0146] According to a directed graph processing method provided by the present invention, the method also includes: in response to receiving a processing request to delete a dynamic node from the directed graph, performing the following operations: determining the number of the dynamic node in the association matrix according to the mapping relationship between the dynamic node number of the dynamic node and the number of the dynamic node in the association matrix; setting the elements of the corresponding row and the corresponding column in the association matrix to 0, and clearing the valid edge list; adding the dynamic node to the end of the unadded node list, updating the relevant links and head and tail pointers of the unadded node list; deleting the dynamic node from the added node list, updating the relevant links and head and tail pointers of the added node list; marking the resource position corresponding to the dynamic node in the dynamic node resource pool as unoccupied; if the dynamic node is in the root node resource pool, deleting the dynamic node from the root node resource pool; if the dynamic node is in the leaf node resource pool, deleting the dynamic node from the leaf node resource pool.
[0147] The operation flow of deleting dynamic node k (k represents the dynamic node number) from the graph is as follows:
[0148] (1) According to the mapping relationship between the dynamic node number of the dynamic node and the number of the dynamic node in the association matrix, determine the number of the dynamic node in the association matrix, such as i.
[0149] (2) Clear the entire i-th row and i-th column from the incidence matrix. The specific operations include:
[0150] ① Traverse each non-zero element in the i-th row and set it to zero.
[0151] ② Clear the valid edge list corresponding to the i-th row.
[0152] ③ Traverse each non-zero element in the j-th column and set it to zero.
[0153] ④ Clear the valid edge list corresponding to the j-th column.
[0154] (3) Add node k to the end of the linked list of unadded nodes and update the related links and head and tail pointers.
[0155] (4) Delete node k from the added node list and update the related links and head and tail pointers.
[0156] (5) Figure 3 The kth resource position in the resource pool is shown marked as unoccupied.
[0157] (6) Delete node k from the root node resource pool. (If node k is not in the root node resource pool, this operation is ignored).
[0158] (7) Delete node k from the leaf node resource pool. (If node k is not in the leaf node resource pool, this operation is ignored).
[0159] The directed graph processing method provided by the present invention realizes the deletion of dynamic nodes within a constant time and improves the data processing efficiency.
[0160] According to a directed graph processing method provided by the present invention, the method further includes: in response to receiving a processing request for traversing subsequent outgoing edges of node i based on the valid edge from node i to node j in the association matrix, performing the following operations: traversing subsequent outgoing edges of node i by tracking the valid edge linked list of the i-th row in the association matrix; if node i is a normal node, determining the normal node number k of node i according to the mapping relationship between the normal node number and the number of the normal node in the association matrix, and performing [spos[k 2+1],spos[k 2+2]) to traverse the edges between them.
[0161] The traversal operation is performed in the order in which the nodes or edges are added. The nodes or edges added first will be traversed first, which conforms to the first-in-first-out traversal order.
[0162] Given an edge (i, j) in the incidence matrix, i is the row number of the incidence matrix, j is the column number of the incidence matrix, and the subsequent outgoing edges of node i can be traversed by directly tracking the valid edge list of the i-th row. For example, when i=2 and j=3, refer to Figure 4 , the next outgoing edge is from node i=2 to j=5, and the next outgoing edge is from node i=2 to j=8.
[0163] After traversing all dynamic outgoing edges, if node i is a normal node, it is necessary to continue traversing the outgoing edges of node i in the normal subgraph. According to the mapping relationship between the normal node number and the normal node number in the association matrix, for example, the normal node number of node i is determined to be k. Since the outgoing edge of normal node k is represented as spos[k 2+1], the outgoing edge of the normal node k+1 is represented as spos[k 2+2],[spos[k 2+1],spos[k 2+2]) represents all outgoing edges of the normal node k. Therefore, for [spos[k 2+1],spos[k 2+2]) to traverse the edges between them.
[0164] The directed graph processing method provided by the present invention realizes the traversal of outgoing edges of nodes within a constant time, thereby improving data processing efficiency.
[0165] According to a directed graph processing method provided by the present invention, in response to receiving a processing request for traversing subsequent incoming edges of node j based on the valid edge from node i to node j in the association matrix, the following operations are performed: traversing the subsequent incoming edges of node j is achieved by tracking the valid edge linked list of the jth column in the association matrix; if node j is a normal node, determining the normal node number s of node j according to the mapping relationship between the normal node number and the number of the normal node in the association matrix, and performing [spos[s 2],spos[s 2+1]) to traverse the edges between them.
[0166] Given an edge (i, j) in the incidence matrix, i is the row number of the incidence matrix, j is the column number of the incidence matrix, and the subsequent incoming edges of node j can be traversed by directly tracking the valid edge list of the jth column. For example, when i=3 and j=2, refer to Figure 4 , the next incoming edge is from node i=7 to j=2, and the next incoming edge is from node i=8 to j=2.
[0167] After traversing all dynamic incoming edges, if node j is a normal node, it is necessary to continue traversing the incoming edges of node j in the normal subgraph. According to the mapping relationship between the normal node number and the normal node number in the association matrix, for example, the normal node number of node j is determined to be s. Since the incoming edge of the normal node s is represented as spos[k 2], the incoming edge of the normal node s+1 is represented as spos[k 2+1],[spos[k 2],spos[k 2+1]) represents all the incoming edges of the normal node s. Therefore, for [spos[s 2],spos[s 2+1]) to traverse the edges between them.
[0168] The directed graph processing method provided by the present invention realizes the traversal of the incoming edges of nodes within a constant time, thereby improving the data processing efficiency.
[0169] According to a directed graph processing method provided by the present invention, the method also includes: in response to receiving a root node traversal request, traversing the root node resource pool and the nodes in the array root; in response to receiving a leaf node traversal request, traversing the leaf node resource pool and the nodes in the array leaf.
[0170] For the traversal of the root node, first traverse the dynamic resource pool of the root node. After the traversal is completed, traverse the Graph.root array in the normal structure.
[0171] For leaf node traversal, first traverse the dynamic resource pool of leaf nodes, and then traverse the Graph.leaf array in the normal structure.
[0172] The directed graph processing method provided by the present invention realizes the traversal of root nodes and leaf nodes in a constant time, thereby improving data processing efficiency.
[0173] According to a directed graph processing method provided by the present invention, the method also includes: in response to receiving a parallel task scheduling request, initializing an empty task queue, and looping the following operations until the task queue is empty: traversing the root node and adding the root node to the task queue; taking out the nodes in the task queue and scheduling them in parallel; wherein, after executing each task corresponding to a node, traversing the child nodes of the node, if the child node has only one parent node, adding the child node to the task queue, and deleting the node that has currently completed the task; if the child node has two or more parent nodes, only deleting the node that has currently completed the task.
[0174] Assume that each node represents a task, and each edge represents the dependency between two tasks (the end task depends on the start task). All the task dependencies form a DAG (directed acyclic graph). In parallel task scheduling, a task execution sequence (an arrangement of all nodes) is input, and the output is required to be a list of all tasks that are allowed to be executed in parallel when each task in the sequence is completed.
[0175] For the scheduling of parallel tasks, the process from graph construction to parallel task scheduling includes:
[0176] 1. Initialize an empty queue Q to maintain all schedulable tasks.
[0177] 2. Add nodes to the graph in the order of the task sequence.
[0178] 3. Add edges to the graph based on task dependencies.
[0179] 4. Traverse all root nodes and add them to Q.
[0180] 5. Loop through the following steps until Q is empty.
[0181] (a) Take all nodes from Q and schedule them in parallel.
[0182] (b) After each task is completed, the corresponding node i in the graph is executed
[0183] i. Traverse each child node of i and determine whether the child node has only one parent node. If
[0184] If yes, add the node to Q. If no, go to step ii.
[0185] ii. Delete node i.
[0186] The directed graph processing method provided by the present invention realizes the scheduling of parallel tasks.
[0187] In addition, the calculation of the shortest path can also be implemented according to the various traversal operations provided in the above embodiments. Assume that each edge of the graph is assigned a cost. Then, given any starting and ending nodes, the shortest path from the starting node to the ending node is returned. Based on different requirements for the cost value, the following two algorithms can be specifically used.
[0188] •Dijkstra algorithm: corresponds to the case where all consumption values are non-negative.
[0189] •Moore-Bellman-Ford algorithm: corresponds to the case where the consumption value meets the conservative condition.
[0190] The directed graph processing method provided by the present invention enables developers of SSD solid-state storage based on the NVME interface standard (including FDP support) to implement a storage dedicated to graph computing, or to dedicate a Namespace of the storage to the graph computing function.
[0191] The directed graph processing device provided by the present invention is described below. The directed graph processing device described below and the directed graph processing method described above can be referred to in correspondence with each other.
[0192] Figure 5 Schematic diagram of the structure of the directed graph processing device provided by the present invention. Figure 5 As shown, the device includes a decomposition module 10 and a storage module 20, wherein: the decomposition module 10 is used to decompose a directed graph into a normal subgraph that remains unchanged and a dynamic subgraph that changes at any time; the storage module 20 is used to save the normal subgraph and the dynamic subgraph respectively into different recycling unit groups defined by a customizable data arrangement interface.
[0193] The directed graph processing device provided by the present invention pre-assigns a normal node number to the normal subgraph, and stores the edges connected to each of the normal nodes in sequence according to the normal node number. When storing the edges connected to each of the normal nodes, all the incoming edges are stored first, and then all the outgoing edges are stored. The edges are numbered according to the storage order of the edges in the normal subgraph, thereby reducing the space occupied by the normal subgraph.
[0194] Figure 6 An example of a physical structure diagram of an electronic device is shown in FIG. Figure 6As shown, the electronic device may include: a processor 910, a communications interface 920, a memory 930 and a communication bus 940, wherein the processor 910, the communications interface 920 and the memory 930 communicate with each other through the communication bus 940. The processor 910 may call the logic instructions in the memory 930 to execute a directed graph processing method, which includes: decomposing a directed graph into a constant normal subgraph and a dynamic subgraph that changes at any time; and saving the normal subgraph and the dynamic subgraph to different recycling unit groups defined by the customizable data arrangement interface.
[0195] In addition, the logic instructions in the above-mentioned memory 930 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on this understanding, the technical solution of the present invention can be essentially or partly embodied in the form of a software product that contributes to the prior art. The computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, etc. Various media that can store program codes.
[0196] On the other hand, the present invention also provides a computer program product, which includes a computer program. The computer program can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can execute the directed graph processing method provided by the above methods, which includes: decomposing a directed graph into a normal subgraph that remains unchanged and a dynamic subgraph that changes at any time; and saving the normal subgraph and the dynamic subgraph respectively into different recycling unit groups defined by a customizable data arrangement interface.
[0197] On the other hand, the present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, it is implemented to execute the directed graph processing method provided by the above-mentioned methods. The method includes: decomposing a directed graph into a normal subgraph that remains unchanged and a dynamic subgraph that changes at any time; and saving the normal subgraph and the dynamic subgraph respectively into different recycling unit groups defined by a customizable data arrangement interface.
[0198] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.
[0199] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0200] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A directed graph processing method, characterized in that: The method comprises: Decomposing a directed graph into a normal subgraph that remains unchanged and a dynamic subgraph that changes at any time; wherein the normal subgraph is a normal structural part of the directed graph that remains unchanged, and the dynamic subgraph is a dynamic structural part of the directed graph that can change at any time; The normal sub-graph and the dynamic sub-graph are respectively saved in different recycling unit groups defined by a customizable data arrangement interface; The nodes in the normal subgraph are normal nodes, and the method further includes: For the normal subgraph, a normal node number of each normal node in the normal node set is given in advance, and the edges connected to each normal node are stored in sequence according to the normal node number; wherein, when storing the edges connected to each normal node, the incoming edges are stored first, and then the outgoing edges are stored; Numbering the edges according to the storage order of the edges in the normal subgraph; The nodes in the dynamic subgraph are dynamic nodes, and the method further includes: For the dynamic subgraph, a dynamic node resource pool of added nodes and unadded nodes is maintained, dynamic node numbers in the dynamic node set are assigned to the dynamic nodes, and resource positions are allocated in sequence, and a linked list structure is used to manage the deletion of the added nodes and the addition of the unadded nodes; the number of the dynamic nodes is preset.
2. The directed graph processing method according to claim 1, characterized in that: The data storage structure of the normal subgraph is defined with the following fields: value n, value m, array spos, array edge, array edge_inv, array cost, array root and array leaf; wherein: The value n represents the number of nodes in the normal subgraph; The value m represents the number of edges of the normal subgraph; The array spos is used to store the numbers of the first edges of the nodes in sequence according to the numbers of the nodes, where the first edge of a node refers to the edge with the smallest number connected to the node; The edge array is used to record the point number of each edge; for the incoming edge, the starting point number is recorded; for the outgoing edge, the end point number is recorded; The array edge_inv is used to record the number of the reverse edge of each edge; The cost array is used to record the cost value of each edge; The array root is used to record the number of the root node; The leaf array is used to record the numbers of leaf nodes.
3. The directed graph processing method according to claim 2, characterized in that: The process of acquiring the data storage structure of the normal subgraph includes: Presetting the number of nodes of the normal subgraph, and adding a corresponding number of nodes to the graph according to the number of nodes; Receive the user's operation of adding edges, update the two-dimensional array storing the start and end points of the edges according to the user's operation of adding edges, update the array storing the consumption values of the edges according to the consumption values of the edges added by the user, and update the number of edges at the same time; After the edge adding operation is completed, the number of nodes, the number of edges, the two-dimensional array, and the array storing the consumption values of the edges are converted into a data storage structure of the normal subgraph.
4. The directed graph processing method according to claim 2, characterized in that: The method further comprises: The information of dynamic edges is saved using the association matrix; The association matrix is a 0-1 matrix, the association matrix is a square matrix, the row nodes of the association matrix include the normal nodes and the dynamic nodes, and the column nodes of the association matrix include the normal nodes and the dynamic nodes; the row nodes and column nodes of the association matrix are arranged and numbered in the same order, the number of the normal node in the association matrix is mapped to the normal node number, and the number of the dynamic node in the association matrix is mapped to the dynamic node number; An element in the incidence matrix whose value is 1 indicates that there is a valid edge pointing from the corresponding row node of the incidence matrix to the corresponding column node; For each row of the association matrix, the elements with a value of 1 establish a link structure through a valid edge link list, and the order of the links is established according to the order in which the elements are set to 1; For each column of the association matrix, the elements with a value of 1 establish a link structure through a valid edge link list, and the order of the links is established according to the order in which the elements are set to 1.
5. The directed graph processing method according to claim 4, characterized in that: The method further comprises: Maintaining a root node resource pool for storing root nodes in the dynamic nodes, and using a root node linked list to manage the addition and deletion of the root nodes; A leaf node resource pool for storing leaf nodes in the dynamic nodes is maintained, and a leaf node linked list is used to manage the addition and deletion of the leaf nodes.
6. The directed graph processing method according to claim 5, characterized in that: The method further comprises: In response to receiving a processing request to add a dynamic edge from node i in the association matrix to node j in the directed graph, performing the following operations: Set the element in the i-th row and j-th column of the incidence matrix to 1; Add the element (i, j) to the tail of the valid edge list of the i-th row of the association matrix, and update the relevant links and head and tail pointers of the valid edge list; Add the element (i, j) to the end of the valid edge list in the jth column of the association matrix, and update the relevant links and head and tail pointers of the valid edge list; If node i is a leaf node, then i is deleted from the leaf node resource pool, and the relevant links and head and tail pointers of the leaf node linked list are updated; If node j is a root node, j is deleted from the root node resource pool, and the related links and head and tail pointers of the root node linked list are updated.
7. The directed graph processing method according to claim 5, characterized in that: The method further comprises: In response to receiving a processing request to delete an edge from node i to node j in the association matrix, the following operations are performed: Delete edge (i, j) from the valid edge list of row i of the association matrix, and update the relevant links and head and tail pointers of the valid edge list; Delete edge (i, j) from the valid edge list of column j of the association matrix, and update the relevant links and head and tail pointers of the valid edge list; Set the element in the i-th row and j-th column of the incidence matrix to 0; If the i-th row of the association matrix is all zero, then the node i is added to the leaf node resource pool, and the relevant links and head and tail pointers of the leaf node linked list are updated; If the jth column of the association matrix is all zero, then node j is added to the root node resource pool, and the related links and head and tail pointers of the root node linked list are updated.
8. The directed graph processing method according to claim 5, characterized in that: The method further comprises: In response to receiving a processing request to add a dynamic node to the directed graph, performing the following operations: According to the dynamic node number of the dynamic node, marking the corresponding resource position in the dynamic node resource pool as occupied; Add the dynamic node at the end of the added node linked list, and update the related links and head and tail pointers of the added node linked list; Deleting the dynamic node from the unadded node linked list, and updating the related links and head and tail pointers of the unadded node linked list; Add the dynamic node to the root node resource pool, and update the relevant links and head and tail pointers of the root node linked list; The dynamic node is added to the leaf node resource pool, and the related links and head and tail pointers of the leaf node linked list are updated.
9. The directed graph processing method according to claim 5, characterized in that: The method further comprises: In response to receiving a processing request to delete a dynamic node from the directed graph, performing the following operations: Determine the number of the dynamic node in the association matrix according to a mapping relationship between the dynamic node number of the dynamic node and the number of the dynamic node in the association matrix; Set the elements of the corresponding rows and columns in the association matrix to 0, and clear the valid edge list; Add the dynamic node at the end of the unadded node linked list, and update the related links and head and tail pointers of the unadded node linked list; Deleting the dynamic node from the added node linked list, and updating the related links and head and tail pointers of the added node linked list; Marking a resource position corresponding to the dynamic node in the dynamic node resource pool as unoccupied; If the dynamic node is in the root node resource pool, deleting the dynamic node from the root node resource pool; If the dynamic node is in the leaf node resource pool, delete the dynamic node from the leaf node resource pool.
10. The directed graph processing method according to claim 5, characterized in that: The method further comprises: In response to receiving a request to traverse subsequent outgoing edges of node i based on a valid edge from node i to node j in the association matrix, the following operations are performed: Traversing subsequent outgoing edges of node i by tracking the valid edge linked list of row i in the association matrix; If node i is a normal node, then the normal node number k of node i is determined according to the mapping relationship between the normal node number and the normal node number in the association matrix, and [spos[k 2+1],spos[k 2+2]) to traverse the edges between them.
11. The directed graph processing method according to claim 5, characterized in that: The method further comprises: In response to receiving a processing request to traverse subsequent incoming edges of node j based on a valid edge from node i to node j in the association matrix, the following operations are performed: Traversing subsequent incoming edges of node j by tracking the valid edge linked list in the j-th column of the association matrix; If node j is a normal node, the normal node number s of node j is determined according to the mapping relationship between the normal node number and the normal node number in the association matrix, and [spos[s 2],spos[s 2+1]) to traverse the edges between them.
12. The directed graph processing method according to claim 5, characterized in that: The method further comprises: In response to receiving a root node traversal request, traverse the root node resource pool and the nodes in the array root; In response to receiving a leaf node traversal request, the leaf node resource pool and the nodes in the leaf array are traversed.
13. The directed graph processing method according to claim 1, characterized in that: The method further comprises: In response to receiving a parallel task scheduling request, an empty task queue is initialized, and the following operations are performed in a loop until the task queue is empty: Traversing the root node, and adding the root node to the task queue; The nodes in the task queue are taken out and scheduled for execution in parallel; wherein, after each task corresponding to a node is executed, the child nodes of the node are traversed, and if the child node has only one parent node, the child node is added to the task queue, and the node that has currently completed the task is deleted; if the child node has two or more parent nodes, only the node that has currently completed the task is deleted.
14. A directed graph processing device, characterized in that: include: A decomposition module is used to decompose a directed graph into a normal subgraph that remains unchanged and a dynamic subgraph that changes at any time; wherein the normal subgraph is a normal structural part that remains unchanged in the directed graph, and the dynamic subgraph is a dynamic structural part that can change at any time in the directed graph; wherein: The nodes in the normal subgraph are normal nodes. For the normal subgraph, the normal node numbers of the normal nodes in the normal node set are given in advance, and the edges connected to each normal node are stored in sequence according to the normal node numbers; wherein, when storing the edges connected to each normal node, the incoming edges are stored first, and then the outgoing edges are stored; The nodes in the dynamic subgraph are dynamic nodes. For the dynamic subgraph, a dynamic node resource pool of added nodes and unadded nodes is maintained, dynamic node numbers in a dynamic node set are assigned to the dynamic nodes, resource positions are assigned in sequence, and a linked list structure is used to manage the deletion of the added nodes and the addition of the unadded nodes; the number of the dynamic nodes is preset; The storage module is used to: save the normal sub-graph and the dynamic sub-graph respectively into different recycling unit groups defined by the customizable data arrangement interface.
15. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the program, the directed graph processing method according to any one of claims 1 to 13 is implemented.
16. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the directed graph processing method according to any one of claims 1 to 13 is implemented.
17. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, the directed graph processing method according to any one of claims 1 to 13 is implemented.
Citation Information
Patent Citations
Parallel graph traversal method for single-source shortest path
CN115049103A
Micro-service division method based on GraphSAGE
CN117608880A