Method for acquiring all paths between any nodes in directed acyclic graph

By acquiring and extending paths in the pathless diagram, the problem that the existing technology cannot obtain all paths is solved, and the automatic acquisition and verification of the path between any node in the ringless graph has been realized, and the evaluation is improved. The verification efficiency and accuracy of the rules.

CN119378773AActive Publication Date: 2025-01-28CHENGDU AIRCRAFT INDUSTRY GROUP

Patent Information

Application Number
CN202411312159.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-20
Publication Date
2025-01-28
Estimated Expiration
2044-09-20

AI Technical Summary

Technical Problem

The prior art cannot automatically obtain all path information in the directed acyclic graph, resulting in the inability to verify the rules corresponding to each path during the complex evaluation process.

Method used

By obtaining all the paths between any node in the ring -free diagram, it is extended to the multi -sources and there is a ringless diagram. The design of the multi -sources is converted into a single source and there is a ring -free diagram. There is a path between any node in the rim without the ring.

Benefits of technology

实现了对有向无环图中任意节点间的所有路径的获取,使得测评规则中网关节点间的校验变得便捷,支持全局规则的有效性校验,提高了校验速度和降低了出错概率。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119378773A_ABST
    Figure CN119378773A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of path search, in particular to a method for acquiring all paths between any nodes in a directed acyclic graph, which comprises the following steps of: setting a given starting point and a given ending point; obtaining an adjacent matrix of the directed acyclic graph; converting the multi-source directed acyclic graph into a single-source directed acyclic graph; solving all paths between an end starting point and an end ending point of the single-source directed acyclic graph, and generating a path list; traversing the path list to obtain an effective path from the path list; deleting nodes before a given starting point and after a given ending point in the effective path; and outputting all path information between the given starting point and the given ending point. According to the technical scheme, the multi-source directed acyclic graph is converted into the single-source directed acyclic graph, the method for obtaining all the paths of the single-source directed acyclic graph is expanded to the multi-source directed acyclic graph for use, on the basis of the method for obtaining all the paths of the single-source directed acyclic graph, obtaining of the paths between any nodes is further achieved, and the method for obtaining all the paths of the single-source directed acyclic graph is more efficient. And the check between the gateway nodes in the evaluation rule becomes convenient.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of path search technology, and in particular to a method for obtaining all paths between arbitrary nodes in a directed acyclic graph. Background Art

[0002] Maintenance training subjects often involve multi-path operations and out-of-order operations. The score of each path between multi-path gateways is required to be the same. The total score between out-of-order operation gateways is equal to the sum of the scores of each path. The evaluation rules are represented by multi-path gateways and out-of-order gateways. When the evaluation rules are compiled, the score of the entire rule needs to be verified. At this time, multi-path operations and out-of-order operations need to be considered. The score of each path between each pair of multi-path operation gateways should be the same, and the score of all operations between each pair of out-of-order operation gateways cannot exceed the limit. In order to verify the gateway, it is necessary to obtain all paths between each pair of gateways and calculate the path score based on the scores of the inspection points in the path.

[0003] In order to obtain all paths between each pair of gateways, it is necessary to abstract the evaluation rules into a directed acyclic graph and then traverse the graph. The depth-first traversal and breadth-first traversal algorithms of the graph can quickly determine whether there is a path between any two nodes, but cannot obtain all paths between two nodes. In the prior art, the invention patent document with publication number CN106919455A discloses a main path filling scheduling method based on a directed acyclic graph. The method selects the main path according to the in-and-out degree of the subtask in the directed acyclic graph, simplifies the parallel tasks involved in the main path into serial tasks, and then obtains the time redundancy of the parallel part. Its defect is that it can only obtain the main path information, and cannot automatically obtain other path information, and the complex evaluation process requires verification of each rule. Therefore, when the complex evaluation rules are abstracted into a directed acyclic graph, only the rules corresponding to the main path can be verified, and all paths cannot be automatically obtained, and the rules corresponding to each path can be verified. Summary of the invention

