A method for obtaining all paths between any nodes in a directed acyclic graph

By obtaining the adjacency matrix of a directed acyclic graph and converting it into a single-source graph, all paths between any nodes in the directed acyclic graph are solved, which solves the problem that existing technologies cannot fully verify paths and improves the efficiency and accuracy of global assessment of aircraft maintenance training subjects.

CN119378773BActive Publication Date: 2025-11-11CHENGDU AIRCRAFT INDUSTRY GROUP
View PDF 3 Cites 0 Cited by

Patent Information

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

AI Technical Summary

Technical Problem

Existing technologies cannot effectively obtain all paths between any nodes in a directed acyclic graph, making it impossible to fully verify the rules corresponding to each path in complex evaluation rules, which affects the efficiency and accuracy of the overall evaluation and verification of aircraft maintenance training subjects.

Method used

By obtaining the adjacency matrix of a single-source directed acyclic graph, it is determined whether the directed acyclic graph is a multi-source graph, and it is converted into a single-source graph. The single-source directed acyclic graph algorithm is used to solve all paths between the starting point and the ending point of the end, generate a path list and output the valid paths.

Benefits of technology

It enables the acquisition of all paths between any nodes in a directed acyclic graph, improves the comprehensiveness and accuracy of evaluation rule verification, reduces the probability of errors, and supports the effective verification of global rules for aircraft maintenance training subjects.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119378773B_ABST
    Figure CN119378773B_ABST
Patent Text Reader

Abstract

The present application relates to the technical field of path search, in particular to a method for obtaining all paths between any nodes in a directed acyclic graph, comprising setting a given starting point and a given end point; obtaining an adjacency matrix of the directed acyclic graph; converting the multi-source directed acyclic graph into a single-source directed acyclic graph; solving all paths between the end starting point and the end end point of the single-source directed acyclic graph and generating a path list; traversing the path list to obtain valid paths therefrom; deleting nodes before the given starting point and after the given end point in the valid paths; and outputting all path information between the given starting point and the given end point. The technical solution converts the multi-source directed acyclic graph into a single-source directed acyclic graph, realizes the expansion of the method for obtaining all paths of the single-source directed acyclic graph to the multi-source directed acyclic graph, and further realizes the acquisition of paths between any nodes based on the method for obtaining all paths of the single-source directed acyclic graph, so that the verification between gateway nodes in the evaluation rules becomes convenient.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

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

[0002] Aircraft maintenance training frequently involves multi-path operations and unordered operations. In multi-path operations, each path between gateways must receive the same score. In unordered operations, the total score between gateways equals the sum of the scores for each path. The evaluation rules use multi-path gateways and unordered gateways to represent these. Once the evaluation rules are developed, the overall score needs to be validated. This requires considering both multi-path and unordered operations. For each pair of multi-path gateways, the score for each path should be the same, and for each pair of unordered gateways, the total score for all operations must not exceed the limit. To validate the gateways, all paths between each pair of gateways need to be obtained, and the path score is calculated based on the scores of the assessment points within each path.

[0003] To obtain all paths between each pair of gateways, the evaluation rules need to be abstracted into a directed acyclic graph (DAG) and then traversed. Depth-first search (DFS) and breadth-first search (BFS) algorithms can quickly determine if a path exists between any two nodes, but they cannot obtain all paths between two nodes. In the prior art, patent document CN106919455A discloses a main path filling scheduling method based on a DAG. This method selects the main path based on the in-degree and out-degree of subtasks in the DAG, simplifying the parallel tasks involved in the main path into serial tasks, thus obtaining time redundancy for the parallel part. Its drawback is that it can only obtain main path information and cannot automatically obtain information about other paths. Since complex evaluation processes require verification of each rule, when the complex evaluation rules are abstracted into a DAG, only the rules corresponding to the main path can be verified, and it is not possible to automatically obtain all paths and verify the rules corresponding to each path. Summary of the Invention

[0004] The purpose of this invention is to address the shortcomings of the prior art by proposing a method for obtaining all paths between any nodes in a directed acyclic graph (DAG). This method, which obtains all paths between any nodes in a single-source DAG, is then extended to multi-source DAGs. A method for converting a multi-source DAG into a single-source DAG is designed, thereby enabling the acquisition of paths between any nodes in a multi-source DAG. This allows for the acquisition of all path information between specified nodes in any DAG, facilitating the verification of gateway nodes in evaluation rules and effectively supporting the verification of global evaluation rules for aircraft maintenance training subjects.

