A method and system for determining loops in a directed acyclic graph

By traversing deeply prioritized traversal to judge the loops in the directed acyclic graph on the client, the problems of poor traffic pressure and user experience in the prior art are solved, and real-time response and accurate judgment in a weak network environment are achieved.

CN114494506BActive Publication Date: 2025-02-07SHANDONG EVAYINFO TECH CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202111533968.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-15
Publication Date
2025-02-07
Estimated Expiration
2041-12-15

AI Technical Summary

Technical Problem

When judging the loop in the directed acyclic graph, the prior art requires front-end and back-end data exchange, resulting in an increase in the traffic pressure on the server side, making it impossible to achieve instant response in a weak network environment, and the user experience is poor.

Method used

By performing deep priority traversal on the client, we can determine whether there are loops in the graph, avoid front-end and back-end data exchange, reduce traffic pressure on the server, and realize instant response in a weak network environment.

Benefits of technology

This method reduces the number of data requests, improves the response speed, ensures the accuracy of judgment results, improves user experience, and performs better especially in weak network environments.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114494506B_ABST
    Figure CN114494506B_ABST
Patent Text Reader

Abstract

The present invention provides a method and system for determining a loop in a directed acyclic graph, obtains a connection request, calculates and updates the out-degree and in-degree of each node according to an existing connection set and a node set; starting from each node with an out-degree of a set value, cyclically executes to receive a parameter of the current node, detects whether the current node exists in a branch stack generated by a depth-first traversal, and if not, pushes the current node into the branch stack, searches for each child-lower-level node of the current node through a connection set and a node set, forms a sub-branch, and recursively upwards until the current node is a terminal node, and the top element of the stack is popped out of the stack; if the top element of the stack exists in the branch stack, it means that there is a loop, and the corresponding connection is not added to the connection set, otherwise the depth-first traversal continues. The implementation process of the present invention does not require front-end and back-end data exchange, reduces the traffic pressure of the service end, and has accuracy; and effectively improves the user experience.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of loop determination, and in particular relates to a method and system for determining a loop in a directed acyclic graph. Background Art

[0002] The statements in this section merely provide background information related to the present invention and do not necessarily constitute prior art.

[0003] The big data market is booming, the degree of informatization of enterprises is constantly deepening, and demands are springing up one after another. In order to quickly respond to market demand, the process management of enterprise data assets in a drag-and-drop low-code visual way has become an inevitable choice for the majority of data managers; it can effectively improve efficiency and reduce time and communication costs in the development process.

[0004] Directed acyclic graph is the data model foundation for low-code, visual, and process-based development, and is an effective tool for describing the process of data governance engineering. In computer science, it refers to a directed acyclic graph (DAG) without loops. The judgment of loops is one of the key technologies for related applications.

[0005] According to the inventor's understanding, for most of the related products on the market, the judgment of the loops in their data flow diagrams is performed by the background server, but this implementation method has certain disadvantages: it will increase the traffic pressure on the server, and it will not be able to respond instantly in a weak network environment, and it cannot guarantee accuracy, resulting in an unsmooth user experience and a serious sense of congestion; at the same time, it will increase the user's traffic consumption. Summary of the invention

[0006] In order to solve the above problems, the present invention proposes a method and system for determining loops in a directed acyclic graph. The implementation process of the present invention does not require data exchange between the front-end and back-end, reduces the traffic pressure on the server, can solve the problem of instant response in a weak network environment, ensures the accuracy of the results, and effectively improves the user experience.

[0007] According to some embodiments, the present invention adopts the following technical solutions:

[0008] A method for determining a loop in a directed acyclic graph comprises the following steps:

[0009] Get the connection request, and calculate and update the out-degree and in-degree of each node based on the existing connection set and node set;

[0010] Starting from each node with an out-degree of the set value, the depth-first traversal process is executed cyclically;

[0011] The depth-first traversal process includes receiving a parameter of the current node, detecting whether the current node exists in the branch stack generated by the depth-first traversal, and if not, pushing the current node into the branch stack, searching for the child nodes of the current node through the connection set and the node set to form a child branch, and continuing the depth-first traversal for all branches until the current node is the terminal node, recursively upward, and the top element of the stack is popped;