[0004] The purpose of the present invention is to address the deficiencies of the above-mentioned prior art and propose a method for obtaining all paths between arbitrary nodes in a directed acyclic graph. The method for obtaining all paths between arbitrary nodes in a single-source directed acyclic graph is extended to a multi-source directed acyclic graph, and a method for converting a multi-source directed acyclic graph into a single-source directed acyclic graph is designed, thereby being able to obtain paths between arbitrary nodes in the multi-source directed acyclic graph, thereby being able to obtain all path information between specified nodes in any directed acyclic graph, making the verification between gateway nodes in the evaluation rules convenient, and effectively supporting the verification of the global evaluation rules of maintenance training subjects.

[0005] The above objectives are achieved through the following solutions: A method for obtaining all paths between any nodes in a directed acyclic graph comprises the following steps: S1, set the target node to the given starting point and the given end point respectively; S2, obtaining the adjacency matrix of the directed acyclic graph based on the in-degree and out-degree of each node in the directed acyclic graph; S3, judging whether the directed acyclic graph is a multi-source directed acyclic graph based on the adjacency matrix; if not, directly proceeding to step S4; if so, converting the multi-source directed acyclic graph into a single-source directed acyclic graph, and then proceeding to step S4; S4, solving all paths between the end starting point and the end point of the single-source directed acyclic graph, and generating a path list; S5, traverse the path list and obtain a valid path; S6, delete the nodes before the given starting point and after the given end point in the valid path; S7, output all path information between the given starting point and the given end point.

[0006] Preferably, in step S3, determining whether the directed acyclic graph is a multi-source directed acyclic graph comprises the following steps: S31-1, obtain the number P of nodes with in-degree 0 according to the adjacency matrix; S31-2, obtaining the number Q of nodes with out-degree 0 according to the adjacency matrix; S31-3, if P>1 and / or Q>1, it is determined to be a multi-source directed acyclic graph, otherwise it is determined to be a single-source directed acyclic graph.

[0007] Preferably, in step S3, converting the multi-source directed acyclic graph into a single-source directed acyclic graph comprises the following steps: S32-1, obtaining an adjacency matrix of a multi-source directed acyclic graph; S32-2, obtaining nodes with an in-degree of 0 and nodes with an out-degree of 0 in the multi-source directed acyclic graph based on the adjacency matrix; S32-3, establish a new end starting point and end point, that is, if the number of nodes with in-degree 0 is greater than 1, then establish a new end starting point; if the number of nodes with out-degree 0 is greater than 1, then establish a new end point; S32-4, based on step S33, re-establish the relationship between the nodes to convert the multi-source directed acyclic graph into a single-source directed acyclic graph, and re-establish the adjacency matrix at the same time.

[0008] Preferably, in step S32-3, the method for establishing a new end starting point is: adding a new node in the multi-source directed acyclic graph so that all nodes with original in-degree 0 are adjacent points of the newly added node, and the newly added node is the end starting point.

[0009] Preferably, in step S32-3, the method for establishing a new end point is: adding a new node in the multi-source directed acyclic graph, so that the new node is an adjacent point of all original nodes with an out-degree of 0, and the new node is the end point.

[0010] Preferably, in step S4, solving all paths between the end starting point and the end point of the single-source directed acyclic graph includes the following steps: S4-1, set the global variable path to record the path information, the global variable result to record the set of paths found, and the static variable findRoad to record whether the path is found; S4-2, determining the total number of paths pathNum between the end starting point and the end point; S4-3, initialize the global variable path to empty and the static variable findRoad to False; set i to record the number of times the path is currently searched and initialize it to 1; S4-4, determine whether i is less than pathNum; if so, proceed to step S4-5, if not, proceed to step S4-13; S4-5, obtaining the end starting point and the end point, and starting the traversal with the end starting point as the traversal starting point; S4-6, determine whether the traversal starting point and the end point are the same; if so, proceed to step S4-7, if not, proceed to step S4-12; S4-7, obtain the adjacent points of the traversal starting point, and add the adjacent points to the path to obtain the local path; S4-8, determine whether the local path does not exist in the found path result; if so, proceed to step S4-9, if not, proceed to step S4-10; S4-9, taking the adjacent point as the traversal starting point, the end point remains unchanged, calling steps S46 to S48 to perform recursive calculation; S4-10, after adding the adjacent point to the child list, proceed to step S4-11; S4-11, iterate the child list, take the child value as the traversal starting point, the end point remains unchanged, and steps S46 to S48 perform recursive calculations; S4-12, set findRoad to true, add path to the path set result, set i=i+1, and return to step S4-4; S4-13, output a path set result, where the path set result includes all paths between the end starting point and the end point.