[0005] The above objectives will be achieved through the following specific methods:

[0006] A method for obtaining all paths between any nodes in a directed acyclic graph includes the following steps:

[0007] S1, set the target nodes as the given start point and the given end point respectively;

[0008] S2, obtain the adjacency matrix of the directed acyclic graph based on the in-degree and out-degree of each node in the directed acyclic graph;

[0009] S3. Determine whether the directed acyclic graph is a multi-source directed acyclic graph based on the adjacency matrix; if not, proceed directly to step S4; if so, convert the multi-source directed acyclic graph into a single-source directed acyclic graph before proceeding to step S4.

[0010] S4, solve for all paths between the start and end points of a single-source directed acyclic graph and generate a list of paths;

[0011] S5, Traverse the path list and obtain the valid paths from it;

[0012] S6, Delete the nodes before the given starting point and after the given ending point in the valid path;

[0013] S7 outputs all path information between a given starting point and a given ending point.

[0014] In the preferred step S3, determining whether a directed acyclic graph is a multi-source directed acyclic graph includes the following steps:

[0015] S31-1, Obtain the number P of nodes with an in-degree of 0 based on the adjacency matrix;

[0016] S31-2, obtain the number Q of nodes with an out-degree of 0 based on the adjacency matrix;

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

[0018] Preferably, in step S3, converting a multi-source directed acyclic graph into a single-source directed acyclic graph includes the following steps:

[0019] S32-1, Obtain the adjacency matrix of a multi-source directed acyclic graph;

[0020] S32-2, Obtaining nodes with in-degree 0 and out-degree 0 in a multi-source directed acyclic graph based on the adjacency matrix;

[0021] S32-3, establish new endpoints and end points, that is: if the number of nodes with an in-degree of 0 is greater than 1, then establish a new endpoint; if the number of nodes with an out-degree of 0 is greater than 1, then establish a new end point.

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

[0023] Preferably, in step S32-3, the method for establishing a new end point is as follows: add a new node in the multi-source directed acyclic graph, such that all nodes with an original in-degree of 0 are adjacent to the new node, and the new node is the end point.

[0024] Preferably, in step S32-3, the method for establishing a new endpoint is as follows: add a new node in the multi-source directed acyclic graph, such that the new node is the adjacent node of all the original nodes with an out-degree of 0, and the new node is the endpoint.

[0025] Preferably, in step S4, solving for all paths between the starting and ending points of a single-source directed acyclic graph includes the following steps:

[0026] S4-1, set the global variable path to record path information, the global variable result to record the set of found paths, and the static variable findRoad to record whether a path has been found;

[0027] S4-2, determine the total number of paths pathNum between the starting point and the ending point of the end;

[0028] S4-3, initialize the global variable path to null and the static variable findRoad to False; set i to record the current path search count and initialize it to 1;

[0029] S4-4, determine if i is less than pathNum; if yes, proceed to step S4-5; otherwise, proceed to step S4-13.

[0030] S4-5: Obtain the start and end points of the traversal, and start the traversal with the start point of the traversal as the starting point of the traversal.

[0031] S4-6, Determine whether the starting point and the ending point of the traversal are the same; if yes, proceed to step S4-7; if no, proceed to step S4-12.

[0032] S4-7: Obtain the adjacent nodes of the traversal starting point and add the adjacent nodes to the path to obtain the local path;

[0033] S4-8, Determine if the local path does not exist in the already found path result; if yes, proceed to step S4-9; otherwise, proceed to step S4-10.

[0034] S4-9, with the adjacent point as the starting point of the traversal and the end point unchanged, call steps S46 to S48 to perform recursive calculation;

[0035] S4-10, After adding the adjacent point to the child list, proceed to step S4-11;

[0036] S4-11, iterate through the child list, starting with the child value as the traversal start point, keeping the end and endpoint unchanged. Steps S46 to S48 perform recursive calculations.

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

[0038] S4-13, Output path set result, which contains all paths between the start point and the end point.

[0039] Preferably, in step S4-2, determining the total number of paths, pathNum, between the starting point and the ending point includes the following steps:

[0040] S421, Set the static variable pathNum to record the number of paths in the directed acyclic graph, and initialize the static variable pathNum to 1;

[0041] S422, obtain the end start point and end end point, and use the end start point as the start node;

[0042] 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;

