Directed graph layout method and apparatus, device, and storage medium
By optimizing the node level of the directed graph, the directed edge length in the directed graph is minimized, thereby improving the compactness and readability of the directed graph after folding or expanding operations, the directed graph in the prior art is solved The problem of poor readability of the graph.
Patent Information
- Application Number
- PCT/CN2024/109307
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2023-08-02
- Filing Date
- 2024-08-01
- Publication Date
- 2025-02-06
AI Technical Summary
In the visualization scenario of directed graphs, the large number of nodes leads to poor readability. The prior art collapses or expands the directed graph by hiding or displaying downstream nodes, but the resulting graph is not compact enough, affecting reading efficiency.
By obtaining the first directed graph that has been laid out, the second directed graph to be re-layed is obtained, and optimized according to the hierarchy of the node. The goal is to minimize the sum of lengths of all directed edges, thereby re-refining the second directed graph. Layout to improve the compactness and readability of the graph.
After folding or expanding operations, the directed edges in the directed graph are as short as possible, and the structure is more compact, making it easier to find the associated nodes and enhance the readability of the directed graph.
Smart Images

Figure CN2024109307_06022025_PF_FP_ABST
Abstract
Description
Directed graph layout method, device, equipment and storage medium
[0001] CROSS-REFERENCE TO RELATED APPLICATIONS
[0002] This application claims priority to the Chinese patent application filed with the State Intellectual Property Office of China on August 2, 2023, with application number 202310968154.9 and invention name “Directed graph layout method, device, equipment and storage medium”, the entire contents of which are incorporated by reference into this application. Technical Field
[0003] The present application relates to the field of computer technology, and in particular to a directed graph layout method, apparatus, device, and storage medium. Background Art
[0004] Directed graphs have strict topological properties and are highly expressive of processes. They can be used to display workflows, state transitions, genealogical hierarchies, and historical version changes. In today's information explosion, in some directed graph scenarios, the large number of nodes in a single directed graph can make them difficult to read. In some directed graph visualization scenarios, interactive features such as collapsing and expanding downstream nodes can be provided to help users more efficiently focus on useful information.
[0005] Summary of the Invention
[0006] In a first aspect, an embodiment of the present application provides a directed graph layout method, the method comprising:
[0007] Obtaining a second directed graph to be re-laid out according to the laid out first directed graph; wherein the second directed graph is a partial directed graph of the first directed graph, or the second directed graph includes the first directed graph;
[0008] Determining an initial level of each node in the second directed graph according to the level of each node in the first directed graph;
[0009] Optimizing the level of each node in the second directed graph according to a preset optimization strategy to obtain an optimized level of each node in the second directed graph; the preset optimization strategy includes an optimization strategy that aims to minimize the sum of the lengths of all directed edges in the second directed graph;
[0010] The second directed graph is rearranged according to the optimization level of each node in the second directed graph.
[0011] In a second aspect, an embodiment of the present application provides a directed graph layout device, the device comprising:
[0012] an acquisition module, configured to acquire a second directed graph to be rearranged based on the laid out first directed graph; wherein the second directed graph is a partial directed graph of the first directed graph, or the second directed graph includes the first directed graph;
[0013] an initial level determination module, configured to determine the initial level of each node in the second directed graph according to the level of each node in the first directed graph;
[0014] a hierarchical optimization module, configured to optimize the hierarchies of the nodes in the second directed graph according to a preset optimization strategy to obtain optimized hierarchies of the nodes in the second directed graph; the preset optimization strategy includes an optimization strategy that aims to minimize the sum of the lengths of all directed edges in the second directed graph;
[0015] A rearrangement module is used to rearrange the second directed graph according to the optimization level of each node in the second directed graph.
[0016] In a third aspect, an embodiment of the present application provides a computer device, comprising:
[0017] processor; and
[0018] A memory is arranged to store computer-executable instructions, wherein the executable instructions are configured to be executed by the processor, and the executable instructions include instructions for executing the steps in the directed graph layout method provided in the above embodiment.
[0019] In a fourth aspect, an embodiment of the present application provides a storage medium for storing computer-executable instructions, wherein the executable instructions enable a computer to execute the directed graph layout method provided in the aforementioned embodiment. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are only some embodiments recorded in this application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0021] FIG1 is a flow chart of a directed graph layout method provided by an embodiment of the present application;
[0022] FIG2 is a schematic diagram of the layout of the first directed graph that has been laid out in the layout method shown in FIG1 ;
[0023] FIG3 is a schematic diagram of the layout of a second directed graph obtained by hiding downstream nodes after the first directed graph shown in FIG2 is folded;
[0024] FIG4 is a schematic diagram of the layout of a second directed graph obtained by the layout method shown in FIG1 after the first directed graph shown in FIG2 is folded;
[0025] FIG5 is a flowchart of another directed graph layout method provided by an embodiment of the present application;
[0026] FIG6 is a schematic diagram of the layout of the second directed graph after pre-sorting the nodes at the same level in the layout method shown in FIG5 ;
[0027] 7 is a schematic diagram of the layout of the second directed graph after the second directed graph is re-layouted using the directed graph layout method shown in FIG. 5 ;
[0028] FIG8 is a schematic diagram of the layout of the directed graph after performing an expansion operation on the downstream nodes of node 2 of the directed graph shown in FIG7 and optimizing the node hierarchy.
[0029] FIG9 is a schematic diagram of the layout after inserting a virtual node into the directed graph shown in FIG8 ;
[0030] FIG10 is a schematic diagram of the layout of the directed graph shown in FIG9 after node order optimization;
[0031] FIG11 is a schematic diagram of the layout of the directed graph shown in FIG10 after rearrangement;
[0032] FIG12 is a schematic diagram of a layout method of an initial directed graph provided by an embodiment of the present application;
[0033] FIG13 is a schematic diagram of another directed graph layout method provided in an embodiment of the present application;
[0034] FIG14 is a module diagram of a directed graph layout device provided in one embodiment of the present application;
[0035] FIG15 is a schematic structural diagram of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0036] In related technologies, the folding and unfolding of downstream nodes is often achieved by hiding or displaying downstream nodes. This method results in a directed graph that is not compact enough and has poor readability, which affects reading efficiency. To address the problem of reduced readability after folding or unfolding downstream nodes in a directed graph, embodiments of the present application provide a directed graph layout method, apparatus, device, and storage medium to make the structure of the directed graph more compact when folded or unfolded, thereby improving the readability of the directed graph.
[0037] In the directed graph method provided in the embodiment of the present application, a second directed graph to be rearranged is obtained based on the laid out first directed graph, and the level at which each node in the second directed graph is located is optimized according to a preset optimization strategy to obtain the optimized level at which each node in the second directed graph is located; wherein the preset optimization strategy includes: an optimization strategy with the goal of minimizing the sum of the lengths of all directed edges in the second directed graph; and rearranging the second directed graph according to the optimized level at which each node in the second directed graph is located. By using a preset optimization strategy such as one with the goal of minimizing the sum of the lengths of all directed edges in the second directed graph, optimizing the level at which each node in the second directed graph is located, and rearranging the second directed graph according to the optimized level, compared to hiding / showing downstream nodes, the directed edges in the directed graph obtained after the folding / expanding operation can be as short as possible, and the structure is more compact, thereby facilitating the finding of related nodes and enhancing the readability of the directed graph.
[0038] Furthermore, based on the layout method provided in the above embodiment, the embodiment of the present application pre-sorts the order of each node in the second directed graph in its own level according to the order of each node in the first directed graph that has been laid out in its own level; on the basis of the pre-sorting, iterates the second directed graph multiple times to reduce the crossing of lines in the second directed graph and determine the optimized order of each node in the second directed graph in its own level; and re-layouts the second directed graph according to the optimized level of each node in the second directed graph and the optimized order of each node in its own level. Since the first directed graph is a laid-out directed graph, the order of each node in the first directed graph in its level is an optimized order. The order of each node in the second directed graph in its level is pre-sorted according to the order of each node in the first directed graph in its level. On this basis, the order of each node in the second directed graph in its level is optimized. The order of each node in the optimized second directed graph in its level is most likely the same as the order in the first directed graph. Thus, the second directed graph after the layout can maintain the overall structure of the original first directed graph as much as possible, thereby reducing the cost of understanding the graph. By rearranging the second directed graph according to the optimized level of each node in the second directed graph and the optimized order of each node in its level, the second directed graph can be made more compact while maintaining the overall structure of the original directed graph, making the directed graph after the folding / expanding operation easier to read and understand, further enhancing the readability of the directed graph.
[0039] In order to enable those skilled in the art to better understand the technical solutions in the embodiments of this application, the technical solutions in the embodiments of this application will be clearly and completely described below in conjunction with the drawings in the embodiments of this specification. Obviously, the described embodiments are only part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts should fall within the scope of protection of this specification.
[0040] Example 1
[0041] This embodiment provides a directed graph layout method, which is used to automatically layout a directed graph in a directed graph visualization application, such as collapsing downstream nodes or expanding downstream nodes of a directed graph. FIG1 is a flow chart of the directed graph layout method provided by one embodiment of the present application. As shown in FIG1 , the directed graph layout method provided by this embodiment may include the following steps:
[0042] S102: Obtain a second directed graph to be re-layout according to the laid-out first directed graph.
[0043] Among them, the first directed graph is a directed graph with optimized layout, which can be a directed graph operated when folding or expanding downstream nodes in a directed graph visualization application. The first directed graph can be an initial directed graph, or it can be a folded directed graph obtained after the last folding downstream node operation, or it can be an expanded directed graph obtained after the last expanding downstream node operation.
[0044] The second directed graph is the directed graph to be rearranged, and may be the directed graph obtained by folding or expanding downstream nodes in a directed graph visualization application. Depending on the operation performed on the first directed graph, the second directed graph may be a partial directed graph of the first directed graph, or may include the first directed graph, i.e., the first directed graph is a partial directed graph of the second directed graph. For example, when the first directed graph is folded, the second directed graph may be a partial directed graph of the first directed graph, and when the first directed graph is expanded, the second directed graph may include the first directed graph.
[0045] In one implementation, a first directed graph can be displayed on a user interaction interface. Based on a user's operation of collapsing downstream nodes of a specified node in the first directed graph, the topological relationship between the nodes in the first directed graph is obtained. Based on the topological relationship between the nodes in the first directed graph, all downstream nodes of the specified node are found in the first directed graph, and all downstream nodes of the specified node are deleted from the first directed graph, thereby obtaining a second directed graph. The obtained second directed graph is a directed graph to be rearranged. After the second directed graph is rearranged, the rearranged second directed graph can be displayed on the user interaction interface, thereby completing the interactive process of collapsing downstream nodes.
[0046] In another implementation, a first directed graph can be displayed on a user interaction interface. Based on a user's operation of expanding downstream nodes of a specified node in the first directed graph, all downstream nodes of the specified node are obtained, and the downstream nodes of the specified node are added to the first directed graph, thereby obtaining a second directed graph. The obtained second directed graph is the directed graph to be rearranged. After the second directed graph is rearranged, the rearranged second directed graph can be displayed on the user interaction interface, thereby completing the interactive process of expanding downstream nodes.
[0047] Of course, it is understandable that the directed graph layout method provided in this embodiment is not limited to being applied in the interaction of folding or unfolding downstream nodes, and it can also be used in visualization applications of other directed graphs, for example, in applications in which the directed graph is changed by adding nodes, adding lines, deleting nodes, deleting lines, etc. to an existing directed graph. In this case, the second directed graph can include the existing first directed graph and the added nodes, which can be obtained based on the operation of adding nodes to the first directed graph. In implementation, the first directed graph can be displayed on the user interaction interface, and according to the user's operation of adding downstream nodes to the specified node in the first directed graph, the downstream nodes added by the user for the specified node are obtained, and then the specified node is found in the first directed graph, and the downstream nodes are added to the specified node in the first directed graph to obtain the second directed graph. Wherein, the second directed graph obtained is the directed graph to be rearranged, and after the second directed graph is rearranged, the rearranged second directed graph can be displayed on the user interaction page, thereby completing the interaction of adding downstream nodes.
[0048] In the above implementation, the designated node may be any designated node in the first directed graph, and the downstream node of the designated node may be a node in the first directed graph that is directly or indirectly dependent on the designated node.
[0049] S104: Determine the initial level of each node in the second directed graph according to the level of each node in the first directed graph.
[0050] Wherein, the second directed graph is a local directed graph of the first directed graph, or the first directed graph is a local directed graph of the second directed graph, therefore, all or part of the nodes in the second directed graph also belong to the first directed graph. For the nodes in the intersection of the second directed graph and the first directed graph, their initial level in the second directed graph can be determined based on the level of the corresponding nodes in the first directed graph in the first directed graph. For other nodes in the second directed graph outside the intersection with the first directed graph, their level can be determined based on the association relationship between other nodes and the nodes in the intersection. Wherein, the level of each node in the first directed graph can be pre-stored in a database, and the level of each node in the first directed graph can be obtained from the database.
[0051] Specifically, in one implementation, the second directed graph is a partial directed graph of the first directed graph, and therefore all nodes in the second directed graph belong to the first directed graph. In this implementation, the corresponding node of each node in the second directed graph can be obtained from the first directed graph, and then the level of the corresponding node in the first directed graph can be obtained. The initial level of each node in the second directed graph is determined according to the level of the corresponding node in the first directed graph.
[0052] In another implementation, the second directed graph includes the first directed graph and other nodes outside the first directed graph, and some of the nodes in the second directed graph belong to the first directed graph. In this implementation, the corresponding nodes of these nodes in the second directed graph can be obtained from the first directed graph, and then the level of the corresponding nodes in the first directed graph can be obtained. The initial level of these nodes in the second directed graph is determined according to the level of the corresponding nodes in the first directed graph. For other nodes in the second directed graph except the nodes in the first directed graph, the initial level of other nodes can be determined based on the association relationship between other nodes and the specified node.
[0053] S106 , optimizing the level of each node in the second directed graph according to a preset optimization strategy to obtain the optimized level of each node in the second directed graph.
[0054] In one implementation, the preset optimization strategy includes an optimization strategy whose goal is to minimize the sum of the lengths of all directed edges in the second directed graph. An initial spanning tree for each node in the second directed graph can be generated based on the initial level at which each node in the second directed graph is located; the sum of the lengths of all directed edges in the initial spanning tree is calculated; and then, the spanning tree is iterated multiple times with the goal of minimizing the sum of the lengths of all directed edges in the spanning tree. During each iteration, the levels of the nodes at both ends of the cross-level directed edges in the spanning tree of the current iteration are adjusted to generate a spanning tree for the next iteration. Thereafter, the level at which each node in the second directed graph is located can be determined based on the spanning tree after the iteration.
[0055] In each iteration, the sum of the lengths of all edges in the tree spanned by this iteration can be calculated by the following method:
[0056] Step 1: Determine the level of each node in the tree spanned by this iteration.
[0057] Among them, the longest path in the iterative spanning tree can be obtained, and the level of each node in the longest path can be determined; for example, for the first node in the longest path, its level can be determined to be the first level L1, for the second node in the longest path, its level can be determined to be the second level L2, for the third node in the longest path, its level can be determined to be the third level L3... For the Nth node in the longest path, its level can be determined to be the Nth level LN ; Then, for other nodes other than the nodes of the longest path in this iterative generation tree, their upstream nodes or downstream nodes can be found in the longest path, and the levels of other nodes can be determined based on the hierarchical relationship between other nodes and their upstream nodes or downstream nodes in the longest path; for example, for node A, if its first downstream node B is on the longest path, the level where node B is located is the third level L3, then the level where node A is located can be the second level L2.
[0058] Step 2: Determine the length of each directed edge in the iterative spanning tree according to the level of each node in the iterative spanning tree.
[0059] Among them, for each directed edge in the tree spanned by this iteration, the length of the directed edge can be determined according to the level difference of the nodes at both ends of the directed edge. For example, for a directed edge from node u to node v, if the level of node u is Lu and the level of node v is Lv, then the length l(u,v) of the directed edge (u,v) can be equal to the level difference Lv-Lu of the levels of the two nodes, that is, l(u,v)=Lv-Lu, where w(u,v) represents the length of the directed edge from node u to node v, Lu represents the level of node u, Lv represents the level of node v, Lu and Lv are both positive integers, and Lv-Lu>0.
[0060] Step 3: Determine the total length of all directed edges in the current iterative spanning tree based on the length of each directed edge in the current iterative spanning tree.
[0061] The sum of the lengths of all directed edges in the tree generated by this iteration is Sum=∑l(u,v).
[0062] After determining the sum of the lengths of all directed edges in the current iterative spanning tree, the sum of the lengths of all edges in the current iterative spanning tree can be compared with the current sum of lengths. If the sum of the lengths of all edges in the current iterative spanning tree is less than the current sum of lengths, the current sum of lengths is updated using the sum of the lengths of all directed edges in the initial spanning tree. Subsequently, based on the lengths of each directed edge in the current iterative spanning tree, cross-level directed edges can be obtained. The levels of the nodes at both ends of the cross-level directed edges can be adjusted to generate the spanning tree for the next iteration, and the next iteration can be performed until the current sum of lengths is minimized. Among them, the cross-level directed edge can be a directed edge whose length is greater than a set threshold. For example, if the length of the directed edge is equal to the difference between the levels of the two points at its two ends, then if the length of the directed edge is greater than 1, it means that the nodes at both ends of the directed edge are not nodes of adjacent levels, and the directed edge is a cross-level directed edge. If the length of the directed edge is equal to 1, it means that the nodes at both ends of the directed edge are nodes of adjacent levels, and the directed edge is a non-cross-level directed edge.
[0063] After the iteration, the level at which each node in the generated tree after the iteration is located can be determined, and this level is the optimized level at which each node in the second directed graph is located.
[0064] It is understandable that there are multiple ways to determine whether the current length sum has reached the minimum. In one implementation, if the value of the current length sum does not change after each iteration, it can be considered that the current length sum is the minimum.
[0065] S108 , re-layout the second directed graph according to the optimization level of each node in the second directed graph.
[0066] The second directed graph can be rearranged based on the principles of symmetry and balance, according to the optimized levels of the nodes in the second directed graph. For example, nodes at the same level can be placed in the same row or column, with equal spacing between different levels. The different levels can be arranged according to their hierarchical relationship so that all directed edges are oriented in the same direction as much as possible, and the nodes in the second directed graph can be rearranged.
[0067] In one implementation, after the second directed graph is rearranged, the rearranged second directed graph may be visualized and displayed on a user interaction interface as a result of a user operation.
[0068] In the above embodiment, a second directed graph is obtained based on the first directed graph, and the hierarchy of each node in the second directed graph is optimized according to a preset optimization strategy such as minimizing the sum of the lengths of all directed edges in the directed graph. The second directed graph is rearranged according to the optimized hierarchy. Compared with folding / displaying the first directed graph by hiding / displaying downstream nodes, the structure of the directed graph can be made more compact, thereby facilitating the positioning of related nodes, enhancing the readability of the directed graph, and facilitating the reading of the directed graph.
[0069] Figure 2 is a schematic diagram of the first directed graph that has been laid out provided by the present embodiment; Figure 3 is a directed graph of the operation result obtained by the method of hiding downstream nodes after a folding operation is performed on the downstream nodes of node 2 in the first directed graph shown in Figure 2; Figure 4 is a directed graph of the operation result obtained by the method of rearrangement shown in the above embodiment of the present application after a folding operation is performed on the downstream nodes of node 2 in the graph in the first directed graph shown in Figure 2. As shown in Figures 2, 3, and 4, in the directed graph obtained by the method of hiding downstream nodes, the directed edge between node 1 and node 2 is a long line, while in the directed graph obtained by the method of rearrangement provided by the above embodiment of the present application, the directed edge between node 1 and node 2 is changed from a long line to a short line, and its structure is more compact, more readable, and easier to find related nodes.
[0070] Example 2
[0071] In the above embodiment, the folding / expanding function of the first directed graph is realized by re-layouting the second directed graph. This method can optimize the hierarchical distribution of nodes and make the folded / expanded directed graph more compact. However, the re-layout may change the overall structure of the directed graph and increase the understanding cost of the directed graph. For example, in the directed graph shown in Figure 4, although node 2 is changed from the 4th column to the 2nd column, node 2 is arranged above node 3, which causes the positions of nodes 3, 4, 5 and their downstream nodes to change significantly. The overall structure of the directed graph has changed significantly compared to Figure 2, which will increase the understanding cost of the graph. In order to ensure that the structure of the directed graph after re-layout does not change substantially, this embodiment provides another directed graph layout method. Based on the directed graph layout method provided in the above embodiment, this method further pre-sorts the nodes of the same level in the second directed graph according to the order of the nodes in the first directed graph, optimizes the order of the nodes in their level based on the pre-sorting, and re-lays out the nodes in the second directed graph according to the optimized level of the nodes in the second directed graph and the optimized order in the level. In this way, the second directed graph can be made more compact while maintaining the overall structure of the original directed graph, making the directed graph easier to read and understand, and further enhancing the readability of the directed graph.
[0072] FIG5 is a flow chart of another directed graph layout method provided by an embodiment of the present application. As shown in FIG5 , the directed graph layout method provided by this embodiment includes:
[0073] S202: Obtain a second directed graph to be re-layout according to the laid-out first directed graph.
[0074] The second directed graph is a local directed graph of the first directed graph, or the second directed graph includes the first directed graph.
[0075] S204: Determine the initial level of each node in the second directed graph according to the level of each node in the first directed graph.
[0076] S206: Optimizing the level of each node in the second directed graph according to a preset optimization strategy to obtain the optimized level of each node in the second directed graph.
[0077] The preset optimization strategy includes: an optimization strategy whose goal is to minimize the sum of the lengths of all directed edges in the second directed graph.
[0078] It can be understood that the processing of steps S202 to S206 is basically the same as the processing of steps S102 to S106 in Example 1. For the specific processing of steps S202 to S206, reference can be made to the corresponding steps in Example 1, which will not be repeated here.
[0079] S208: Pre-sort the order of each node in the second directed graph in its level according to the order of each node in the first directed graph in its level.
[0080] Wherein, the second directed graph is a local directed graph of the first directed graph, or the first directed graph is a local directed graph of the second directed graph, therefore, all or part of the nodes in the second directed graph also belong to the first directed graph. For these nodes in the second directed graph, their order in the second directed graph can be pre-sorted according to the order of the corresponding nodes in the first directed graph in the first directed graph, and for other nodes in the second directed graph, they can be sorted in a specified order, and the specified order can be any specified order. Wherein, the order of each node in the first directed graph in its level is pre-stored in a database, and the order of each node in the first directed graph in its level can be obtained from the database.
[0081] Furthermore, since the level of each node in the second directed graph is optimized, the optimization will make the cross-level directed edges as short as possible, but it will cause cross-level nodes in the second directed graph whose node levels have changed. Among them, the cross-level node is a node whose level has changed, and the level of the node in the second directed graph has changed compared to the level in the first directed graph. For example, in the first directed graph described in Figure 2, node 2 is in the 4th column, that is, the fourth level, and there is no node 3 in the 2nd column. In the second directed graph shown in Figure 4, the node has changed to the 2nd column, that is, the second level. Therefore, when pre-sorting, the level of each node in the first directed graph can be obtained; according to the level of each node in the first directed graph and the level of each node in the second directed graph, the cross-level node in the second directed graph whose level has changed is determined, and when pre-sorting the order of each node in the second directed graph in its level, the cross-level node is placed at the last position of its level. Since cross-level nodes are associated with cross-level directed edges (i.e., cross-level connections), when pre-sorting the order of the nodes in the second directed graph in their respective levels, the cross-level nodes are placed at the last position in their respective levels. This can control the cross-level directed edges to the bottom or one side of the directed graph as much as possible, making it easier to find and read. FIG6 is a schematic diagram of the layout of the nodes of the same level after pre-sorting in the layout method shown in FIG5. As shown in FIG6, the level where node 2 is located has changed. It is at the fourth level in the first directed graph, but at the second level in the second directed graph. Therefore, node 2 is a cross-level node and is placed at the end of the second level where it is currently located.
[0082] S210: With the goal of minimizing the number of line crossings in the second directed graph, the second directed graph is iterated multiple times to obtain an optimized order of each node in the second directed graph in its own level; wherein, in each iteration, the order of each node in the second directed graph in its own level is adjusted according to a preset sorting algorithm.
[0083] The preset sorting algorithm may be an algorithm for sorting by node importance, for example, an algorithm for sorting by node centrality value, or an algorithm for sorting by node centroid value, and the centrality value or center value of a node may be determined based on its relative position to the nodes in the previous layer. That is, for each iteration, for each level in the second directed graph, the importance value of the nodes in the level may be determined based on the position of the nodes in the level relative to the nodes in the previous layer; and the order of the nodes in the level may be adjusted based on the importance value of the nodes in the level. The importance value may be the centroid value or centrality value of the node relative to the nodes in the previous layer.
[0084] Specifically, for each iteration in multiple iterations, the second directed graph can be scanned layer by layer in this iteration. When scanning to the current level, the importance value of the node in the current level can be determined based on the position of the node in the current level relative to the node in the previous level. Then, the order of the nodes in the current level can be adjusted based on the importance value of the node in the current level. After scanning all levels in the second directed graph, the number of line crossings in the second directed graph after this iteration can be calculated. If the number of line crossings in the second directed graph after this iteration is less than the number of line crossings in the second directed graph after the previous iteration, the number of line crossings in the second directed graph after this iteration is used as the current number of line crossings, and the next iteration is performed until the current number of line crossings is minimized.
[0085] If the current number of line crossings is less than or equal to a set threshold, the iteration may be stopped. The set threshold is, for example, 0.
[0086] S212: Relaying the second directed graph according to the optimization level of each node in the second directed graph and the optimization order of each node in the level.
[0087] Among them, based on the principles of symmetry and balance, the coordinates of each node in the second directed graph can be determined according to the optimization level of each node in the second directed graph and the optimization order of each node in the level in which it is located; according to the coordinates of each node in the second directed graph, the second directed graph can be rearranged.
[0088] It can be understood that the first directed graph that has been laid out can be the previous directed graph after the layout is optimized by the layout method provided in the embodiment of the present application. The order of the nodes in the first directed graph is already the order after the optimized layout. The nodes in the same level are pre-sorted according to the order of the nodes in the first directed graph. On the basis of the pre-sorting, the order of the nodes is optimized according to the importance value of the nodes. The optimized order after optimization is likely to be basically the same as the order in the first directed graph. Therefore, the basic structure of the first directed graph can be retained while making the second directed graph compact. Moreover, iterative optimization based on the pre-sorting can further reduce the number of iterations and improve layout efficiency. Figure 7 is a schematic diagram of the layout of the second directed graph obtained by the layout method provided in this embodiment. It can be seen from Figure 7 that the directed graph is more compact than the directed graph shown in Figure 3, and the relative positions of the corresponding nodes have not changed significantly compared to the directed graph shown in Figure 2.
[0089] Furthermore, after the second directed graph is rearranged, the optimization level and optimization order of each node in the second directed graph may be cached for subsequent use, for example, when performing folding / expanding operations on the second directed graph.
[0090] In one implementation, although the level at which each node in the second directed graph is located is optimized, there may still be cross-level directed edges in the second directed graph. For example, when expanding the downstream nodes of node 2, the layout diagram of the directed graph after optimizing the level at which the node is located is shown in Figure 8. As can be seen from Figure 8, a cross-level directed edge pointing from node 1 to node 2 appears between node 1 and node 2, that is, a cross-level connection. This cross-level connection will intersect with other nodes and connections, and affect the subsequent optimization of the level at which the node is located. In this case, a virtual node can be inserted into the cross-level connection, and the cross-level connection can be changed to a connection of multiple adjacent level connections. Then, the order of the nodes is optimized. This method can reduce the intersection of connections, and can reduce the number of iterations in the subsequent optimization of the node order, thereby improving the optimization efficiency.
[0091] Specifically, we can determine the levels that the cross-level nodes span, and then insert virtual nodes into each level that the cross-level connection spans, and replace the original connection from the nth level to the n+sth level. n,n+i Change to a line from level n to level n+1 n,n+1 , the line from the n+1th level to the n+2th level l n+1,n+2 ...the line l from the n+s-1th level to the n+sth level n+s-1,n+s FIG9 is a schematic diagram of the layout after inserting virtual nodes in the directed graph shown in FIG8 . As shown in FIG9 , virtual node 1 (i.e., virtual 1 in FIG9 ) and virtual node 2 (i.e., virtual 2 in FIG9 ) can be inserted in the second and third levels between the first level where node 1 is located and the fourth level where node 2 is located, and the cross-level connection from node 1 to node 2 is changed into a combination of a connection from node 1 to virtual node 1, a connection from virtual node 1 to virtual node 2, and a connection from virtual node 2 to node 2.
[0092] After inserting virtual nodes, the order of nodes within the same level of the directed graph can be optimized with the goal of minimizing line crossings. The order of the nodes within the directed graph's level is determined to minimize line crossings. Figure 10 is a schematic diagram of the layout of the nodes in the directed graph shown in Figure 9 after order optimization. As shown in Figure 10, after order optimization, the number of line crossings in the directed graph is zero, meaning there are no line crossings in the directed graph.
[0093] After determining the optimization level and optimization order of each node in the second directed graph, the second directed graph can be rearranged according to the optimization level and optimization order of each node based on the principles of symmetry and balance. In the rearranged second directed graph, virtual nodes may not be displayed, and only the connections between virtual nodes may be displayed, as shown in Figure 11.
[0094] Example 3
[0095] The above method uses the optimized layout directed graph as the basis for folding, unfolding and other operations. For the initial directed graph, it can be optimized by the following method to obtain the initial directed graph after the optimized layout. The initial directed graph can be used as the first directed graph of the optimized layout for subsequent folding / unfolding operations. Figure 12 is a flow chart of a method for laying out an initial directed graph provided by an embodiment of the present application. As shown in Figure 12, the method for laying out an initial directed graph provided by an embodiment of the present application may include the following steps:
[0096] S302: Obtain an initial directed graph to be laid out.
[0097] The initial directed graph is an acyclic directed graph. If the initial directed graph contains a cycle, it will be converted into an acyclic directed graph.
[0098] S304: Determine the initial level of each node in the initial directed graph and the initial order of each node in the initial directed graph in the level.
[0099] The initial level of each node in the initial directed graph may be a level determined according to the hierarchical structure of the nodes, and the initial order may be an order pre-sorted according to a specified rule, such as an order pre-sorted according to the node acquisition order.
[0100] S306: Optimizing the level of each node in the initial directed graph according to a preset optimization strategy to determine the optimized level of each node in the initial directed graph; wherein the preset optimization strategy includes an optimization strategy that aims to minimize the sum of the lengths of all directed edges in the second directed graph;
[0101] S308: With the goal of minimizing the number of crossings of links in the initial directed graph, the initial directed graph is iterated multiple times to determine the optimized order of the nodes in the initial directed graph within their respective hierarchies; wherein, in each iteration, the order of the nodes in the initial directed graph within their respective hierarchies is adjusted according to a preset sorting algorithm;
[0102] S310: Layout the initial directed graph according to the optimized level of each node in the initial directed graph and the order of each node in the initial directed graph in the level.
[0103] It can be understood that the method for laying out the initial directed graph is basically the same as the method for re-layouting the second directed graph in the above embodiment. For the specific processing of steps S306-S310 when laying out the initial directed graph, you can refer to the corresponding processing of the corresponding steps when re-layouting the second directed graph, which will not be repeated here.
[0104] Example 4
[0105] The above embodiments provide methods for laying out an initial directed graph and a non-initial directed graph. Those skilled in the art will understand that, through the methods provided in the above embodiments, the initial directed graph can be optimized and laid out to obtain a first directed graph after optimized layout; according to the operation on the first directed graph after optimized layout, the second directed graph to be laid out can be obtained from the first directed graph that has been optimized, and the second directed graph can be re-laid to obtain the second directed graph after optimized layout; according to the operation on the second directed graph after optimized layout, the third directed graph to be laid out can be obtained from the second directed graph that has been optimized, and the third directed graph can be re-laid to obtain the third directed graph after optimized layout;... According to the operation on the Nth directed graph after optimized layout, the N+1th directed graph to be laid out can be obtained based on the Nth directed graph after optimized layout, and the N+1th directed graph can be re-laid to obtain the N+1th directed graph after optimized layout. To facilitate further understanding of the technical solution provided in the embodiment of the present application, this embodiment provides another directed graph layout algorithm. FIG13 is a flow chart of another directed graph layout algorithm provided in the embodiment of the present application. As shown in FIG13 , the directed graph layout algorithm provided in the embodiment of the present application may include the following steps:
[0106] S402: Obtain the current directed graph to be laid out.
[0107] The current directed graph to be laid out may be an initial directed graph, or may be obtained from a previous directed graph based on an operation on the previous directed graph. The operation on the previous directed graph may include, for example, collapsing downstream nodes of a specified node in the previous directed graph, expanding downstream nodes of a specified node in the previous directed graph, or adding downstream nodes of a specified node in the previous directed graph.
[0108] S404: Determine the initial level of each node in the current directed graph and the initial order of each node in the level.
[0109] Among them, if the current directed graph is an initial directed graph, the initial level of each node can be determined according to the hierarchical structure of the nodes, and then, for the nodes at the same level, they can be pre-sorted according to the specified rules to obtain their initial order in the level. If the current directed graph is not an initial directed graph, the initial level of each node in the current directed graph that intersects with the previous directed graph and the initial order of each node in its level can be determined based on the level of each node in the cached previous directed graph and the order of each node in its level. The initial level and initial order of other nodes outside the intersection can be determined according to a specified sorting algorithm, or can be specified arbitrarily.
[0110] S406, optimizing the level of each node in the current directed graph according to a preset optimization strategy to obtain the optimized level of each node in the current directed graph; wherein the preset optimization strategy includes: an optimization strategy with the goal of minimizing the sum of the lengths of all directed edges in the second directed graph.
[0111] S408, with the goal of minimizing the number of line crossings in the current directed graph, iterate the current directed graph multiple times to determine the optimized order of each node in the current directed graph in its own level; wherein, in each iteration, the order of each node in the current directed graph in its own level is adjusted according to a preset sorting algorithm.
[0112] S410 , laying out the current directed graph according to the optimization level of each node in the current directed graph and the optimization order of each node in the current directed graph in the level.
[0113] It can be understood that the method for laying out the current directed graph is basically the same as the method for re-layouting the second directed graph in the above embodiment. The specific processing of steps S406 to S410 can refer to the corresponding steps in the above embodiment and will not be repeated here.
[0114] In the visualization application of directed graphs, multiple folding and unfolding operations may be performed, and there is no specific order between the folding and unfolding operations. As shown in Figure 11, node 8 is the common downstream node of node 7 and node 2. When the downstream nodes of 7 are hidden first, node 8 is hidden. When the downstream nodes of node 2 are hidden again, node 8 is not included in the hidden downstream nodes. When the downstream nodes of node 2 are unfolded again, if the logic of displaying hidden nodes is used according to the prior art, only the nodes hidden when the downstream nodes of node 2 are hidden will be displayed, that is, node 8 will not be displayed, which will lead to the loss of downstream nodes. The method provided in the embodiment of the present application obtains all downstream nodes of the specified node after each operation on the specified node, deletes all downstream nodes of the specified node in the previous directed graph, or obtains all nodes in the current directed graph after adding the downstream nodes of the specified node, and then rearranges the current directed graph. No matter what the order of the folding and unfolding operations is, and no matter how many folding and unfolding operations are performed, node loss can be avoided.
[0115] Among them, the downstream nodes of the specified node can be obtained from the historical layout of the directed graph based on the operation record. For example, if the downstream nodes of 7 are collapsed first, then the downstream nodes of 2 are collapsed, and then the downstream nodes of node 2 are expanded, the historical layout before folding 7 can be obtained, and all downstream nodes of node 2 can be obtained from the historical layout before folding 7, and then subsequent re-layout processing can be performed. Furthermore, the method provided in this embodiment stores the topological structure after each layout for subsequent use. After the layout, the layout method provided in this embodiment also includes:
[0116] S412 , cache the optimized level of each node in the current directed graph after layout and the optimized order of each node in the level.
[0117] Example 5
[0118] Corresponding to the directed graph method provided in the above embodiment, based on the same technical concept, the embodiment of the present application also provides a directed graph layout device, which is used to execute the directed graph layout method provided in the above embodiment. Figure 14 is a module schematic diagram of the directed graph layout device provided in one embodiment of the present application. As shown in Figure 14, the directed graph layout device 100 provided in this embodiment includes an acquisition module 10, an initial level determination module 20, a level optimization module 30, and a re-layout module 40, wherein:
[0119] An acquisition module 10 is configured to acquire a second directed graph to be re-layout based on the laid-out first directed graph; wherein the second directed graph is a partial directed graph of the first directed graph, or the second directed graph includes the first directed graph;
[0120] an initial level determination module 20, configured to determine the initial level of each node in the second directed graph according to the level of each node in the first directed graph;
[0121] a hierarchical optimization module 30 configured to optimize the hierarchical level of each node in the second directed graph according to a preset optimization strategy to obtain an optimized hierarchical level of each node in the second directed graph; the preset optimization strategy includes an optimization strategy that aims to minimize the sum of the lengths of all directed edges in the second directed graph;
[0122] The rearrangement module 40 is configured to rearrange the second directed graph according to the optimization level of each node in the second directed graph.
[0123] In one implementation, the acquisition module 10 includes:
[0124] a folding unit configured to delete the downstream nodes of the designated node from the first directed graph according to a folding downstream node operation on the designated node in the first directed graph, to obtain a second directed graph to be rearranged; or
[0125] The expansion unit is configured to add the downstream nodes of the designated node in the first directed graph according to the operation of expanding the downstream nodes of the designated node in the first directed graph, so as to obtain the second directed graph to be rearranged.
[0126] In one implementation, the hierarchy optimization module 30 includes:
[0127] a generating unit, configured to generate an initial spanning tree for each node in the second directed graph according to an initial level of each node in the second directed graph;
[0128] A length sum calculation unit, configured to calculate the sum of the lengths of all edges in the initial spanning tree;
[0129] an iterative unit, configured to iterate the initial spanning tree multiple times with the goal of minimizing the sum of the lengths of all edges in the spanning tree; wherein, during each iteration, the levels of the nodes at both ends of the cross-level directed edges in the spanning tree of the current iteration are adjusted to generate a spanning tree for the next iteration;
[0130] The level determination unit is used to determine the optimization level of each node in the second directed graph according to the iterated spanning tree.
[0131] In one implementation, the directed graph layout apparatus 100 further includes:
[0132] A pre-sorting module, configured to pre-sort the order of the nodes in the second directed graph in the level thereof according to the order of the nodes in the first directed graph in the level thereof;
[0133] An order optimization module is configured to iterate the second directed graph multiple times to minimize line crossings in the second directed graph, and determine an optimized order of the nodes in the second directed graph within their respective layers; wherein, during each iteration, the order of the nodes in the second directed graph within their respective layers is adjusted according to a preset sorting algorithm;
[0134] The re-layout module 40 is further configured to re-layout the second directed graph according to the optimization level of each node in the second directed graph and the optimization order of each node in the second directed graph in the level.
[0135] In one implementation, the pre-sorting module includes:
[0136] A level acquisition subunit, which acquires the level of each node in the first directed graph;
[0137] a cross-level determination subunit, configured to determine, based on the levels of the nodes in the first directed graph and the levels of the nodes in the second directed graph, cross-level nodes in which the levels of the nodes in the second directed graph have changed;
[0138] The sorting subunit is configured to sort the cross-level node at the last position of the level to which it belongs when pre-sorting the order of the nodes in the second directed graph in the level to which it belongs.
[0139] In one implementation, the sequence optimization module includes:
[0140] a crossing calculation unit, configured to calculate, after each iteration, the number of crossings of links in the second directed graph after the current iteration;
[0141] An iteration unit is used to, if the number of line crossings in the second directed graph after this iteration is less than the number of line crossings in the directed graph after the previous iteration, use the number of line crossings in the second directed graph after this iteration as the current number of line crossings, and perform the next iteration until the current number of line crossings is minimized.
[0142] In one implementation, the sequence optimization module further includes:
[0143] an importance determining unit, configured to determine, for each level in the second directed graph, an importance value of a node in the level according to a position of the node in the level relative to a node in a level above the level;
[0144] The order adjustment unit is used to adjust the order of the nodes in the layer according to the importance values of the nodes in the layer.
[0145] In one implementation, the re-layout module includes:
[0146] a coordinate calculation unit, which determines the coordinates of each node in the second directed graph according to the level of each node in the second directed graph and the order of each node in the level of each node in the second directed graph;
[0147] A layout unit is used to layout the second directed graph according to the coordinates of each node in the second directed graph.
[0148] In one implementation, the directed graph layout apparatus further includes:
[0149] The cache module is used to cache the optimization level of each node in the second directed graph and the optimization order of each node in the second directed graph in the level.
[0150] It should be noted that the directed graph layout device provided in the embodiment of the present application and the directed graph layout method provided in the embodiment of the present application are based on the same inventive concept. Therefore, the specific implementation of this embodiment can refer to the implementation of the corresponding directed graph layout method mentioned above, and the repeated parts will not be repeated.
[0151] Example 6
[0152] Corresponding to the directed graph layout method provided in the above embodiment, based on the same technical concept, an embodiment of the present application also provides a computer device, which is used to execute the above directed graph layout method, as shown in Figure 15.
[0153] Computer devices can vary significantly depending on their configuration or performance. They may include one or more processors and memory, which may store one or more applications or data. The memory may be either ephemeral or persistent. Applications stored in the memory may include one or more modules, each of which may include a series of computer-executable instructions for the computer device. Furthermore, the processor may be configured to communicate with the memory to execute the series of computer-executable instructions in the memory on the computer device. Computer devices may also include one or more power supplies, one or more wired or wireless network interfaces, one or more input / output interfaces, one or more keyboards, and the like.
[0154] In a specific embodiment, a computer device includes a memory and one or more programs, wherein the one or more programs are stored in the memory, and the one or more programs may include one or more modules, and each module may include a series of computer-executable instructions in the computer device, and the one or more programs are configured to be executed by one or more processors, including computer-executable instructions for performing the following:
[0155] Obtaining a second directed graph to be re-laid out according to the laid out first directed graph; wherein the second directed graph is a partial directed graph of the first directed graph, or the second directed graph includes the first directed graph;
[0156] Determining an initial level of each node in the second directed graph according to the level of each node in the first directed graph;
[0157] Optimizing the level of each node in the second directed graph according to a preset optimization strategy to obtain an optimized level of each node in the second directed graph; the preset optimization strategy includes an optimization strategy that aims to minimize the sum of the lengths of all directed edges in the second directed graph;
[0158] The second directed graph is rearranged according to the optimization level of each node in the second directed graph.
[0159] In one implementation, obtaining the second directed graph to be re-layout according to the laid-out first directed graph includes:
[0160] According to the fold downstream node operation on the designated node in the first directed graph, the downstream node of the designated node is deleted from the first directed graph to obtain a second directed graph to be rearranged; or
[0161] According to the operation of expanding downstream nodes of the designated node in the first directed graph, the downstream nodes of the designated node are added to the first directed graph to obtain a second directed graph to be rearranged.
[0162] In one implementation, optimizing the level of each node in the second directed graph with the goal of minimizing the sum of lengths of all directed edges in the second directed graph to obtain the optimized level of each node in the second directed graph includes:
[0163] generating an initial spanning tree for each node in the second directed graph according to the initial level of each node in the second directed graph;
[0164] Calculating the sum of the lengths of all edges in the initial spanning tree;
[0165] The initial spanning tree is iterated multiple times with the goal of minimizing the sum of the lengths of all edges in the spanning tree; wherein, in each iteration, the levels of the nodes at both ends of the cross-level directed edges in the spanning tree of the current iteration are adjusted to generate a spanning tree for the next iteration;
[0166] The optimized level of each node in the second directed graph is determined according to the iterated spanning tree.
[0167] In one implementation, the method further includes:
[0168] pre-sorting the order of the nodes in the second directed graph in the level they belong to, according to the order of the nodes in the first directed graph in the level they belong to;
[0169] With the goal of minimizing the number of line crossings in the second directed graph, the second directed graph is iterated multiple times to determine an optimized order of the nodes in the second directed graph within the hierarchy; wherein, during each iteration, the order of the nodes in the second directed graph within the hierarchy is adjusted according to a preset sorting algorithm;
[0170] The re-layout of the second directed graph according to the optimization level of each node in the second directed graph includes:
[0171] The second directed graph is rearranged according to the optimization level of each node in the second directed graph and the optimization order of each node in the second directed graph in the level.
[0172] In one implementation, the method further includes:
[0173] Obtaining the level of each node in the first directed graph;
[0174] Determining, based on the levels of the nodes in the first directed graph and the levels of the nodes in the second directed graph, cross-level nodes in which the levels of the nodes in the second directed graph have changed;
[0175] When pre-sorting the order of the nodes in the second directed graph in the level to which they belong, the cross-level node is arranged at the last position in the level to which it belongs.
[0176] In one implementation, optimizing the level of each node in the second directed graph according to a preset optimization strategy to obtain the optimized level of each node in the second directed graph includes:
[0177] After each iteration, the number of line crossings in the second directed graph after the current iteration is calculated;
[0178] If the number of line crossings in the second directed graph after this iteration is less than the number of line crossings in the directed graph after the previous iteration, the number of line crossings in the second directed graph after this iteration is used as the current number of line crossings, and the next iteration is performed until the current number of line crossings is minimized.
[0179] In one implementation, adjusting the order of the nodes in the second directed graph in their respective levels according to a preset sorting algorithm during each iteration includes:
[0180] For each level in the second directed graph, determining the importance value of the nodes in the level according to the positions of the nodes in the level relative to the nodes in the previous level;
[0181] The order of the nodes in the level is adjusted according to the importance values of the nodes in the level.
[0182] In one implementation, laying out the second directed graph according to the level of each node in the second directed graph and the order of each node in the level of the second directed graph includes:
[0183] determining the coordinates of each node in the second directed graph according to the level of each node in the second directed graph and the order of each node in the level of each node in the second directed graph;
[0184] The second directed graph is laid out according to the coordinates of each node in the second directed graph.
[0185] In one implementation, the method further includes:
[0186] The optimized level of each node in the second directed graph and the optimized order of each node in the second directed graph in its level are cached.
[0187] It should be noted that the embodiment of the computer device in this application and the embodiment of the directed graph layout method in this application are based on the same inventive concept. Therefore, the specific implementation of this embodiment can refer to the implementation of the corresponding directed graph layout method mentioned above, and the repeated parts will not be repeated.
[0188] Example 7
[0189] Corresponding to the training method of the time series prediction model and the time series prediction method provided in the embodiments of the present application, based on the same technical concept, the embodiments of the present application also provide a storage medium for storing computer-executable instructions;
[0190] In a specific embodiment, the storage medium may be a USB flash drive, an optical disk, a hard disk, etc. When the computer executable instructions stored in the storage medium are executed by the processor, the following process can be implemented:
[0191] Obtaining a second directed graph to be re-laid out according to the laid out first directed graph; wherein the second directed graph is a partial directed graph of the first directed graph, or the second directed graph includes the first directed graph;
[0192] Determining an initial level of each node in the second directed graph according to the level of each node in the first directed graph;
[0193] The level at which each node in the second directed graph is located is optimized according to a preset optimization strategy to obtain the optimized level at which each node in the second directed graph is located; the preset optimization strategy includes: an optimization strategy whose goal is to minimize the sum of the lengths of all directed edges in the second directed graph.
[0194] The second directed graph is rearranged according to the optimization level of each node in the second directed graph.
[0195] In one implementation, obtaining the second directed graph to be re-layout according to the laid-out first directed graph includes:
[0196] According to the fold downstream node operation on the designated node in the first directed graph, the downstream node of the designated node is deleted from the first directed graph to obtain a second directed graph to be rearranged; or
[0197] According to the operation of expanding downstream nodes of the designated node in the first directed graph, the downstream nodes of the designated node are added to the first directed graph to obtain a second directed graph to be rearranged.
[0198] In one implementation, optimizing the level of each node in the second directed graph according to a preset optimization strategy to obtain the optimized level of each node in the second directed graph includes:
[0199] generating an initial spanning tree for each node in the second directed graph according to the initial level of each node in the second directed graph;
[0200] Calculating the sum of the lengths of all edges in the initial spanning tree;
[0201] The initial spanning tree is iterated multiple times with the goal of minimizing the sum of the lengths of all edges in the spanning tree; wherein, in each iteration, the levels of the nodes at both ends of the cross-level directed edges in the spanning tree of the current iteration are adjusted to generate a spanning tree for the next iteration;
[0202] The optimized level of each node in the second directed graph is determined according to the iterated spanning tree.
[0203] In one implementation, the method further includes:
[0204] pre-sorting the order of the nodes in the second directed graph in the level they belong to, according to the order of the nodes in the first directed graph in the level they belong to;
[0205] With the goal of minimizing the number of line crossings in the second directed graph, the second directed graph is iterated multiple times to determine an optimized order of the nodes in the second directed graph within the hierarchy; wherein, during each iteration, the order of the nodes in the second directed graph within the hierarchy is adjusted according to a preset sorting algorithm;
[0206] The re-layout of the second directed graph according to the optimization level of each node in the second directed graph includes:
[0207] The second directed graph is rearranged according to the optimization level of each node in the second directed graph and the optimization order of each node in the second directed graph in the level.
[0208] In one implementation, the method further includes:
[0209] Obtaining the level of each node in the first directed graph;
[0210] Determining, based on the levels of the nodes in the first directed graph and the levels of the nodes in the second directed graph, cross-level nodes in which the levels of the nodes in the second directed graph have changed;
[0211] When pre-sorting the order of the nodes in the second directed graph in the level to which they belong, the cross-level node is arranged at the last position in the level to which it belongs.
[0212] In one implementation, the step of iterating the second directed graph multiple times with the goal of minimizing the number of crossings of lines in the second directed graph to determine the order of the nodes in the second directed graph in the hierarchy includes:
[0213] After each iteration, the number of line crossings in the second directed graph after the current iteration is calculated;
[0214] If the number of line crossings in the second directed graph after this iteration is less than the number of line crossings in the directed graph after the previous iteration, the number of line crossings in the second directed graph after this iteration is used as the current number of line crossings, and the next iteration is performed until the current number of line crossings is minimized.
[0215] In one implementation, adjusting the order of the nodes in the second directed graph in their respective levels according to a preset sorting algorithm during each iteration includes:
[0216] For each level in the second directed graph, determining the importance value of the nodes in the level according to the positions of the nodes in the level relative to the nodes in the previous level;
[0217] The order of the nodes in the level is adjusted according to the importance values of the nodes in the level.
[0218] In one implementation, laying out the second directed graph according to the level of each node in the second directed graph and the order of each node in the level of the second directed graph includes:
[0219] determining the coordinates of each node in the second directed graph according to the level of each node in the second directed graph and the order of each node in the level of each node in the second directed graph;
[0220] The second directed graph is laid out according to the coordinates of each node in the second directed graph.
[0221] In one implementation, the method further includes:
[0222] The optimization level of each node in the second directed graph and the optimization order of each node in the second directed graph in the level are cached.
[0223] It should be noted that the embodiment of the storage medium in this application and the embodiment of the directed graph layout method in this application are based on the same inventive concept. Therefore, the specific implementation of this embodiment can refer to the implementation of the corresponding directed graph layout method mentioned above, and the repeated parts will not be repeated.
[0224] The foregoing description of this specification describes specific embodiments. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recited in the claims can be performed in an order different from that described in the embodiments and still achieve the desired results. Furthermore, the processes depicted in the accompanying drawings do not necessarily require the specific order shown or the sequential order to achieve the desired results. In certain embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0225] In the 1990s, technological improvements could be clearly distinguished as either hardware improvements (for example, improvements to circuit structures such as diodes, transistors, and switches) or software improvements (improvements to process flows). However, with the advancement of technology, many process flow improvements today can now be considered direct improvements to hardware circuit structures. Designers almost always create the corresponding hardware circuit structure by programming the improved process flow into the hardware circuit. Therefore, it cannot be said that a process flow improvement cannot be implemented using hardware modules. For example, a programmable logic device (PLD), such as a field programmable gate array (FPGA), is an integrated circuit whose logical function is determined by user programming. Designers can "integrate" a digital system on a PLD by programming it themselves, without having to hire a chip manufacturer to design and manufacture a dedicated integrated circuit chip. Moreover, nowadays, instead of manually fabricating integrated circuit chips, this programming is mostly done using "logic compiler" software. This is similar to the software compiler used when developing programs. Before compilation, the original code must also be written in a specific programming language, called a hardware description language (HDL). There is not just one HDL, but many, such as ABEL (Advanced Boolean Expression Language), AHDL (Altera Hardware Description Language), Confluence, CUPL (Cornell University Programming Language), HDCal, JHDL (Java Hardware Description Language), Lava, Lola, MyHDL, PALASM, RHDL (Ruby Hardware Description Language), etc. The most commonly used are VHDL (Very-High-Speed Integrated Circuit Hardware Description Language) and Verilog. Those skilled in the art will also understand that by simply programming the method flow in one of these hardware description languages and then programming it into an integrated circuit, a hardware circuit that implements the logic method flow can be easily obtained.
[0226] The controller can be implemented in any suitable manner. For example, the controller can take the form of a microprocessor or processor and a computer-readable medium storing computer-readable program code (e.g., software or firmware) executable by the (micro)processor, logic gates, switches, application-specific integrated circuits (ASICs), programmable logic controllers, and embedded microcontrollers. Examples of controllers include, but are not limited to, the following microcontrollers: ARC 625D, Atmel AT91SAM, Microchip PIC18F26K20, and Silicone Labs C8051F320. The memory controller can also be implemented as part of the control logic of the memory. Those skilled in the art will also know that in addition to implementing the controller in a purely computer-readable program code format, the controller can be implemented in the form of logic gates, switches, application-specific integrated circuits, programmable logic controllers, and embedded microcontrollers by logically programming the method steps. Therefore, such a controller can be considered a hardware component, and the devices included therein for implementing various functions can also be considered as structures within the hardware component. Or even, the devices for implementing various functions can be considered as both software modules that implement the method and structures within the hardware component.
[0227] The systems, devices, modules, or units described in the above embodiments may be implemented by computer chips or entities, or by products having certain functions. A typical implementation device is a computer. Specifically, the computer may be, for example, a personal computer, a laptop computer, a cellular phone, a camera phone, a smartphone, a personal digital assistant, a media player, a navigation device, an email device, a game console, a tablet computer, a wearable device, or a combination of any of these devices.
[0228] For the convenience of description, the above devices are described as being divided into various units according to their functions. Of course, when implementing one or more embodiments of this specification, the functions of each unit can be implemented in the same or multiple software and / or hardware.
[0229] Those skilled in the art will appreciate that the embodiments of this specification may be provided as methods, systems, or computer program products. Therefore, one or more embodiments of this specification may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Furthermore, one or more embodiments of this specification may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0230] The embodiments of this specification are described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of this specification. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes 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 serial and parallel device to produce a machine, so that the instructions executed by the processor of the computer or other programmable serial and parallel device produce a device for implementing the functions specified in one or more processes in the flowchart and / or one or more boxes in the block diagram.
[0231] These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable serial and parallel device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce a product including an instruction device that implements the functions specified in one or more processes in the flowchart and / or one or more boxes in the block diagram.
[0232] These computer program instructions may also be loaded onto a computer or other programmable fraud case serial and parallel device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, whereby the instructions executed on the computer or other programmable device provide steps for implementing the functions specified in one or more processes in the flowchart and / or one or more boxes in the block diagram.
[0233] In a typical configuration, a computing device includes one or more processors (CPUs), input / output interfaces, network interfaces, and memory.
[0234] Memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. Memory is an example of a computer-readable medium.
[0235] Computer-readable media includes permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. The information can be computer-readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassettes, magnetic tape, magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer-readable media does not include transitory computer-readable media (transitory media), such as modulated data signals and carrier waves.
[0236] It should also be noted that the terms "comprises," "includes," or any other variations thereof are intended to encompass non-exclusive inclusion, such that a process, method, commodity, or apparatus that includes a series of elements includes not only those elements but also other elements not explicitly listed, or includes elements inherent to such process, method, commodity, or apparatus. In the absence of further limitations, an element defined by the phrase "comprises a ..." does not exclude the presence of other identical elements in the process, method, commodity, or apparatus that includes the element.
[0237] Those skilled in the art will appreciate that the embodiments of this specification may be provided as methods, systems, or computer program products. Thus, one or more embodiments of this specification may take the form of a fully hardware embodiment, a fully software embodiment, or an embodiment combining software and hardware. Furthermore, one or more embodiments of this specification may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0238] One or more embodiments of this specification may be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, and the like that perform specific tasks or implement specific abstract data types. One or more embodiments of this specification may also be practiced in distributed computing environments where tasks are performed by remote processing devices connected via a communications network. In a distributed computing environment, program modules may be located in local and remote computer storage media, including storage devices.
[0239] The various embodiments in this specification are described in a progressive manner. Similar parts between the various embodiments can be referred to in conjunction with each other. Each embodiment focuses on the differences between the other embodiments. In particular, the system embodiments are generally similar to the method embodiments, so the description is relatively simple. For relevant parts, refer to the description of the method embodiments.
[0240] The foregoing is merely an example of the present invention and is not intended to limit the present application. Various modifications and variations are possible for those skilled in the art. Any modifications, equivalent substitutions, or improvements made within the spirit and principles of this specification are intended to be included within the scope of the claims of this specification.
Claims
1. A directed graph layout method, the method comprising: Acquire a second directed graph to be re-layout according to the laid out first directed graph; wherein the second directed graph is a local directed graph of the first directed graph, or the second directed graph includes the first directed graph; Determining an initial level at which each node in the second directed graph is located according to the level at which each node in the first directed graph is located; Optimizing the level of each node in the second directed graph according to a preset optimization strategy to obtain the optimized level of each node in the second directed graph; the preset optimization strategy includes: an optimization strategy with the goal of minimizing the sum of the lengths of all directed edges in the second directed graph; The second directed graph is rearranged according to the optimization level of each node in the second directed graph.
2. According to the directed graph layout method of claim 1, the step of obtaining the second directed graph to be re-layout according to the laid out first directed graph comprises: According to the folding downstream node operation of the designated node in the first directed graph, the downstream node of the designated node is deleted from the first directed graph to obtain a second directed graph to be rearranged; or According to the operation of expanding downstream nodes of the designated node in the first directed graph, the downstream nodes of the designated node are added to the first directed graph to obtain the second directed graph to be rearranged.
3. The method according to claim 1, wherein optimizing the level of each node in the second directed graph according to a preset optimization strategy to obtain the optimized level of each node in the second directed graph comprises: Generate an initial spanning tree for each node in the second directed graph according to the initial level of each node in the second directed graph; Calculate the sum of the lengths of all directed edges in the initial spanning tree; The initial spanning tree is iterated multiple times with the goal of minimizing the sum of the lengths of all directed edges in the spanning tree; wherein, in each iteration, the node levels at both ends of the cross-level directed edges in the spanning tree of the current iteration are adjusted to generate a spanning tree for the next iteration; The optimization level of each node in the second directed graph is determined according to the iterated spanning tree.
4. The directed graph layout method according to any one of claims 1 to 3, further comprising: Pre-sorting the order of each node in the second directed graph in its level according to the order of each node in the first directed graph in its level; The second directed graph is iterated multiple times with the goal of minimizing the number of line crossings in the second directed graph to determine the optimized order of each node in the second directed graph in its level; wherein, in each iteration, the order of each node in the second directed graph in its level is adjusted according to a preset sorting algorithm; re-layout the second directed graph according to the optimization level of each node in the second directed graph, include: The second directed graph is rearranged according to the optimization level of each node in the second directed graph and the optimization order of each node in the second directed graph in the level.
5. The method according to claim 4, further comprising: Obtaining the level of each node in the first directed graph; Determine, according to the level at which each node in the first directed graph is located and the level at which each node in the second directed graph is located, a cross-level node in which the level at which the node in the second directed graph is located is changed; When pre-sorting the order of the nodes in the second directed graph in the level to which they belong, the cross-level node is arranged at the last position of the level to which it belongs.
6. The method according to claim 4, wherein the second directed graph is iterated multiple times with the goal of minimizing the number of crossings of the lines in the second directed graph, and the order of the nodes in the second directed graph in the level to which they belong is determined, comprising: After each iteration, the number of line crossings in the second directed graph after the iteration is calculated; If the number of line crossings in the second directed graph after this iteration is less than the number of line crossings in the directed graph after the previous iteration, the number of line crossings in the second directed graph after this iteration is used as the current number of line crossings, and the next iteration is performed until the current number of line crossings is minimized.
7. The method according to claim 4, wherein: In each iteration, adjusting the order of each node in the second directed graph in its level according to a preset sorting algorithm includes: For each level in the second directed graph, determining the importance value of the nodes in the level according to the positions of the nodes in the level relative to the nodes in the previous level; The order of the nodes in the level is adjusted according to the importance values of the nodes in the level.
8. The directed graph layout method according to claim 4, wherein the second directed graph is laid out according to the optimization level of each node in the second directed graph and the optimization order of each node in the second directed graph in the level where the node is located, comprising: Determining the coordinates of each node in the second directed graph according to the optimization level of each node in the second directed graph and the optimization order of each node in the second directed graph in its level; The second directed graph is laid out according to the coordinates of each node in the second directed graph.
9. The method according to claim 4, further comprising: The optimization level of each node in the second directed graph and the optimization order of each node in the second directed graph in its level are cached.
10. A directed graph layout device, the device comprising: An acquisition module, configured to acquire a second directed graph to be re-arranged according to the laid out first directed graph; wherein the second directed graph is a local directed graph of the first directed graph, or the second directed graph includes the first directed graph; An initial level determination module, used to determine the initial level of each node in the second directed graph according to the level of each node in the first directed graph; A hierarchical optimization module, configured to optimize the hierarchies of the nodes in the second directed graph according to a preset optimization strategy to obtain the optimized hierarchies of the nodes in the second directed graph; the preset optimization strategy includes: an optimization strategy with the goal of minimizing the sum of the lengths of all directed edges in the second directed graph; A rearrangement module is used to rearrange the second directed graph according to the optimization level of each node in the second directed graph.
11. A computer device, comprising: processor; as well as A memory arranged to store computer executable instructions, the executable instructions being configured to be executed by the processor, the executable instructions comprising instructions for executing the steps in the method according to any one of claims 1 to 9.
12. A storage medium for storing computer-executable instructions, wherein the executable instructions enable a computer to execute the method according to any one of claims 1 to 9.
Citation Information
Patent Citations
Monitoring data processing method and device, storage medium and electronic equipment
CN113176975A
Graph visualization method and system based on ring constraint and stress model
CN113536663A
Directed graph layout method and device, equipment and storage medium
CN117009608A
Method of Stable Incremental Layout For a Hierarchical Graph Representation
US20080246769A1
Cited By
Business process topological graph construction method, electronic equipment and readable storage medium
CN121326693A