[0011] Preferably, in step S4-2, determining the total number of paths pathNum between the end starting point and the end point includes the following steps: S421, set a static variable pathNum to record the number of paths in the directed acyclic graph, and initialize the static variable pathNum to 1; S422, obtaining the end starting point and the end point, and taking the end starting point as the starting node; S423, determine whether the start node and the end point are the same; if not, proceed to step S424, if not, proceed to step S428; S424, obtaining all adjacent points of the current starting node according to the adjacency matrix, and generating an adjacent point list child, wherein the out-degree len(out) of the current starting node is the length of the adjacent point list child; S425, for the current starting node, the number of newly added paths is represented by len(out)-1, then pathNum=pathNum+len(out)-1; S426, taking the node in the adjacent point list child as the starting node, leaving the end point unchanged, calling steps S423 to S425 to recursively calculate the number of paths; S428, output pathNum is the number of all paths between the end starting point and the end point.

[0012] Preferably, the step S5 is to determine a path including a given starting point and a given end point as a valid path.

[0013] Beneficial technical effects brought by the present invention: The present invention discloses a method for obtaining all paths between any nodes in a directed acyclic graph, which mainly comprises the following steps: obtaining a directed acyclic graph adjacency matrix; judging whether it is a multi-source directed acyclic graph; converting the multi-source directed acyclic graph into a single-source directed acyclic graph; solving the path of the single-source directed acyclic graph; obtaining a valid path according to a given starting point and a given end point and outputting path information. By applying this method in an evaluation rule, it is possible to effectively verify whether all path settings between a multi-path operation gateway and an out-of-order operation gateway meet the requirements, and then verify the validity of the global rule, which is of great significance to improving the verification speed and reducing the error probability, and provides strong support for the construction of complex evaluation rules. BRIEF DESCRIPTION OF THE DRAWINGS

[0014] Figure 1 This is the basic implementation flow chart of this technical solution; Figure 2 To solve the flow chart of all paths between the end starting point and the end end point; Figure 3A flow chart for determining the total number of paths pathNum between the end start point and the end end point; Figure 4 is a schematic diagram of a single-source directed acyclic graph; Figure 5 for Figure 4 Schematic diagram of the adjacency matrix of the single-source directed acyclic graph shown. DETAILED DESCRIPTION

[0015] In order to make the purpose, technical solution and advantages of the invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the drawings in the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all of the embodiments.

[0016] Therefore, the following detailed description of the invention provided in the accompanying drawings is not intended to limit the scope of the invention claimed for protection, but merely represents selected embodiments of the invention. 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.

[0017] Example 1 This embodiment discloses a method for obtaining all paths between any nodes in a directed acyclic graph, as a basic implementation scheme of the present invention. Figure 1 As shown, the following steps are included: S1, set the target nodes to the given starting point and the given end point respectively. This technical solution is to obtain all paths between any nodes, so the target node here refers to two arbitrary nodes selected before and after in the directed acyclic graph as needed.

[0018] S2, based on the in-degree and out-degree of each node in the directed acyclic graph, obtain the adjacency matrix of the directed acyclic graph. Figure 5 As shown, Figure 4 The adjacency matrix of a single-source directed acyclic graph is shown.

[0019] S3, judging whether the directed acyclic graph is a multi-source directed acyclic graph based on the adjacency matrix; if not, directly proceeding to step S4; if so, converting the multi-source directed acyclic graph to a single-source directed acyclic graph, and then proceeding to step S4. Figure 4 The figure shows a single-source directed acyclic graph, where A, B, C, D, E, F, G, H, I, G, and K all represent nodes. Among them, the in-degree of A is 0, indicating the end point; the out-degree of K is 0, indicating the end point, and the others are all intermediate nodes. It can be seen that a single-source directed acyclic graph has only one end point and one end point.

[0020] S4, solve all paths between the end starting point and the end point of the single-source directed acyclic graph, and generate a path list. That is, the generated path list includes all paths between the end starting point and the end point, and of course also includes all paths between a given starting point and a given end point.