[0043] S424: Obtain all adjacent nodes of the current starting node based on the adjacency matrix and generate an adjacency list child. The out-degree len(out) of the current starting node is the length of the adjacency list child.

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

[0045] S426, using the nodes in the adjacent node list child as the starting node, with the end and ending points unchanged, call steps S423~S425 to recursively calculate the number of paths;

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

[0047] Preferably, step S5 is to determine the path containing a given starting point and a given ending point as a valid path.

[0048] The beneficial technical effects of this invention are as follows:

[0049] This invention discloses a method for obtaining all paths between any nodes in a directed acyclic graph (DAG), mainly comprising the following steps: obtaining the adjacency matrix of the DAG; determining whether it is a multi-source DAG; converting the multi-source DAG into a single-source DAG; solving for paths in the single-source DAG; obtaining valid paths based on a given starting point and a given ending point, and outputting path information. By applying this method to evaluation rules, it is possible to effectively verify whether the path settings between multi-path operation gateways and unordered operation gateways meet the requirements, thereby verifying the validity of global rules. This is significant for improving verification speed and reducing the probability of errors, and provides strong support for the construction of complex evaluation rules. Attached Figure Description

[0050] Figure 1 This is a basic implementation flowchart of the technical solution;

[0051] Figure 2 A flowchart for solving all paths between the end start point and the end point;

[0052] Figure 3 A flowchart for determining the total number of paths, pathNum, between the start and end points of an endpoint;

[0053] Figure 4 This is a schematic diagram of a single-source directed acyclic graph;

[0054] Figure 5 for Figure 4 The diagram shows the adjacency matrix of a single-source directed acyclic graph. Detailed Implementation

[0055] To make the purpose, technical solution and advantages of the invention clearer, the technical solution of the invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are some embodiments of the invention, but not all embodiments.

[0056] Therefore, the following detailed description of the invention provided in the accompanying drawings is not intended to limit the scope of the claimed invention, but merely to illustrate selected embodiments of the invention. All other embodiments obtained by those skilled in the art based on the embodiments of the invention without inventive effort are within the scope of protection of the invention.

[0057] Example 1

[0058] This embodiment discloses a method for obtaining all paths between any nodes in a directed acyclic graph, as a basic implementation of the present invention, such as... Figure 1 As shown, it includes the following steps:

[0059] S1 sets the target nodes as the given start point and the given end point, respectively. This technical solution obtains all paths between any nodes; therefore, the target nodes here refer to two arbitrary nodes selected from the directed acyclic graph as needed.

[0060] S2, obtains the adjacency matrix of the directed acyclic graph (DAG) based on the in-degree and out-degree of each node. For example... Figure 5 As shown, this is Figure 4 The diagram shows an adjacency matrix for a single-source directed acyclic graph.

[0061] S3: Determine whether the directed acyclic graph (DAG) is a multi-source DAG based on the adjacency matrix; if not, proceed directly to step S4; if so, convert the multi-source DAG into a single-source DAG before proceeding to step S4. Figure 4 The diagram shows a single-source directed acyclic graph (DAG), where A, B, C, D, E, F, G, H, I, G, and K represent nodes. A has an in-degree of 0, representing the starting point; K has an out-degree of 0, representing the ending point; and the others are intermediate nodes. It is evident that a single-source DAG has only one starting point and one ending point.

[0062] S4 solves for all paths between the starting and ending points of a single-source directed acyclic graph and generates a path list. That is, the generated path list contains all paths between the starting and ending points of each end, and also all paths between a given starting point and a given ending point.

[0063] S5: Traverse the path list and obtain valid paths. A valid path is the path containing the target node. Based on this, a path containing a given start point and a given end point can be determined as a valid path.

[0064] S6, delete nodes before a given starting point and after a given ending point in a valid path.

[0065] S7 outputs all path information between a given starting point and a given ending point.

[0066] Example 2

[0067] This embodiment discloses a method for obtaining all paths between any nodes in a directed acyclic graph, as a basic implementation of the present invention, such as... Figure 1 As shown, it includes the following steps:

[0068] S1 sets the target nodes as the given start point and the given end point, respectively.

[0069] S2, obtains the adjacency matrix of the directed acyclic graph (DAG) based on the in-degree and out-degree of each node. For example... Figure 5 As shown, this is Figure 4 The diagram shows an adjacency matrix for a single-source directed acyclic graph.