[0012] If the top element of the stack exists in the branch stack, it means there is a cycle, a prompt is issued that the cycle is not allowed, and the corresponding connection is not added to the connection set, otherwise the depth-first traversal process continues.

[0013] As an optional implementation, the following steps are also included:

[0014] The nodes and links in the graph are stored in two sets in advance.

[0015] As a further qualification, the parameters of a node object include a universally unique identifier, an in-degree, and an out-degree.

[0016] As a further limitation, the parameters of the link object include the universally unique identifiers of the upper and lower nodes.

[0017] As an optional implementation, the set value is 1.

[0018] As an optional implementation, the process of determining the terminal node is that if the out-degree of the current node is 0, it is considered to be a terminal node.

[0019] As an optional implementation, if the depth-first traversal process is completed, the corresponding connection is added to the connection set, and the current rendering effect is re-rendered.

[0020] A system for determining a loop in a directed acyclic graph, comprising a data layer, wherein the data layer comprises:

[0021] The parameter updating module is configured to obtain a connection request, and calculate and update the out-degree and in-degree of each node according to the existing connection set and node set;

[0022] The depth-first traversal module is configured to start from each node with an out-degree of a set value and cyclically execute the depth-first traversal process, including receiving a parameter of the current node, detecting whether the current node exists in the branch stack generated by the depth-first traversal, and if not, pushing the current node into the branch stack, searching for the child subordinate nodes of the current node through the connection set and the node set to form a sub-branch, and continuing the depth-first traversal for all branches until the current node is the terminal node, recursively upward, and the top element of the stack is popped; if the top element of the stack exists in the branch stack, it means there is a loop, and a prompt that the loop is not allowed to exist is issued and the corresponding connection is not added to the connection set, otherwise the depth-first traversal process continues.

[0023] As an optional implementation, the data layer further includes a storage module configured to pre-store the nodes and links in the graph in two sets respectively.

[0024] As an optional implementation, the system further includes: a rendering layer, the rendering layer including:

[0025] A trigger module is configured to trigger a ring detection when it is detected that a user connects a rendered node;

[0026] The display module is configured to display the stored node and connection data visually on the canvas to display the user's adding, deleting, and modifying operations on the nodes and the connections between them on the canvas.

[0027] An electronic device comprises a memory and a processor, and computer instructions stored in the memory and executed on the processor. When the computer instructions are executed by the processor, the steps in the above method are completed.

[0028] A computer-readable storage medium is used to store computer instructions, and when the computer instructions are executed by a processor, the steps in the above method are completed.

[0029] Compared with the prior art, the present invention has the following beneficial effects:

[0030] Compared with the back-end verification method, the present invention eliminates the front-end and back-end interaction, reduces the number of data requests, and improves the response speed; and is no longer affected by the network environment. This method has more obvious advantages in a weak network environment, can achieve timely response, and ensure the accuracy of the judgment result.

[0031] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, preferred embodiments are given below and described in detail with reference to the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS

[0032] The accompanying drawings in the specification, which constitute a part of the present invention, are used to provide a further understanding of the present invention. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute improper limitations on the present invention.

[0033] Figure 1 Schematic diagram of the process of this embodiment. DETAILED DESCRIPTION

[0034] The present invention will be further described below in conjunction with the accompanying drawings and embodiments.

[0035] It should be noted that the following detailed descriptions are all illustrative and intended to provide further explanation of the present invention. Unless otherwise specified, all technical and scientific terms used herein have the same meanings as those commonly understood by those skilled in the art to which the present invention belongs.

[0036] It should be noted that the terms used herein are only for describing specific embodiments and are not intended to limit exemplary embodiments according to the present invention. As used herein, unless the context clearly indicates otherwise, the singular form is also intended to include the plural form. In addition, it should be understood that when the terms "comprising" and / or "including" are used in this specification, it indicates the presence of features, steps, operations, devices, components and / or combinations thereof.