[0021] S5, traverse the path list to obtain a valid path. The so-called valid path is the path where the target node is located. Based on this, a path including a given starting point and a given end point can be determined as a valid path.

[0022] S6, delete the nodes before the given starting point and after the given end point in the valid path.

[0023] S7, output all path information between the given starting point and the given end point.

[0024] Example 2 This embodiment discloses a method for obtaining all paths between any nodes in a directed acyclic graph, as a basic implementation scheme of the present invention. Figure 1 As shown, the following steps are included: S1, set the target node to the given starting point and the given end point respectively.

[0025] S2, based on the in-degree and out-degree of each node in the directed acyclic graph, obtain the adjacency matrix of the directed acyclic graph. Figure 5 As shown, Figure 4 The adjacency matrix of a single-source directed acyclic graph is shown.

[0026] S3, based on the adjacency matrix, determine whether the directed acyclic graph is a multi-source directed acyclic graph; if not, directly enter step S4; if so, convert the multi-source directed acyclic graph into a single-source directed acyclic graph, and then enter step S4.

[0027] Among them, Figure 4 It can be seen that a single-source directed acyclic graph has only one end starting point and one end point, and since there are multiple nodes with in-degree 0 and out-degree 0 in a multi-source directed acyclic graph, it is necessary to convert the multi-source directed acyclic graph into a single-source directed acyclic graph, and then apply the path acquisition algorithm of the single-source directed acyclic graph to solve it. Based on this, judging whether a directed acyclic graph is a multi-source directed acyclic graph includes the following steps: S31-1, obtain the number P of nodes with in-degree 0 according to the adjacency matrix.

[0028] S31-2, obtaining the number Q of nodes with out-degree 0 according to the adjacency matrix.

[0029] S31-3, if P>1 and / or Q>1, it is determined to be a multi-source directed acyclic graph, otherwise it is determined to be a single-source directed acyclic graph.

[0030] Furthermore, for a multi-source directed acyclic graph, converting it into a single-source directed acyclic graph includes the following steps: S32-1, obtain the adjacency matrix of the multi-source directed acyclic graph.

[0031] S32-2, based on the adjacency matrix, obtain the nodes with in-degree 0 and the nodes with out-degree 0 in the multi-source directed acyclic graph.

[0032] S32-3, establish a new end starting point and end terminal. That is: if the number of nodes with in-degree 0 is greater than 1, then establish a new end starting point, add a new node in the multi-source directed acyclic graph, so that all the original nodes with in-degree 0 are adjacent points of the newly added node, and the newly added node is the end starting point, so that the directed acyclic graph has only one end starting point with in-degree 0. If the number of nodes with out-degree 0 is greater than 1, then establish a new end terminal, specifically: add a new node in the multi-source directed acyclic graph, so that the newly added node is an adjacent point of all the original nodes with out-degree 0, and the newly added node is the end terminal, so that the directed acyclic graph has only one end terminal with out-degree 0.

[0033] S32-4, based on step S33, re-establish the relationship between the nodes to convert the multi-source directed acyclic graph into a single-source directed acyclic graph, and re-establish the adjacency matrix at the same time.

[0034] S4, solve all paths between the end starting point and the end point of the single-source directed acyclic graph, and generate a path list. That is, the generated path list includes all paths between the end starting point and the end point, and of course also includes all paths between a given starting point and a given end point.

[0035] S5, traverse the path list to obtain a valid path. The so-called valid path is the path where the target node is located. Based on this, a path including a given starting point and a given end point can be determined as a valid path.

[0036] S6, deleting the nodes before the given starting point and after the given end point in the valid path, that is, obtaining all paths between the given starting point and the given end point.

[0037] S7, output all path information between the given starting point and the given end point.

[0038] Example 3 This embodiment discloses a method for obtaining all paths between any nodes in a directed acyclic graph, as a basic implementation scheme of the present invention. Figure 1 As shown, the following steps are included: S1, set the target node to the given starting point and the given end point respectively.

[0039] S2, based on the in-degree and out-degree of each node in the directed acyclic graph, obtain the adjacency matrix of the directed acyclic graph. Figure 5 As shown, Figure 4 The adjacency matrix of a single-source directed acyclic graph is shown.

