A hierarchical automatic layout method and device for internal module graph
By constructing a basic hierarchical structure, scanning nested relationships, and establishing virtual connections, and optimizing node and port positions, the complex layout problem of SysML's internal module graph is solved, achieving efficient and readable hierarchical automatic layout.
Patent Information
- Application Number
- CN202511660511.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-13
- Publication Date
- 2026-01-27
- Estimated Expiration
- 2045-11-13
AI Technical Summary
Existing hierarchical automatic layout methods cannot effectively cover complex structures when processing internal module graphs in SysML, resulting in poor layout effects, numerous edge intersections, and severe node overlaps, which reduces the readability of the graph and the user experience.
By acquiring node, line, and port information from the internal module graph, a basic hierarchical structure is constructed, nesting relationships are scanned, virtual connections are established, node and port positions and sorting are optimized, connection intersections are reduced, and layering and connection processing are performed using a graph manager, hierarchy partitioning device, and layout allocation device to restore the minimum intersection situation.
It achieves complete coverage of complex SysML internal module diagrams, improves layout readability and efficiency, reduces line intersections, and enhances user experience.
Smart Images

Figure CN121093650B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of system modeling technology, specifically relating to a hierarchical automatic layout method and apparatus for internal module diagrams. Background Technology
[0002] In the field of system modeling, the Internal Block Diagram (IBD) in SysML (System Modeling Language) is an important diagram type used to illustrate the modules of a system and the relationships between their internal components. After constructing the IBD, a hierarchical automatic layout method is needed to ensure that the diagram elements are arranged neatly and aesthetically according to certain rules.
[0003] Existing hierarchical auto-layout methods, such as the Sugiyama framework, perform well when handling simple nodes. However, they fail to effectively cover all graph elements when dealing with complex structures in SysML's internal module graphs, such as ports on nodes, multi-level nested graph elements, and complex connection paths, resulting in layouts that do not meet expectations. Furthermore, existing hierarchical auto-layout methods suffer from problems such as numerous edge intersections, severe node overlap, and low layout efficiency when handling large-scale graphs. These issues not only affect graph readability but also degrade the user experience. Summary of the Invention
[0004] The purpose of this invention is to overcome the shortcomings of the prior art and provide a hierarchical automatic layout method and apparatus for internal module diagrams. The solution of this invention can solve the problems existing in the prior art.
[0005] The technical solution of this invention:
[0006] According to the first aspect, a hierarchical automatic layout method for internal module diagrams is provided, including the following steps:
[0007] Step 1: Obtain all node information, line information, and port information of the outer layer in the internal module diagram, and use lines to connect the nodes and ports according to the basic hierarchical structure to form the initial shape of the model diagram layout;
[0008] Step 2: Scan each node to obtain all node information, line information, and port information within it. If nesting relationships exist, use the nesting information as the subgraph of the current node.
[0009] Step 3: Scan each node of the nested information to obtain all node information, line information, and port information within it. If a nesting relationship exists, treat the nested information as a subgraph of the current node and connect the nodes and ports using lines according to the basic hierarchical structure to form the initial shape of the nested graph layout.
[0010] Step four, repeat step three until all nested relationships are obtained and arranged;
[0011] Step 5: Determine the virtual connections between different nested node relationships, and connect the virtual connections to the outermost node;
[0012] Step 6: Based on the information obtained in the above steps, modify the initial shape of the model layout to obtain the final shape of the model layout, specifically including:
[0013] S6.1, Determine the location and size of nodes and ports:
[0014] S6.2, determine the order of nodes at the same level;
[0015] S6.3, Determine the port order;
[0016] S6.4 Assign coordinates to nodes and ports according to the sorting results of nodes and ports;
[0017] S6.5, determine the rules for connecting lines, calculate the minimum intersection of lines between levels, and connect lines according to the minimum intersection; restore lines reversed according to the basic hierarchical structure method to their original state.
[0018] Furthermore, the method for the basic hierarchical structure includes the following steps:
[0019] S1.1 Traverse all nodes. If a cycle exists, find the key line that constitutes the cycle, reverse its in and out directions, and record the line. Find the node with an in-degree of 0 and use it as the first-level node of the hierarchical layout.
[0020] S1.2 Starting from the first-level node, the nodes connected to it are sequentially layered. The node that the first-level node points to through a line is the second-level node, and so on. All nodes are assigned a level. If a node has been assigned a level multiple times, the level with the largest sequence number is selected as the level of this node.
[0021] S1.3 For cross-level connected node relationships, that is, when the level difference between two adjacent nodes is greater than 1, virtual nodes need to be established between their intermediate levels. The number of virtual nodes is the level difference between two adjacent nodes minus 1, and the virtual nodes are connected sequentially, so that each node is only connected to its adjacent nodes.
[0022] S1.4 Calculate the position and size of each level: Level width = width of the widest node in the current level, Level height = sum of heights of nodes within the level + sum of spacing between nodes in the same level, Starting horizontal coordinate of each node = Starting position of the previous level + width of the previous level + width of the level interval, Starting vertical coordinate of each node = (height of the highest level - height of the current level) / 2.
[0023] Furthermore, the method for determining the location and size of nodes and ports includes the following steps:
[0024] S6.1.1 Determine the direction of the port: For each port contained in a node, calculate the out-degree and in-degree of the port. If the out-degree is greater than the in-degree, the port is placed on the right side of the node; otherwise, the port is placed on the left side of the node. If there is a nested port, determine the out-degree and in-degree of the nested port. If the out-degree is greater than the in-degree, the port is placed on the right side of the nested port; otherwise, the port is placed on the left side of the nested port.
[0025] S6.1.2 Determine the height of nodes and ports: Based on the number of ports and lines on the same side of the node / port, the height of one side of the node / port = the sum of the heights of the ports it contains + the port spacing * the number of ports it contains + the line spacing * the number of lines. The maximum height of the node / port on both the left and right sides is the node / port height.
[0026] Furthermore, the method for determining the sorting of nodes in the same layer is as follows: sort every two adjacent layers of nodes in turn, and find the arrangement with the smallest number of line intersections: when the number of nodes in the layer is small, use full permutations to find all arrangements and find the sequence with the fewest line intersections; when the number of nodes in the layer is large, obtain a certain number of random sorting sequences of nodes in the layer by specifying the number of iterations, and compare them to find the sequence with the smallest number of intersections.
[0027] Furthermore, the method for determining the port sorting is as follows: sort the ports on one side of each node and find the arrangement with the minimum number of line intersections: when the number of ports is small, use full permutations to find all arrangements and find the sequence with the fewest line intersections; when the number of ports is large, specify the number of iterations, obtain a certain number of random port sorting sequences, and compare to find the sequence with the smallest number of intersections.
[0028] Furthermore, the rules for the connection are as follows:
[0029] S6.5.1 Sort the lines on one side of each node / port: when the starting points of the lines are the same, sort them according to the order of the ordinates of the endpoints they are connected to; when the endpoints of the lines are the same, sort them according to the order of the ordinates of the starting points they are connected to.
[0030] The sorting rule for virtual node connections is based on the original starting point and original ending point of the connection, and the above steps are performed to sort the connections.
[0031] S6.5.2 Assigning Inflection Points of Coordinate Lines: A line needs to make two turns from its starting point to reach its endpoint. All connections between any two adjacent layers are processed uniformly. The inflection point assignments are sorted according to the connection order. Each connection is compared sequentially with its preceding connections to set its inflection point sequence. The inflection point results must conform to the following rules:
[0032] If the coordinates of the starting point of the current connection are greater than the coordinates of the starting point of the previous connection and the coordinates of the ending point of the current connection are greater than the coordinates of the ending point of the previous connection, then the coordinates of the inflection point of the current connection are greater than the coordinates of the inflection point of the previous connection; otherwise, the coordinates of the inflection point of the current connection are less than the coordinates of the inflection point of the previous connection.
[0033] If the coordinates of the starting point of the current connection are greater than the coordinates of the starting point of the previous connection and the coordinates of the ending point of the current connection are less than the coordinates of the ending point of the previous connection: the order of the starting point and ending point coordinates of the two connections is inconsistent, the intersection between the connections is unavoidable, and the coordinates of the inflection point of the current connection are not related to the coordinates of the inflection point of the previous connection.
[0034] The coordinates of the starting point of the current connection are less than the coordinates of the starting point of the previous connection and the coordinates of the ending point of the current connection are greater than the coordinates of the ending point of the previous connection. The order of the starting point and ending point coordinates of the two connections is inconsistent, and the intersection between the connections is unavoidable. The coordinates of the inflection point of the current connection are not related to the coordinates of the inflection point of the previous connection.
[0035] The coordinates of the starting point of the current connection are less than the coordinates of the starting point of the previous connection and the coordinates of the ending point of the current connection are less than the coordinates of the ending point of the previous connection. If the coordinates of the starting point of the current connection are greater than the coordinates of the ending point, then the coordinates of the inflection point of the current connection are less than the coordinates of the inflection point of the previous connection; otherwise, the coordinates of the inflection point of the current connection are greater than the coordinates of the inflection point of the previous connection.
[0036] S6.5.3 connects the edges that were separated by creating virtual nodes, so that all line segments are connected together. When the ordinate of a line is less than a certain difference, the ordinate of a line segment is changed so that the connection point of the two line segments is a straight line, reducing the number of inflection points when connecting.
[0037] Furthermore, the hierarchical automatic layout method for internal module graphs also includes restoring virtual contiguous nodes to their original points.
[0038] According to the second aspect, a hierarchical automatic layout device for internal module diagrams is provided, comprising a graph manager, a hierarchy division device, a layout allocation device, and a line processing device. The graph manager constructs sub-graphs at all levels based on the nesting relationship of nodes in the internal module diagram, and obtains all node information, line information, and port information, which is then sent to the hierarchy division device. The hierarchy division device divides the outer layer nodes and sub-graph nodes at all levels into layers and sends the results to the layout allocation device. The layout allocation device determines the position and size of nodes and ports, sorts nodes within the same level, arranges ports, and sends the results to the line processing device. The line processing device performs connection processing on the obtained nodes and ports, and uses virtual connections to connect the top-level model diagram of the sub-graph when there are connections in different sub-graphs. The connections and virtual connections are arranged to obtain the arrangement with the fewest intersections.
[0039] Furthermore, the graph manager restores the virtual connections to their original connection positions.
[0040] The beneficial effects of this invention compared to the prior art are as follows:
[0041] (1) The method proposed in this invention breaks through the limitation that the traditional hierarchical automatic layout method is only applicable to simple graph elements. During the layout process, the ports and graph element nesting involved in the internal module graph are taken into account, realizing a hierarchical automatic layout method that fully covers the internal module graph elements.
[0042] (2) By sorting nodes in the same layer, sorting ports on the same side of the same node, and sorting inflection points of connections between adjacent layers in a multi-round sorting method, the number of intersections between connections is effectively reduced when connecting ports, thus improving the readability of the layout diagram.
[0043] (3) In the case of nested nodes, the present invention uses the method of creating subgraphs. For the connection of different nested subgraphs, the method of establishing virtual connection in the subgraph of the nearest common ancestor node is used, which effectively solves the layout problem of cross-graph connection. Attached Figure Description
[0044] The accompanying drawings, which form part of this specification, are used to provide a further understanding of the embodiments of the invention and illustrate the principles of the invention together with the textual description. Obviously, the drawings described below are merely some embodiments of the invention, and those skilled in the art can obtain other drawings based on these drawings without creative effort.
[0045] Figure 1 The diagram illustrates the steps of a hierarchical automatic layout method for internal module diagrams according to an embodiment of the present invention.
[0046] Figure 2 A schematic diagram of a hierarchical automatic layout device for internal module diagrams provided according to an embodiment of the present invention is shown.
[0047] Figure 3 A flowchart illustrating the construction of a virtual connection according to an embodiment of the present invention is shown;
[0048] Figure 4 An example diagram of constructing a virtual connection according to an embodiment of the present invention is shown;
[0049] Figure 5 A flowchart for establishing a virtual node according to an embodiment of the present invention is shown;
[0050] Figure 6 An example diagram of constructing a virtual node according to an embodiment of the present invention is shown;
[0051] Figure 7An example diagram of virtual node connection sorting provided according to an embodiment of the present invention is shown;
[0052] Figure 8 A flowchart of line processing rules provided according to an embodiment of the present invention is shown;
[0053] Figure 9 An example diagram of the sorting of inflection points of the connecting lines according to an embodiment of the present invention is shown;
[0054] Figure 10 An example diagram of a hierarchical automatic layout method for internal module diagrams provided according to an embodiment of the present invention is shown. Detailed Implementation
[0055] It should be noted that, unless otherwise specified, the embodiments and features described in this application can be combined with each other. The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of the present invention, and not all of them. The following description of at least one exemplary embodiment is merely illustrative and is in no way intended to limit the present invention or its application or use. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0056] It should be noted that the terminology used herein is for the purpose of describing particular embodiments only and is not intended to limit the exemplary embodiments according to this application. As used herein, the singular form is intended to include the plural form as well, unless the context clearly indicates otherwise. Furthermore, it should be understood that when the terms "comprising" and / or "including" are used in this specification, they indicate the presence of features, steps, operations, devices, components, and / or combinations thereof.
[0057] Unless otherwise specifically stated, the relative arrangement, numerical expressions, and values of the components and steps set forth in these embodiments do not limit the scope of the invention. It should also be understood that, for ease of description, the dimensions of the various parts shown in the drawings are not drawn to actual scale. Techniques, methods, and devices known to those skilled in the art may not be discussed in detail, but where appropriate, such techniques, methods, and devices should be considered part of the specification. In all examples shown and discussed herein, any specific values should be interpreted as merely exemplary and not as limitations. Therefore, other examples of exemplary embodiments may have different values. It should be noted that similar reference numerals and letters in the following figures denote similar items; therefore, once an item is defined in one figure, it need not be further discussed in subsequent figures.
[0058] like Figure 1 As shown, according to a first aspect embodiment of the present invention, a hierarchical automatic layout method for internal module diagrams is provided, comprising the following steps:
[0059] Step 1: Obtain all node information, line information, and port information of the outer layer in the internal module diagram, and use lines to connect the nodes and ports according to the basic hierarchical structure to form the initial shape of the model diagram layout;
[0060] Step 2: Scan each node to obtain all node information, line information, and port information within it. If nesting relationships exist, use the nesting information as the subgraph of the current node.
[0061] Step 3: Scan each node of the nested information to obtain all node information, line information, and port information within it. If a nesting relationship exists, treat the nested information as a subgraph of the current node and connect the nodes and ports using lines according to the basic hierarchical structure to form the initial shape of the nested graph layout.
[0062] Step four, repeat step three until all nested relationships are obtained and arranged;
[0063] Step 5: Determine the virtual connections between different nested node relationships, and connect the virtual connections to the outermost node;
[0064] Step 6: Based on the information obtained in the above steps, modify the initial shape of the model layout to obtain the final shape of the model layout, specifically including:
[0065] S6.1, Determine the location and size of nodes and ports:
[0066] S6.2, determine the order of nodes at the same level;
[0067] S6.3, Determine the port order;
[0068] S6.4 Assign coordinates to nodes and ports according to the sorting results of nodes and ports;
[0069] S6.5, determine the rules for connecting lines, calculate the minimum intersection of lines between levels, and connect lines according to the minimum intersection; restore lines reversed according to the basic hierarchical structure method to their original state.
[0070] By taking into account the ports and nesting of graph elements involved in the internal module diagram through the above steps, a hierarchical automatic layout method that fully covers the internal module diagram elements is realized.
[0071] In a further embodiment, the basic hierarchy method includes the following steps:
[0072] S1.1 Traverse all nodes. If a cycle exists, find the key line that constitutes the cycle, reverse its in and out directions, and record the line. Find the node with an in-degree of 0 and use it as the first-level node of the hierarchical layout.
[0073] S1.2 Starting from the first-level node, the nodes connected to it are sequentially layered. The node that the first-level node points to through a line is the second-level node, and so on. All nodes are assigned a level. If a node has been assigned a level multiple times, the level with the largest sequence number is selected as the level of this node.
[0074] S1.3 For cross-level connected node relationships, that is, when the level difference between two adjacent nodes is greater than 1, virtual nodes need to be established between their intermediate levels. The number of virtual nodes is the level difference between two adjacent nodes minus 1, and the virtual nodes are connected sequentially, so that each node is only connected to its adjacent nodes.
[0075] S1.4 Calculate the position and size of each level: Level width = width of the widest node in the current level, Level height = sum of heights of nodes within the level + sum of spacing between nodes in the same level, Starting horizontal coordinate of each node = Starting position of the previous level + width of the previous level + width of the level interval, Starting vertical coordinate of each node = (height of the highest level - height of the current level) / 2.
[0076] In a further embodiment, the method for determining the location and size of nodes and ports includes the following steps:
[0077] S6.1.1 Determine the direction of the port: For each port contained in a node, calculate the out-degree and in-degree of the port. If the out-degree is greater than the in-degree, the port is placed on the right side of the node; otherwise, the port is placed on the left side of the node. If there is a nested port, determine the out-degree and in-degree of the nested port. If the out-degree is greater than the in-degree, the port is placed on the right side of the nested port; otherwise, the port is placed on the left side of the nested port.
[0078] S6.1.2 Determine the height of nodes and ports: Based on the number of ports and lines on the same side of the node / port, the height of one side of the node / port = the sum of the heights of the ports it contains + the port spacing * the number of ports it contains + the line spacing * the number of lines. The maximum height of the node / port on both the left and right sides is the node / port height.
[0079] In a further embodiment, the method for determining the sorting of nodes in the same layer is as follows: Sort every two adjacent layers of nodes sequentially to find the arrangement with the minimum number of line intersections. When the number of nodes in a layer is small, use all permutations to find all possible arrangements and identify the sequence with the fewest line intersections. When the number of nodes in a layer is large, obtain a certain number of random sorting sequences of nodes in the layer by specifying the number of iterations, and compare them to find the sequence with the smallest number of intersections. Using this method, the minimum number of intersections can be obtained while ensuring computational speed.
[0080] In a further embodiment, the method for determining the port sorting is as follows: sort the ports on one side of each node and find the arrangement with the minimum number of line intersections: when the number of ports is small, use all permutations to find all arrangements and find the sequence with the fewest line intersections; when the number of ports is large, specify the number of iterations to obtain a certain number of random port sorting sequences, and compare them to find the sequence with the fewest intersections. Using this method, the minimum number of intersections can be obtained while ensuring computational speed.
[0081] In another embodiment, the connection rules are as follows:
[0082] S6.5.1 Sort the lines on one side of each node / port: when the starting points of the lines are the same, sort them according to the order of the ordinates of the endpoints they are connected to; when the endpoints of the lines are the same, sort them according to the order of the ordinates of the starting points they are connected to.
[0083] The sorting rule for virtual node connections is based on the original starting point and original ending point of the connection, and the above steps are performed to sort the connections.
[0084] S6.5.2 Assigning Inflection Points of Coordinate Lines: A line needs to make two turns from its starting point to reach its endpoint. All connections between two adjacent layers are processed uniformly. The inflection point assignments are sorted according to the connection sorting results. Each connection is compared sequentially with its preceding connections to set its inflection point sequence. For example... Figure 7 As shown, the inflection point results must meet the following rules:
[0085] If the coordinates of the starting point of the current connection are greater than the coordinates of the starting point of the previous connection and the coordinates of the ending point of the current connection are greater than the coordinates of the ending point of the previous connection, then the coordinates of the inflection point of the current connection are greater than the coordinates of the inflection point of the previous connection; otherwise, the coordinates of the inflection point of the current connection are less than the coordinates of the inflection point of the previous connection.
[0086] If the coordinates of the starting point of the current connection are greater than the coordinates of the starting point of the previous connection and the coordinates of the ending point of the current connection are less than the coordinates of the ending point of the previous connection: the order of the starting point and ending point coordinates of the two connections is inconsistent, the intersection between the connections is unavoidable, and the coordinates of the inflection point of the current connection are not related to the coordinates of the inflection point of the previous connection.
[0087] The coordinates of the starting point of the current connection are less than the coordinates of the starting point of the previous connection and the coordinates of the ending point of the current connection are greater than the coordinates of the ending point of the previous connection. The order of the starting point and ending point coordinates of the two connections is inconsistent, and the intersection between the connections is unavoidable. The coordinates of the inflection point of the current connection are not related to the coordinates of the inflection point of the previous connection.
[0088] The coordinates of the starting point of the current connection are less than the coordinates of the starting point of the previous connection and the coordinates of the ending point of the current connection are less than the coordinates of the ending point of the previous connection. If the coordinates of the starting point of the current connection are greater than the coordinates of the ending point, then the coordinates of the inflection point of the current connection are less than the coordinates of the inflection point of the previous connection; otherwise, the coordinates of the inflection point of the current connection are greater than the coordinates of the inflection point of the previous connection.
[0089] S6.5.3 connects the edges that were separated by creating virtual nodes, so that all line segments are connected together. When the ordinate of a line is less than a certain difference, the ordinate of a line segment is changed so that the connection point of the two line segments is a straight line, reducing the number of inflection points when connecting.
[0090] In a further embodiment, a hierarchical automatic layout method for internal module graphs also includes restoring virtual contiguous nodes to their original points. This setting better restores the realism of the internal module graph.
[0091] According to the second aspect, a hierarchical automatic layout device for internal module diagrams is provided, comprising a graph manager, a hierarchy division device, a layout allocation device, and a line processing device. The graph manager constructs sub-graphs at all levels based on the nesting relationship of nodes in the internal module diagram, and obtains all node information, line information, and port information, which is then sent to the hierarchy division device. The hierarchy division device divides the outer layer nodes and sub-graph nodes at all levels into layers and sends the results to the layout allocation device. The layout allocation device determines the position and size of nodes and ports, sorts nodes within the same level, arranges ports, and sends the results to the line processing device. The line processing device performs connection processing on the obtained nodes and ports, and uses virtual connections to connect the top-level model diagram of the sub-graph when there are connections in different sub-graphs. The connections and virtual connections are arranged to obtain the arrangement with the fewest intersections.
[0092] Further in one embodiment, such as Figure 2 As shown, the graph manager restores the virtual connections to their original positions.
[0093] To gain a better understanding of the hierarchical automatic layout method for internal module diagrams provided by this invention, a detailed description is provided below with reference to specific examples and accompanying drawings.
[0094] 4.1 Hierarchical Automatic Layout Method and Device Execution Flow for Internal Module Graphs
[0095] The hierarchical automatic layout device for internal module diagrams consists of the following structure: Figure 1As shown, the device comprises four parts: a graph manager, a hierarchy partitioning device, a layout allocation device, and a line processing device. First, the graph manager constructs subgraphs at various levels based on the nesting relationships of graph element nodes. Then, the hierarchy partitioning device independently executes a hierarchical automatic layout process for each subgraph, sequentially layering the nodes within the subgraph. Next, the layout allocation device sorts the nodes within the same layer and arranges the ports contained in the nodes, determining the position and size of the nodes and ports. The line processing device sorts the connections between adjacent layers and determines the coordinates of the connections. Finally, the graph manager collects the laid-out subgraphs and performs a subgraph merging operation.
[0096] 4.2 Constructing a subgraph structure based on the nesting relationship of nodes
[0097] The graph manager retrieves all node, line, and port information from the internal module graph and abstracts the graph structure. Considering the nesting relationships of node elements, each node is scanned to obtain all its internal node, line, and port information. The retrieved nested information is then abstracted into a nested graph of the current node, serving as a subgraph structure of the original graph. This process is repeated recursively until all nested node information is obtained.
[0098] The graph manager constructs a virtual connection flowchart for nested graphs, as shown below. Figure 3 As shown, for connections between different nested graphs, the graph manager selects the nested graph of the nearest common ancestor node of the nested graph to which the nodes at both ends of the connection belong, changes the two ends of the connection to the ancestor nodes of the original two ends in the ancestor nested graph, and marks the connection as a virtual connection.
[0099] like Figure 4 In the nested internal module diagram shown, the connection between node #2 and node #4 is a link. According to the nesting diagram's structure, #2 and #3 belong to the nested graph of node #1, and #4 belongs to the nested graph of node #3. When processing the connection, since nodes #2 and #4 do not belong to the same nested graph, the nearest common ancestor of nodes #2 and #4, node #1, is selected. The ancestor of node #2 in node #1 is node #3, and the ancestor of node #4 in node #1 is node #4. Therefore, the connection is changed so that node #4 points to node #3.
[0100] 4.3 Constructing the basic hierarchical structure of subgraphs
[0101] For each nested graph, the hierarchical partitioning device sequentially performs the following steps to divide the nodes within the nested graph into layers:
[0102] 1) Break the cycle: Find all nodes in the graph with an in-degree of 0 and treat them as the first-level nodes in the hierarchical layout. Starting from the first-level nodes, use depth-first traversal to find the key edges that form a cycle, reverse them and record them, so that there are no cycles in the graph.
[0103] 2) Determine the hierarchy: Starting from the first-level node, sequentially assign hierarchy to the nodes connected to it. The node pointed to by an edge from the first-level node becomes the second-level node. Continue this process in a loop, assigning hierarchy to all nodes. If a node has been assigned hierarchy multiple times, select the highest hierarchy.
[0104] 3) Supplementing Virtual Nodes: The flowchart for establishing virtual nodes for cross-layer connections in the hierarchical partitioning device is as follows. Figure 5 As shown, for cross-level node connections, where the level difference between two adjacent nodes is greater than 1, virtual nodes need to be established between their intermediate levels. The number of virtual nodes is equal to the level difference between the two adjacent nodes minus 1, and these virtual nodes are connected sequentially, ultimately ensuring that each node is only connected to its adjacent nodes. For example... Figure 6 As shown, node #1 is in the first layer and node #4 is in the fourth layer. Therefore, the layer difference between #1 and #4 is 3, which is greater than 1. A virtual node #5 needs to be created in the second layer, which is between the two points, and a virtual node #6 needs to be created in the third layer.
[0105] 4) Calculate the size of each level: Calculate the position and size of each level. Level width = width of the widest node in the current level, level height = sum of heights of nodes within the level + sum of spacing between nodes in the same level. The starting horizontal coordinate of each level node = starting position of the previous level + width of the previous level + level interval width, and the starting vertical coordinate of the level node = (height of the highest level - height of the current level) / 2.
[0106] 4.4 Location and Size of Processing Nodes and Ports
[0107] The layout allocation device sequentially performs the following steps to process the position and size of nodes and ports:
[0108] 1) Port direction: For each port contained in a node, calculate the out-degree and in-degree of the port. If the out-degree is greater than the in-degree, the port is placed on the right side of the node; otherwise, the port is placed on the left side of the node. When there are nested ports, the direction of the nested ports is recursively determined.
[0109] 2) Node and Port Size: Ports and connections are placed according to specified spacing. The required height for each node / port to accommodate both ports and cables needs to be calculated. Based on the number of ports and cables on the same side of the node / port, the height of one side of the node / port = sum of the heights of all contained ports + port spacing * number of contained ports + cable spacing * number of cables. The maximum value on both sides of the node / port represents the required height of the node / port.
[0110] 3) Sorting Nodes within the Same Layer: Nodes within each layer are sorted to reduce the number of intersections between connections. The process involves sorting nodes in every two adjacent layers to find the arrangement with the fewest line intersections. When the number of nodes within a layer is small, all permutations are used to find the sequence with the fewest line intersections. When the number of nodes within a layer is large, a certain number of randomized node sorting sequences within the layer are obtained by specifying the number of iterations, and the sequence with the fewest intersections is compared.
[0111] 4) Port Sorting: The ports on one side of each node are sorted to reduce the number of intersections between port connections. The goal is to find the arrangement with the fewest line intersections. When the number of ports is small, all permutations are used to find the sequence with the fewest line intersections. When the number of ports is large, a specified number of iterations is used to obtain a certain number of random port sorting sequences, and the sequence with the fewest intersections is compared.
[0112] 5) Assign coordinates: Assign coordinates to nodes and ports in sequence according to the sorting results of nodes and ports.
[0113] 4.5 Calculate the minimum intersection of lines connecting different levels.
[0114] The line processing device sequentially performs the following steps to obtain the minimum intersection of the lines and assign coordinates to the lines:
[0115] 1) Preprocessing of connection sorting: Sort the lines on one side of each node / port to reduce the intersection of lines with the same starting point or the same ending point. When the starting points of lines are the same, sort them according to the ordinate order of their connected ending points; when the ending points of lines are the same, sort them according to the ordinate order of their connected starting points.
[0116] 2) Virtual Node Connection Preprocessing: The sorting rules for virtual node connections are based on the original start and end points of the connections, performing the connection sorting preprocessing steps described above. For example... Figure 7 As shown, virtual node #5 has two connections, #6 and #7. The original starting point and original ending point of #6 are #1 and #3, respectively, and the original starting point and original ending point of #7 are #1 and #4, respectively. Therefore, referring to the rule of the same starting point in the connection sorting preprocessing, #6 and the original ending point #3 are sorted earlier than #7 and the original ending point #4. Thus, #6 is sorted earlier than #7, making #6 earlier than #7 in the sorting of #1 outgoing edge, #5 incoming edge, and #5 outgoing edge.
[0117] 3) Assigning inflection points on coordinate lines: A line needs to make two turns from its starting point to reach its endpoint. All connections between any two adjacent layers are processed uniformly, and the inflection points are assigned to the lines based on the connection order. The flowchart of the line processing device is shown below. Figure 7 As shown, each connection is compared sequentially with the preceding connection to set the inflection point sequence for that connection. The inflection point results must meet the following rules:
[0118] If the starting point of the current connection is greater than the starting point of the previous connection and the ending point of the current connection is greater than the ending point of the previous connection, then the inflection point of the current connection is greater than the inflection point of the previous connection; otherwise, the inflection point of the current connection is less than the inflection point of the previous connection.
[0119] If the starting point of the current connection is greater than the starting point of the previous connection and the ending point of the current connection is less than the ending point of the previous connection: the order of the starting and ending points of the two connections is inconsistent, the intersection between the connections is unavoidable, and the inflection point of the current connection has no relation to the size of the previous connection.
[0120] If the starting point of the current connection is less than the starting point of the previous connection and the ending point of the current connection is greater than the ending point of the previous connection: the starting and ending points of the two connections are not in the same order, and intersection between the connections is unavoidable. The inflection point of the current connection is not related to the size of the previous connection. If the starting point of the current connection is greater than the ending point of the previous connection, then the inflection point of the current connection is less than the inflection point of the previous connection; otherwise, the inflection point of the current connection is greater than the inflection point of the previous connection.
[0121] Examples of line processing devices, such as Figure 9 As shown:
[0122] #1 No preceding connection, no comparison sequence;
[0123] #2 does not intersect with its preceding sequence #1, therefore there is no comparison sequence.
[0124] #3 does not intersect with the preceding line #1, and must be less than the inflection point of the preceding line #2 to avoid intersecting with #2, i.e. #3 < #2;
[0125] #4 does not intersect with its preceding lines #1 and #2, but intersects with its preceding line #3 unavoidably; therefore, there is no comparison sequence.
[0126] #5 does not intersect with the preceding lines #1 and #2. Intersection with the preceding line #3 is unavoidable. It must be greater than the inflection point of the preceding line #4 to avoid intersection with #4, i.e. #5>#4.
[0127] #6 does not intersect with the preceding lines #1, #2, #4, and #5, and must be less than the inflection point of the preceding line #3 to avoid intersecting with #4, i.e., #6 < #3;
[0128] In summary, the inflection point order is #6<#3<#2、#5>#4, and the inflection points are allocated according to this order.
[0129] 4) Line Repair: Repairs edges that were broken due to the creation of virtual nodes, connecting all line segments together. When connecting, if the ordinate of a line is less than a certain difference, the ordinate of one line segment is changed so that the connection point between the two line segments is a straight line, reducing the number of inflection points at the connection. Edges that were flipped when the loop was broken are flipped back.
[0130] 4.6 Merging Subgraphs
[0131] Due to the nested subgraph processing in the graph manager, subgraphs need to be merged after automatic subgraph layout. Subgraph merging only requires restoring the virtual connections established by "building the subgraph structure according to the nesting relationship of nodes," pointing both ends of the lines back to their original nodes. For example... Figure 3 The connection was changed to point from node #2 to node #3 when constructing the subgraph. Now it needs to be restored to point from node #2 to node #4. During the restoration process, the original inflection point position of the connection remains unchanged, and the graph manager changes its start and end coordinates to the left of the midpoint on the same side of the original start and end nodes.
[0132] A complete example of hierarchical automatic layout for internal module diagrams is as follows: Figure 10 As shown:
[0133] 1. Construct a subgraph structure based on the nesting relationship of nodes.
[0134] Part5 and Part6 are nested graphs of Part4, therefore Part5, Part6, and Part5 together form a single graph.
[0135] Part1, part2, part3, and part4 belong to the top-level graph and are also within the same nested graph. Since part2 connects to part5, and the two points are not within the same nested graph, and since part2 and part4 are within the same nested graph, e2 is changed to connect part2 to part4. Therefore, Part1, part2, part3, part4, e1, e2, e3, and e4 form a single graph.
[0136] 2. Construct the basic hierarchical structure of the subgraph
[0137] 2.1 Breaking the loop: There is a loop relationship between part1-part2-part3-part1. By flipping e3, a loop-free relationship between part1-part2-part3 and part1-part3 is formed.
[0138] 2.2 Determine the hierarchy
[0139] part1 has an in-degree of 0, so it is determined to be a first-level node. It connects part2 and part3, and part2 and part3 are at least second-level nodes. part2 connects part3 and part4, so the level of part3 and part4 is greater than that of part2. In summary, part1 is the first level, part2 is the second level, and part3 and part4 are the third level.
[0140] 2.3 Supplementing Virtual Nodes
[0141] e3 is connected to the third-level node part3 by the first-level node part1. A virtual node needs to be created in the second level to form part1-virtual node-part3.
[0142] 3. Process the location and size of nodes and ports.
[0143] 3.1 Port Direction
[0144] Taking port p1 as an example: p1 is only connected to e1, which is its outgoing line, so the direction of p1 is to the right.
[0145] 3.2 Node and Port Size
[0146] Taking port p3 as an example: P3 needs to accommodate p1, so its height needs to be increased. Part1 needs to accommodate p3, so its height needs to be increased.
[0147] 3.3 Sorting of nodes at the same level
[0148] Taking Part3 and Part4 as examples: Both Part3 and Part4 are third-level nodes. Since the node connected to the left of Part4 is Part2, and the node connected to the left of Part3 is Part2 and a virtual node, the average ordinate of the left-side node connected to each point is calculated. Part4 is less than Part3, so the ordinate of Part4 needs to be less than Part3.
[0149] 3.4 Port sorting
[0150] Taking ports p2 and p3 as an example: the node connected to p3 is part2, and the node connected to p2 is a virtual node. The ordinate of the virtual node is greater than that of part2, so the ordinate of p2 needs to be greater than that of p3.
[0151] Calculate the minimum intersection of connections between levels.
[0152] Taking the connection between lines e3 and e4 as an example: the ordinates of the starting and ending points of e3 are both greater than the ordinates of the starting and ending points of e4, and the ordinate of the starting point is less than the ordinate of the ending point. Therefore, the inflection point of e3 is less than the inflection point of e4.
[0153] Merging subgraphs
[0154] Restore the reverse edge e3 and cancel the virtual node created by e3.
[0155] Change e2 back to part2 pointing to part5, while keeping the starting point and inflection point position of e3.
[0156] In summary, the hierarchical automatic layout method and apparatus for internal module diagrams provided by this invention have at least the following advantages compared to the prior art:
[0157] (1) The method proposed in this invention breaks through the limitation that the traditional hierarchical automatic layout method is only applicable to simple graph elements. During the layout process, the ports and graph element nesting involved in the internal module graph are taken into account, realizing a hierarchical automatic layout method that fully covers the internal module graph elements.
[0158] (2) By sorting nodes in the same layer, sorting ports on the same side of the same node, and sorting inflection points of connections between adjacent layers in a multi-round sorting method, the number of intersections between connections is effectively reduced when connecting ports, thus improving the readability of the layout diagram.
[0159] (3) In the case of nested nodes, the present invention uses the method of creating subgraphs. For the connection of different nested subgraphs, the method of establishing virtual connection in the subgraph of the nearest common ancestor node is used, which effectively solves the layout problem of cross-graph connection.
[0160] For ease of description, spatial relative terms such as "above," "on top of," "on the upper surface of," "above," etc., are used herein to describe the spatial positional relationship of a device or feature as shown in the figures to other devices or features. It should be understood that spatial relative terms are intended to encompass different orientations in use or operation beyond the orientation of the device as described in the figures. For example, if the device in the figures were inverted, a device described as "above" or "on top of" other devices or structures would subsequently be positioned as "below" or "under" other devices or structures. Thus, the exemplary term "above" can include both "above" and "below." The device may also be positioned in other different ways (rotated 90 degrees or in other orientations), and the spatial relative descriptions used herein will be interpreted accordingly.
[0161] Furthermore, it should be noted that the use of terms such as "first" and "second" to define components is merely for the purpose of distinguishing the corresponding components. Unless otherwise stated, the above terms have no special meaning and therefore should not be construed as limiting the scope of protection of this invention.
[0162] The above are merely preferred embodiments of the present invention and are not intended to limit the present invention. Various modifications and variations can be made to the present invention by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.
Claims
1. A hierarchical automatic layout method for internal module diagrams, characterized in that, Includes the following steps: Step 1: Obtain all node information, line information, and port information of the outer layer in the internal module diagram, and use lines to connect the nodes and ports according to the basic hierarchical structure to form the initial shape of the model diagram layout; Step 2: Scan each node to obtain all node information, line information, and port information within it. If nesting relationships exist, use the nesting information as the subgraph of the current node. Step 3: Scan each node of the nested information to obtain all node information, line information, and port information within it. If a nesting relationship exists, treat the nested information as a subgraph of the current node and connect the nodes and ports using lines according to the basic hierarchical structure to form the initial shape of the nested graph layout. Step four, repeat step three until all nested relationships are obtained and arranged; Step 5: Determine the virtual connections between different nested node relationships, and connect the virtual connections to the outermost node; Step 6: Based on the information obtained in the above steps, modify the initial shape of the model layout to obtain the final shape of the model layout, specifically including: S6.1, Determine the location and size of nodes and ports: The method for determining the location and size of nodes and ports includes the following steps: S6.1.1 Determine the direction of the port: For each port contained in a node, calculate the out-degree and in-degree of the port. If the out-degree is greater than the in-degree, the port is placed on the right side of the node; otherwise, the port is placed on the left side of the node. If there is a nested port situation, the out-degree and in-degree of the nested port are determined. If the out-degree is greater than the in-degree, the port is placed to the right of the nested port; otherwise, the port is placed to the left of the nested port. S6.1.2 Determine the height of nodes and ports: Based on the number of ports and lines on the same side of a node / port, the height of one side of a node / port = the sum of the heights of the ports it contains + the port spacing * the number of ports it contains + the line spacing * the number of lines. The maximum height of the left and right sides of a node / port is the height of the node / port. S6.2, determine the order of nodes at the same level; S6.3, Determine the port order; S6.4 Assign coordinates to nodes and ports according to the sorting results of nodes and ports; S6.5, determine the rules for connecting lines, calculate the minimum intersection of lines between levels, and connect lines according to the minimum intersection; restore lines reversed according to the basic hierarchical structure method to their original state.
2. The hierarchical automatic layout method for internal module diagrams according to claim 1, characterized in that, The method for the basic hierarchical structure includes the following steps: S1.1 Traverse all nodes. If a cycle exists, find the key line that constitutes the cycle, reverse its in and out directions, and record the line. Find the node with an in-degree of 0 and use it as the first-level node of the hierarchical layout. S1.2 Starting from the first-level node, the nodes connected to it are sequentially layered. The node that the first-level node points to through a line is the second-level node, and so on. All nodes are assigned a level. If a node has been assigned a level multiple times, the level with the largest sequence number is selected as the level of this node. S1.3 For cross-level connected node relationships, that is, when the level difference between two adjacent nodes is greater than 1, virtual nodes need to be established between their intermediate levels. The number of virtual nodes is the level difference between two adjacent nodes minus 1, and the virtual nodes are connected sequentially, so that each node is only connected to its adjacent nodes. S1.4 Calculate the position and size of each level: Level width = width of the widest node in the current level, Level height = sum of heights of nodes within the level + sum of spacing between nodes in the same level, Starting horizontal coordinate of each node = Starting position of the previous level + width of the previous level + width of the level interval, Starting vertical coordinate of each node = (height of the highest level - height of the current level) / 2.
3. The hierarchical automatic layout method for internal module diagrams according to claim 2, characterized in that, The method for determining the sorting of nodes in the same layer is as follows: sort every two adjacent layers of nodes in turn, and find the arrangement with the smallest number of line intersections: when the number of nodes in the layer is small, use full permutations to find all arrangements and find the sequence with the fewest line intersections; when the number of nodes in the layer is large, obtain a certain number of random sorting sequences of nodes in the layer by specifying the number of iterations, and compare them to find the sequence with the smallest number of intersections.
4. The hierarchical automatic layout method for internal module diagrams according to claim 3, characterized in that, The method for determining the port sorting is as follows: sort the ports on one side of each node and find the arrangement with the minimum number of line intersections: when the number of ports is small, use full permutations to find all arrangements and find the sequence with the fewest line intersections; when the number of ports is large, specify the number of iterations, obtain a certain number of random port sorting sequences, and compare to find the sequence with the smallest number of intersections.
5. A hierarchical automatic layout method for internal module diagrams according to claim 4, characterized in that, The rules for the connection are as follows: S6.5.1 Sort the lines on one side of each node / port: when the starting points of the lines are the same, sort them according to the order of the ordinates of the endpoints they are connected to; when the endpoints of the lines are the same, sort them according to the order of the ordinates of the starting points they are connected to. The sorting rule for virtual node connections is based on the original starting point and original ending point of the connection, and the above steps are performed to sort the connections. S6.5.2 Assigning Inflection Points of Coordinate Lines: A line needs to make two turns from its starting point to reach its endpoint. All connections between any two adjacent layers are processed uniformly. The inflection point assignments are sorted according to the connection order. Each connection is compared sequentially with its preceding connections to set its inflection point sequence. The inflection point results must conform to the following rules: If the coordinates of the starting point of the current connection are greater than the coordinates of the starting point of the previous connection and the coordinates of the ending point of the current connection are greater than the coordinates of the ending point of the previous connection, then the coordinates of the inflection point of the current connection are greater than the coordinates of the inflection point of the previous connection; otherwise, the coordinates of the inflection point of the current connection are less than the coordinates of the inflection point of the previous connection. If the coordinates of the starting point of the current connection are greater than the coordinates of the starting point of the previous connection and the coordinates of the ending point of the current connection are less than the coordinates of the ending point of the previous connection: the order of the starting point and ending point coordinates of the two connections is inconsistent, the intersection between the connections is unavoidable, and the coordinates of the inflection point of the current connection are not related to the coordinates of the inflection point of the previous connection. The coordinates of the starting point of the current connection are less than the coordinates of the starting point of the previous connection and the coordinates of the ending point of the current connection are greater than the coordinates of the ending point of the previous connection. The order of the starting point and ending point coordinates of the two connections is inconsistent, and the intersection between the connections is unavoidable. The coordinates of the inflection point of the current connection are not related to the coordinates of the inflection point of the previous connection. The coordinates of the starting point of the current connection are less than the coordinates of the starting point of the previous connection and the coordinates of the ending point of the current connection are less than the coordinates of the ending point of the previous connection. If the coordinates of the starting point of the current connection are greater than the coordinates of the ending point, then the coordinates of the inflection point of the current connection are less than the coordinates of the inflection point of the previous connection; otherwise, the coordinates of the inflection point of the current connection are greater than the coordinates of the inflection point of the previous connection. S6.5.3 connects the edges that were separated by creating virtual nodes, so that all line segments are connected together. When the ordinate of a line is less than a certain difference, the ordinate of a line segment is changed so that the connection point of the two line segments is a straight line, reducing the number of inflection points when connecting.
6. A hierarchical automatic layout method for internal module diagrams according to claim 5, characterized in that, The method also includes restoring the virtual connection to the node it originally pointed to.
7. A hierarchical automatic layout apparatus for implementing the hierarchical automatic layout method for internal module diagrams as described in any one of claims 1-6, characterized in that, The system includes a graph manager, a hierarchy partitioning device, a layout allocation device, and a line processing device. The graph manager constructs subgraphs at various levels based on the nesting relationship of nodes in the internal module graph and obtains all node information, line information, and port information, which is then sent to the hierarchy partitioning device. The hierarchy partitioning device divides the outer layer nodes and subgraph nodes at each level into layers and sends the results to the layout allocation device. The layout allocation device determines the position and size of nodes and ports, sorts nodes within the same level, arranges ports, and sends the results to the line processing device. The line processing device connects the obtained nodes and ports, and when there are connections in different subgraphs, it uses virtual connections to connect the top-level model graph of the subgraph. It then arranges the connections and virtual connections to obtain the arrangement with the fewest intersections.
8. The hierarchical automatic layout device according to claim 7, characterized in that, The graph manager restores the virtual connections to their original positions.
Citation Information
Patent Citations
An automatic layout algorithm of a series-parallel nested subtask flow chart
CN109582299A
Automatic layout method, device and equipment for network topological graph
CN110213107A