[0037] Embodiment 1:

[0038] A method for determining a loop in a directed acyclic graph, such as Figure 1 As shown, the front-end JavaScript is used as an example to implement the system, including the following steps:

[0039] Step 1: Store the nodes and links in the graph in two sets (or arrays) respectively, where the main parameters of the node object are the Universally Unique Identifier (UUID), in-degree and out-degree, and the main parameters of the link object are the UUIDs of the upper and lower nodes.

[0040] Step 2: When the user connects the nodes rendered by the rendering layer, it will trigger the event listener customized by JsPlumb in the browser, and call the ring detection method of the data layer. The main parameters of this method are the outgoing node id and the incoming node id.

[0041] Step 3: Calculate and update the out-degree and in-degree of each node through the connection set and the node set.

[0042] Step 4: Starting from each node with an out-degree of 1, perform a depth-first traversal of the directed graph to find a loop.

[0043] The loop detection method receives a parameter of the current node. Check whether the current node exists in the branch stack generated by the depth-first traversal. If not, push the current node into the branch stack, find the child nodes (sub-branches) of the current node through the node and connection set, and continue to perform depth-first traversal on all branches until the out-degree of the current node is 0 (the end node), recursively upward, and pop the top element of the stack.

[0044] If this element exists in the branch stack, it means there is a loop. Jump out of the loop.

[0045] Step 5: If a loop exists, the user is prompted not to allow the loop to exist and the connection is not added to the connection set maintained by the data layer.

[0046] Some of the above steps are implemented in the rendering layer, and some are implemented in the data layer.

[0047] The rendering layer is developed based on JsPlumb and is responsible for rendering the flowchart. The data layer stores the node and connection data and displays them visually on the web page canvas. Users can add, delete, and modify nodes and their connections on the canvas.

[0048] The data layer is mainly responsible for storing and maintaining the data sets of each node and its connections, and providing method support and verification for various operations performed by users on the canvas.

[0049] Of course, in other embodiments, other systems may be used as the implementation basis.

[0050] Embodiment 2:

[0051] A system for determining a loop in a directed acyclic graph, comprising a data layer, wherein the data layer comprises:

[0052] The parameter updating module is configured to obtain a connection request, and calculate and update the out-degree and in-degree of each node according to the existing connection set and node set;

[0053] The depth-first traversal module is configured to start from each node with an out-degree of a set value and cyclically execute the depth-first traversal process, including receiving a parameter of the current node, detecting whether the current node exists in the branch stack generated by the depth-first traversal, and if not, pushing the current node into the branch stack, searching for the child subordinate nodes of the current node through the connection set and the node set to form a sub-branch, and continuing the depth-first traversal for all branches until the current node is the terminal node, recursively upward, and the top element of the stack is popped; if the top element of the stack exists in the branch stack, it means there is a loop, and a prompt that the loop is not allowed to exist is issued and the corresponding connection is not added to the connection set, otherwise the depth-first traversal process continues.

[0054] The data layer also includes a storage module configured to store the nodes and links in the graph in two sets in advance.

[0055] The system further includes: a rendering layer, the rendering layer including:

[0056] A trigger module is configured to trigger a ring detection when it is detected that a user connects a rendered node;

[0057] The display module is configured to display the stored node and connection data visually on the canvas to display the user's adding, deleting, and modifying operations on the nodes and the connections between them on the canvas.

[0058] Embodiment three:

[0059] An electronic device includes a memory and a processor, and computer instructions stored in the memory and executed on the processor. When the computer instructions are executed by the processor, the steps in the method in the first embodiment are completed.

[0060] Embodiment 4:

[0061] A computer-readable storage medium is used to store computer instructions, and when the computer instructions are executed by a processor, the steps in the method in embodiment 1 are completed.

[0062] Those skilled in the art will appreciate that embodiments of the present invention may be provided as methods, systems, or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0063] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0064] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0065] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0066] Although the above describes the specific implementation mode of the present invention in conjunction with the accompanying drawings, it is not intended to limit the scope of protection of the present invention. Those skilled in the art should understand that various modifications or variations that can be made by those skilled in the art on the basis of the technical solution of the present invention without creative work are still within the scope of protection of the present invention.