[0040] S3, based on the adjacency matrix, determine whether the directed acyclic graph is a multi-source directed acyclic graph; if not, directly enter step S4; if so, convert the multi-source directed acyclic graph into a single-source directed acyclic graph, and then enter step S4.

[0041] S4, solve all paths between the end starting point and the end point of the single-source directed acyclic graph, and generate a path list. That is, the generated path list includes all paths between the end starting point and the end point, and of course also includes all paths between a given starting point and a given end point.

[0042] Wherein, solving all paths between the end starting point and the end point of the single-source directed acyclic graph includes the following steps: S4-1, set the global variable path to record the path information, the global variable result to record the set of paths found, and the static variable findRoad to record whether the path is found; S4-2, determining the total number of paths pathNum between the end starting point and the end point; S4-3, initialize the global variable path to empty and the static variable findRoad to False; set i to record the number of times the path is currently searched and initialize it to 1; S4-4, determine whether i is less than pathNum; if so, proceed to step S4-5, if not, proceed to step S4-13; S4-5, obtaining the end starting point and the end point, and starting the traversal with the end starting point as the traversal starting point; S4-6, determine whether the traversal starting point and the end point are the same; if so, proceed to step S4-7, if not, proceed to step S4-12; S4-7, obtain the adjacent points of the traversal starting point, and add the adjacent points to the path to obtain the local path; S4-8, determine whether the local path does not exist in the found path result; if so, proceed to step S4-9, if not, proceed to step S4-10; S4-9, taking the adjacent point as the traversal starting point, the end point remains unchanged, calling steps S46 to S48 to perform recursive calculation; S4-10, after adding the adjacent point to the child list, proceed to step S4-11; S4-11, iterate the child list, take the child value as the traversal starting point, the end point remains unchanged, and steps S46 to S48 perform recursive calculations; S4-12, set findRoad to true, add path to the path set result, set i=i+1, and return to step S4-4; S4-13, output a path set result, where the path set result includes all paths between the end starting point and the end point.

[0043] S5, traverse the path list to obtain a valid path. The so-called valid path is the path where the target node is located. Based on this, a path including a given starting point and a given end point can be determined as a valid path.

[0044] S6, delete the nodes before the given starting point and after the given end point in the valid path.

[0045] S7, output all path information between the given starting point and the given end point.

[0046] In this technical solution, the number of paths between the end starting point and the end point in the directed acyclic graph is obtained, and the number of paths is used as the threshold (i.e., the upper limit of the number of loops) to perform a depth-first traversal of the directed acyclic graph, and obtain a path in each loop. The traversal process involves two recursions: the first recursion starts from the nearest neighbor point, with the goal of finding the path as quickly as possible; the second recursion aims to ensure that a new path is found by exhaustive enumeration when the first recursion fails to find a new path.

[0047] Example 4 This embodiment discloses a method for obtaining all paths between any nodes in a directed acyclic graph, as a basic implementation scheme of the present invention. Figure 1 As shown, the following steps are included: S1, set the target node to the given starting point and the given end point respectively.

[0048] S2, based on the in-degree and out-degree of each node in the directed acyclic graph, obtain the adjacency matrix of the directed acyclic graph. Figure 5 As shown, Figure 4 The adjacency matrix of a single-source directed acyclic graph is shown.

[0049] S3, based on the adjacency matrix, determine whether the directed acyclic graph is a multi-source directed acyclic graph; if not, directly enter step S4; if so, convert the multi-source directed acyclic graph into a single-source directed acyclic graph, and then enter step S4.

[0050] S4, solve all paths between the end starting point and the end point of the single-source directed acyclic graph, and generate a path list. That is, the generated path list includes all paths between the end starting point and the end point, and of course also includes all paths between a given starting point and a given end point.

[0051] Wherein, solving all paths between the end starting point and the end point of the single-source directed acyclic graph includes the following steps: S4-1, set the global variable path to record the path information, the global variable result to record the set of paths found, and the static variable findRoad to record whether the path is found.

[0052] S4-2, determining the total number of paths pathNum between the end starting point and the end point, including the following steps: S421, set a static variable pathNum to record the number of paths in the directed acyclic graph, and initialize the static variable pathNum to 1.

[0053] S422, obtaining the end starting point and the end end point, and taking the end starting point as the starting node.