[0070] S3. Determine whether the directed acyclic graph is a multi-source directed acyclic graph based on the adjacency matrix. If not, proceed directly to step S4. If so, convert the multi-source directed acyclic graph into a single-source directed acyclic graph before proceeding to step S4.

[0071] Among them, by Figure 4 It can be seen that a single-source directed acyclic graph (DAG) has only one starting point and one ending point. However, since a multi-source DAG contains multiple nodes with in-degree and out-degree of 0, it is necessary to convert the multi-source DAG into a single-source DAG and then apply a pathfinding algorithm for single-source DAGs. Therefore, determining whether a directed acyclic graph is a multi-source DAG includes the following steps:

[0072] S31-1, obtain the number P of nodes with an in-degree of 0 based on the adjacency matrix.

[0073] S31-2, obtain the number Q of nodes with an out-degree of 0 based on the adjacency matrix.

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

[0075] Furthermore, for a multi-source directed acyclic graph, converting it into a single-source directed acyclic graph includes the following steps:

[0076] S32-1, obtain the adjacency matrix of a multi-source directed acyclic graph.

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

[0078] S32-3, Establish new endpoints and end points. Specifically: If the number of nodes with an in-degree of 0 is greater than 1, establish a new endpoint by adding a node to the multi-source directed acyclic graph, making all original nodes with an in-degree of 0 adjacent to the new node. This new node becomes the endpoint, and the directed acyclic graph then has only one endpoint with an in-degree of 0. If the number of nodes with an out-degree of 0 is greater than 1, establish a new endpoint. Specifically: add a node to the multi-source directed acyclic graph, making the new node adjacent to all original nodes with an out-degree of 0. This new node becomes the endpoint, and the directed acyclic graph then has only one endpoint with an out-degree of 0.

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

[0080] S4 solves for all paths between the starting and ending points of a single-source directed acyclic graph and generates a path list. That is, the generated path list contains all paths between the starting and ending points of each end, and also all paths between a given starting point and a given ending point.

[0081] S5: Traverse the path list and obtain valid paths. A valid path is the path containing the target node. Based on this, a path containing a given start point and a given end point can be determined as a valid path.

[0082] S6: Delete the nodes before the given starting point and after the given ending point from the valid paths, thus obtaining all paths between the given starting point and the given ending point.

[0083] S7 outputs all path information between a given starting point and a given ending point.

[0084] Example 3

[0085] This embodiment discloses a method for obtaining all paths between any nodes in a directed acyclic graph, as a basic implementation of the present invention, such as... Figure 1 As shown, it includes the following steps:

[0086] S1 sets the target nodes as the given start point and the given end point, respectively.

[0087] S2, obtains the adjacency matrix of the directed acyclic graph (DAG) based on the in-degree and out-degree of each node. For example... Figure 5 As shown, this is Figure 4 The diagram shows an adjacency matrix for a single-source directed acyclic graph.

[0088] S3. Determine whether the directed acyclic graph is a multi-source directed acyclic graph based on the adjacency matrix. If not, proceed directly to step S4. If so, convert the multi-source directed acyclic graph into a single-source directed acyclic graph before proceeding to step S4.

[0089] S4 solves for all paths between the starting and ending points of a single-source directed acyclic graph and generates a path list. That is, the generated path list contains all paths between the starting and ending points of each end, and also all paths between a given starting point and a given ending point.

[0090] Solving for all paths between the start and end points of a single-source directed acyclic graph includes the following steps:

[0091] S4-1, set the global variable path to record path information, the global variable result to record the set of found paths, and the static variable findRoad to record whether a path has been found;

[0092] S4-2, determine the total number of paths pathNum between the starting point and the ending point of the end;

[0093] S4-3, initialize the global variable path to null and the static variable findRoad to False; set i to record the current path search count and initialize it to 1;

[0094] S4-4, determine if i is less than pathNum; if yes, proceed to step S4-5; otherwise, proceed to step S4-13.

[0095] S4-5: Obtain the start and end points of the traversal, and start the traversal with the start point of the traversal as the starting point of the traversal.

[0096] S4-6, Determine whether the starting point and the ending point of the traversal are the same; if yes, proceed to step S4-7; if no, proceed to step S4-12.

[0097] S4-7: Obtain the adjacent nodes of the traversal starting point and add the adjacent nodes to the path to obtain the local path;

[0098] S4-8, Determine if the local path does not exist in the already found path result; if yes, proceed to step S4-9; otherwise, proceed to step S4-10.