Claims

1. A method for determining a loop in a directed acyclic graph, characterized in that: The following steps are involved: Store the nodes and links in the graph in two sets in advance; When the user connects the nodes rendered by the rendering layer, it triggers the custom event listener of JsPlumb in the browser and calls the ring detection method of the data layer; Get the connection request, and calculate and update the out-degree and in-degree of each node based on the existing connection set and node set; Starting from each node with an out-degree of the set value, the depth-first traversal process is executed cyclically; The depth-first traversal process includes receiving a parameter of the current node, detecting whether the current node exists in the branch stack generated by the depth-first traversal, and if not, pushing the current node into the branch stack, searching for the child nodes of the current node through the connection set and the node set to form a child branch, and continuing the depth-first traversal for all branches until the current node is the terminal node, recursively upward, and the top element of the stack is popped; If the top element of the stack exists in the branch stack, it means there is a loop, a prompt that the loop is not allowed to exist is issued and the corresponding connection is not added to the connection set, otherwise the depth-first traversal process continues; The rendering layer is developed based on JsPlumb and is responsible for rendering the flowchart. The data layer stores the node and connection data and displays them visually on the web page canvas. Users can add, delete, and modify nodes and their connections on the canvas. The data layer is mainly responsible for storing and maintaining the data sets of each node and its connections, and providing method support and verification for various operations performed by users on the canvas.

2. A method for determining a loop in a directed acyclic graph as claimed in claim 1, characterized in that: The parameters of the node object include the universal unique identifier, in-degree and out-degree; The parameters of the connection object include the universally unique identifiers of the upper and lower nodes.

3. A method for determining a loop in a directed acyclic graph as claimed in claim 1, characterized in that: The set value is 1.

4. A method for determining a loop in a directed acyclic graph as claimed in claim 1, characterized in that: The process of determining the terminal node is as follows: if the out-degree of the current node is 0, it is considered to be a terminal node.

5. A system for determining a loop in a directed acyclic graph, using a method for determining a loop in a directed acyclic graph as claimed in any one of claims 1 to 4, characterized in that: Comprising a data layer, the data layer comprising: The parameter updating module is configured to obtain a connection request, and calculate and update the out-degree and in-degree of each node according to the existing connection set and node set; The depth-first traversal module is configured to start from each node with an out-degree of a set value and cyclically execute the depth-first traversal process, including receiving a parameter of the current node, detecting whether the current node exists in the branch stack generated by the depth-first traversal, and if not, pushing the current node into the branch stack, searching for the child subordinate nodes of the current node through the connection set and the node set to form a sub-branch, and continuing the depth-first traversal for all branches until the current node is the terminal node, recursively upward, and the top element of the stack is popped; if the top element of the stack exists in the branch stack, it means there is a loop, and a prompt that the loop is not allowed to exist is issued and the corresponding connection is not added to the connection set, otherwise the depth-first traversal process continues.

6. A system for determining loops in a directed acyclic graph as claimed in claim 5, characterized in that: The data layer also includes a storage module configured to store the nodes and links in the graph in two sets in advance.

7. A system for determining loops in a directed acyclic graph as claimed in claim 5, characterized in that: The system further comprises: a rendering layer, wherein the rendering layer comprises: A trigger module is configured to trigger a ring detection when it is detected that a user connects a rendered node; The display module is configured to display the stored node and connection data visually on the canvas to display the user's adding, deleting, and modifying operations on the nodes and the connections between them on the canvas.

8. An electronic device, characterized in that: The method comprises a memory and a processor, and computer instructions stored in the memory and executed on the processor, wherein when the computer instructions are executed by the processor, the steps in the method according to any one of claims 1 to 4 are completed.

9. A computer-readable storage medium, characterized in that: Used to store computer instructions, which, when executed by a processor, complete the steps of the method according to any one of claims 1 to 4.

Citation Information

Patent Citations

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

    CN113672369A