[0054] S423, determine whether the starting node and the end point are the same; if not, proceed to step S424, if not, proceed to step S428.

[0055] S424, obtaining all adjacent points of the current starting node according to the adjacency matrix, and generating an adjacent point list child, wherein the out-degree len(out) of the current starting node is the length of the adjacent point list child.

[0056] S425, for the current starting node, the number of newly added paths is represented as len(out)-1, then pathNum=pathNum+len(out)-1.

[0057] S426, taking the node in the adjacent point list child as the starting node, leaving the end point unchanged, calling steps S423 to S425 to recursively calculate the number of paths.

[0058] S428, output pathNum is the number of all paths between the end starting point and the end point.

[0059] S4-3, initialize the global variable path to empty and the static variable findRoad to False; set i to record the number of times the path is currently searched and initialize it to 1.

[0060] S4-4, determine whether i is less than pathNum; if so, proceed to step S4-5, if not, proceed to step S4-13.

[0061] S4-5, obtaining the end starting point and the end end point, and starting the traversal with the end starting point as the traversal starting point.

[0062] S4-6, determine whether the traversal starting point and the end point are the same; if so, proceed to step S4-7, if not, proceed to step S4-12.

[0063] S4-7, obtain the adjacent points of the traversal starting point, and add the adjacent points to the path to obtain the local path.

[0064] S4-8, determine whether the local path does not exist in the found path result; if so, proceed to step S4-9, if not, proceed to step S4-10.

[0065] S4-9, taking the adjacent point as the traversal starting point, the end point remains unchanged, and calling steps S46 to S48 to perform recursive calculation.

[0066] S4-10, after adding the adjacent points to the child list, proceed to step S4-11.

[0067] S4-11, iterate the child list, use the child value as the traversal starting point, and the end point remains unchanged. Steps S46 to S48 perform recursive calculations.

[0068] S4-12, set findRoad to true, add path to the path set result, set i=i+1, and return to step S4-4.

[0069] S4-13, output a path set result, where the path set result includes all paths between the end starting point and the end point.

[0070] S5, traverse the path list to obtain a valid path. The so-called valid path is the path where the target node is located. Based on this, a path including a given starting point and a given end point can be determined as a valid path.

[0071] S6, delete the nodes before the given starting point and after the given end point in the valid path.

[0072] S7, output all path information between the given starting point and the given end point.

Claims

1. A method for obtaining all paths between any nodes in a directed acyclic graph, characterized in that: The following steps are involved: S1, set the target node to the given starting point and the given end point respectively; S2, obtaining the adjacency matrix of the directed acyclic graph based on the in-degree and out-degree of each node in the directed acyclic graph; S3, judging whether the directed acyclic graph is a multi-source directed acyclic graph based on the adjacency matrix; if not, directly proceeding to step S4; if yes, converting the multi-source directed acyclic graph into a single-source directed acyclic graph, and then proceeding to step S4; S4, solving all paths between the end starting point and the end point of the single-source directed acyclic graph, and generating a path list; S5, traverse the path list and obtain a valid path; S6, delete the nodes before the given starting point and after the given end point in the valid path; S7, output all path information between the given starting point and the given end point.

2. A method for obtaining all paths between any nodes in a directed acyclic graph as claimed in claim 1, characterized in that: In step S3, determining whether the directed acyclic graph is a multi-source directed acyclic graph comprises the following steps: S31-1, obtain the number P of nodes with in-degree 0 according to the adjacency matrix; S31-2, obtaining the number Q of nodes with out-degree 0 according to the adjacency matrix; S31-3, if P>1 and / or Q>1, it is determined to be a multi-source directed acyclic graph, otherwise it is determined to be a single-source directed acyclic graph.

3. A method for obtaining all paths between any nodes in a directed acyclic graph as claimed in claim 1, characterized in that: In step S3, converting the multi-source directed acyclic graph into a single-source directed acyclic graph comprises the following steps: S32-1, obtaining an adjacency matrix of a multi-source directed acyclic graph; S32-2, obtaining nodes with an in-degree of 0 and nodes with an out-degree of 0 in the multi-source directed acyclic graph based on the adjacency matrix; S32-3, establish a new end starting point and end point, that is, if the number of nodes with in-degree 0 is greater than 1, then establish a new end starting point; if the number of nodes with out-degree 0 is greater than 1, then establish a new end point; S32-4, based on step S33, re-establish the relationship between the nodes to convert the multi-source directed acyclic graph into a single-source directed acyclic graph, and re-establish the adjacency matrix at the same time.