[0099] S4-9, with the adjacent point as the starting point of the traversal and the end point unchanged, call steps S46 to S48 to perform recursive calculation;

[0100] S4-10, After adding the adjacent point to the child list, proceed to step S4-11;

[0101] S4-11, iterate through the child list, starting with the child value as the traversal start point, keeping the end and endpoint unchanged. Steps S46 to S48 perform recursive calculations.

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

[0103] S4-13, Output path set result, which contains all paths between the start point and the end point.

[0104] S5: Traverse the path list and obtain valid paths. A valid path is the path containing the target node. Based on this, a path containing a given start point and a given end point can be determined as a valid path.

[0105] S6, delete nodes before a given starting point and after a given ending point in a valid path.

[0106] S7 outputs all path information between a given starting point and a given ending point.

[0107] In this technical solution, the number of paths between the starting and ending points of a directed acyclic graph (DAG) is obtained. Using this number of paths as a threshold (i.e., the upper limit of the number of iterations), a depth-first traversal is performed on the DAG, obtaining one path in each iteration. The traversal process involves two recursions: the first recursion starts with the nearest neighbor and aims to find a path as quickly as possible; the second recursion aims to ensure a new path is found through exhaustive search if the first recursion fails to find one.

[0108] Example 4

[0109] This embodiment discloses a method for obtaining all paths between any nodes in a directed acyclic graph, as a basic implementation of the present invention, such as... Figure 1 As shown, it includes the following steps:

[0110] S1 sets the target nodes as the given start point and the given end point, respectively.

[0111] S2, obtains the adjacency matrix of the directed acyclic graph (DAG) based on the in-degree and out-degree of each node. For example... Figure 5 As shown, this is Figure 4 The diagram shows an adjacency matrix for a single-source directed acyclic graph.

[0112] S3. Determine whether the directed acyclic graph is a multi-source directed acyclic graph based on the adjacency matrix. If not, proceed directly to step S4. If so, convert the multi-source directed acyclic graph into a single-source directed acyclic graph before proceeding to step S4.

[0113] S4 solves for all paths between the starting and ending points of a single-source directed acyclic graph and generates a path list. That is, the generated path list contains all paths between the starting and ending points of each end, and also all paths between a given starting point and a given ending point.

[0114] Solving for all paths between the start and end points of a single-source directed acyclic graph includes the following steps:

[0115] S4-1, set the global variable path to record path information, the global variable result to record the set of found paths, and the static variable findRoad to record whether a path has been found.

[0116] S4-2, determine the total number of paths, pathNum, between the starting point and the ending point, including the following steps:

[0117] S421, Set the static variable pathNum to record the number of paths in the directed acyclic graph, and initialize the static variable pathNum to 1.

[0118] S422, obtain the end start point and end end point, and use the end start point as the starting node.

[0119] 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.

[0120] S424: Obtain all adjacent nodes of the current starting node based on the adjacency matrix and generate an adjacency list child. The out-degree len(out) of the current starting node is the length of the adjacency list child.

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

[0122] S426, using the nodes in the adjacent node list child as the starting node, with the end and ending nodes unchanged, call steps S423 to S425 to recursively calculate the number of paths.

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

[0124] S4-3, initialize the global variable path to empty and the static variable findRoad to False; set i to record the current number of paths searched and initialize it to 1.

[0125] S4-4, determine if i is less than pathNum; if yes, proceed to step S4-5; otherwise, proceed to step S4-13.

[0126] S4-5: Obtain the start and end points of the traversal, and start the traversal with the start point of the traversal as the starting point of the traversal.

[0127] S4-6, determine whether the starting point and the ending point of the traversal are the same; if yes, proceed to step S4-7; if no, proceed to step S4-12.

[0128] S4-7: Obtain the adjacent nodes of the traversal starting point and add the adjacent nodes to the path to obtain the local path.

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

[0130] S4-9: Starting from the adjacent point and keeping the end point unchanged, call steps S46 to S48 to perform recursive calculation.

[0131] S4-10: After adding the adjacent node to the child list, proceed to step S4-11.

[0132] S4-11, iterate through the child list, starting with the child value as the traversal start point, keeping the end points unchanged, and perform recursive calculations in steps S46 to S48.

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

[0134] S4-13, Output path set result, which contains all paths between the start point and the end point.

[0135] S5: Traverse the path list and obtain valid paths. A valid path is the path containing the target node. Based on this, a path containing a given start point and a given end point can be determined as a valid path.