4. A method for obtaining all paths between any nodes in a directed acyclic graph as claimed in claim 3, characterized in that: In step S32-3, the method for establishing a new end starting point is: adding a new node in the multi-source directed acyclic graph so that all nodes with original in-degree 0 are adjacent points of the newly added node, and the newly added node is the end starting point.

5. A method for obtaining all paths between any nodes in a directed acyclic graph as claimed in claim 3, characterized in that: In step S32-3, the method for establishing a new end point is: adding a node in the multi-source directed acyclic graph, so that the newly added node is an adjacent point of all the original nodes with an out-degree of 0, and the newly added node is the end point.

6. A method for obtaining all paths between any nodes in a directed acyclic graph as claimed in claim 1, characterized in that: In step S4, solving all paths between the end starting point and the end point of the single-source directed acyclic graph includes the following steps: S4-1, set the global variable path to record the path information, the global variable result to record the set of paths found, and the static variable findRoad to record whether the path is found; S4-2, determining the total number of paths pathNum between the end starting point and the end point; S4-3, initialize the global variable path to empty and the static variable findRoad to False; set i to record the number of times the path is currently searched and initialize it to 1; S4-4, determine whether i is less than pathNum; if so, proceed to step S4-5, if not, proceed to step S4-13; S4-5, obtaining the end starting point and the end point, and starting the traversal with the end starting point as the traversal starting point; S4-6, determine whether the traversal starting point and the end point are the same; if so, proceed to step S4-7, if not, proceed to step S4-12; S4-7, obtain the adjacent points of the traversal starting point, and add the adjacent points to the path to obtain the local path; S4-8, determine whether the local path does not exist in the found path result; if so, proceed to step S4-9, if not, proceed to step S4-10; S4-9, taking the adjacent point as the traversal starting point, the end point remains unchanged, calling steps S46 to S48 to perform recursive calculation; S4-10, after adding the adjacent point to the child list, proceed to step S4-11; S4-11, iterate the child list, take the child value as the traversal starting point, the end point remains unchanged, and steps S46 to S48 perform recursive calculations; S4-12, set findRoad to true, add path to the path set result, set i=i+1, and return to step S4-4; S4-13, output a path set result, where the path set result includes all paths between the end starting point and the end point.

7. A method for obtaining all paths between any nodes in a directed acyclic graph as claimed in claim 6, characterized in that: In the step S4-2, determining the total number of paths pathNum between the end starting point and the end point includes the following steps: S421, set a static variable pathNum to record the number of paths in the directed acyclic graph, and initialize the static variable pathNum to 1; S422, obtaining the end starting point and the end point, and taking the end starting point as the starting node; S423, determine whether the start node and the end point are the same; if not, proceed to step S424, if not, proceed to step S428; S424, obtaining all adjacent points of the current starting node according to the adjacency matrix, and generating an adjacent point list child, wherein the out-degree len(out) of the current starting node is the length of the adjacent point list child; S425, for the current starting node, the number of newly added paths is represented by len(out)-1, then pathNum=pathNum+len(out)-1; S426, taking the node in the adjacent point list child as the starting node, leaving the end point unchanged, calling steps S423 to S425 to recursively calculate the number of paths; S428, output pathNum is the number of all paths between the end starting point and the end point.

8. A method for obtaining all paths between any nodes in a directed acyclic graph as claimed in claim 1, characterized in that: The step S5 is to determine the path including the given starting point and the given end point as a valid path.

Citation Information

Patent Citations

  • Method for main path filling dispatching based on directed acyclic graph

    CN106919455A

  • Method, device and system for determining reachable path between two points

    CN110319845A

  • Method and device for verifying ring of directed acyclic graph, electronic equipment and storage medium

    CN113672369A

  • Directed acyclic graph generation method, network coding method and network transmission method

    CN114124722A

  • Network topological graph path acquisition system and method

    CN117240771A

Cited By

  • Flow chart layered layout method and layout system

    CN122473300A