[0136] S6, delete nodes before a given starting point and after a given ending point in a valid path.

[0137] S7 outputs all path information between a given starting point and a given ending point.

Claims

1. A method for obtaining all paths between any nodes in a directed acyclic graph, used for obtaining paths between gateway nodes in aircraft maintenance training subject assessment rules to support the verification of assessment rules, characterized in that... Includes the following steps: S1, set the target nodes as the given start point and the given end point respectively; S2, obtain 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. Determine whether the directed acyclic graph is a multi-source directed acyclic graph based on the adjacency matrix; if not, proceed directly to step S4; if so, convert the multi-source directed acyclic graph into a single-source directed acyclic graph before proceeding to step S4. S4, solve for all paths between the starting and ending points of a single-source directed acyclic graph and generate a path list; wherein, solving for all paths between the starting and ending points of a single-source directed acyclic graph includes the following steps: S4-1, set the global variable path to record path information, the global variable result to record the set of found paths, and the static variable findRoad to record whether a path has been found; S4-2, determine the total number of paths pathNum between the starting point and the ending point of the end; S4-3, initialize the global variable path to null and the static variable findRoad to False; set i to record the current path search count and initialize it to 1; S4-4, determine if i is less than pathNum; if yes, proceed to step S4-5; otherwise, proceed to step S4-13. S4-5: Obtain the start and end points of the traversal, and start the traversal with the start point of the traversal as the starting point of the traversal. S4-6, Determine whether the starting point and the ending point of the traversal are the same; if yes, proceed to step S4-7; if no, proceed to step S4-12. S4-7: Obtain the adjacent nodes of the traversal starting point and add the adjacent nodes to the path to obtain the local path; S4-8, Determine if the local path does not exist in the already found path result; if yes, proceed to step S4-9; otherwise, proceed to step S4-10. S4-9, with the adjacent point as the starting point of the traversal and the end point unchanged, call 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 through the child list, starting with the child value as the traversal start point, keeping the end and endpoint unchanged. 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 path set result, which contains all paths between the start point and the end point of the end; S5, Traverse the path list and obtain the valid paths from it; S6, Delete the nodes before the given starting point and after the given ending point in the valid path; S7 outputs all path information between a given starting point and a given ending point.

2. The method for obtaining all paths between any nodes in a directed acyclic graph as described in claim 1, characterized in that, In step S3, determining 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 an in-degree of 0 based on the adjacency matrix; S31-2, obtain the number Q of nodes with an out-degree of 0 based on the adjacency matrix; S31-3, if P > 1 and / or Q > 1, then it is determined to be a multi-source directed acyclic graph; otherwise, it is determined to be a single-source directed acyclic graph.

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

4. The method for obtaining all paths between any nodes in a directed acyclic graph as described in claim 3, characterized in that, In step S32-3, the method for establishing a new end point is as follows: add a new node in the multi-source directed acyclic graph, such that all nodes with an original in-degree of 0 are adjacent to the new node, and the new node is the end point.

5. The method for obtaining all paths between any nodes in a directed acyclic graph as described in claim 3, characterized in that, In step S32-3, the method for establishing a new endpoint is as follows: add a new node in the multi-source directed acyclic graph, such that the new node is the adjacent node of all the original nodes with an out-degree of 0, and the new node is the endpoint.

6. The method for obtaining all paths between any nodes in a directed acyclic graph as described in claim 1, characterized in that, In step S4-2, determining the total number of paths, pathNum, between the starting point and the ending point includes the following steps: S421, Set the static variable pathNum to record the number of paths in the directed acyclic graph, and initialize the static variable pathNum to 1; S422, obtain the end start point and end end point, and use the end start point as the start node; 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; S424: Obtain all adjacent nodes of the current starting node based on the adjacency matrix and generate an adjacency list child. The out-degree len(out) of the current starting node is the length of the adjacency list child. S425, for the current starting node, the number of newly added paths is represented as len(out)-1, then pathNum=pathNum+len(out)-1; S426, using the nodes in the adjacent node list child as the starting node, with the end and ending points unchanged, call steps S423~S425 to recursively calculate the number of paths; S428, the output pathNum is the number of all paths between the end start point and the end end point.

7. The method for obtaining all paths between any nodes in a directed acyclic graph as described in claim 1, characterized in that, Step S5 is to determine the path containing a given starting point and a given ending 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