A method, device and electronic device for finding the optimal root node of an undirected tree graph
By collapsing nodes from the edges and expanding the center point in the undirected tree diagram, combined with network type and hierarchical filtering rules, the problem of difficult root node selection in undirected tree topology is solved, and a more accurate and reasonable automatic search for root nodes is achieved.
Patent Information
- Application Number
- CN202211096348.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-09-08
- Publication Date
- 2024-09-13
- Estimated Expiration
- 2042-09-08
AI Technical Summary
The existing technology has few algorithms for finding root nodes in undirected tree topology. Common methods such as selecting the node with the largest degree or disconnecting leaf nodes in sequence make it difficult to find a reasonable root node, resulting in large layout deviations.
Starting from the edge of the undirected tree diagram, nodes are folded according to the preset folding rules until at most two center points are left, and then expanded from the center points according to the preset expansion rules, and the optimal one is determined based on filtering rules such as network type, node type and level. root node.
The automatic search scheme for root nodes is optimized to ensure that the determined root node is more reasonable, and a reasonable root node is automatically found accurately, improving the layout effect of the network topology.
Smart Images

Figure CN115665039B
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of topological graphs, and in particular to a method, a device and an electronic device for finding an optimal root node of an undirected tree graph. Background Art
[0002] Tree topology is one of the common topological structures in network topology. In the process of visualizing tree topology, it is usually necessary to select a node as the root node of the tree. The root node selection of the tree diagram is generally divided into two types: manual assignment and automatic assignment. The former is based on people's understanding of the network and makes selections based on actual conditions. The latter is when people do not understand the network topology, an algorithm automatically assigns a node based on the known network topology.
[0003] When people do not understand the network topology, the network topology needs to be automatically laid out during visualization to help people intuitively understand the structure of the network topology. The layout result directly affects people's first impression of the network topology, and the choice of the root node will affect the effect of the automatic layout. Therefore, it is very important to find the root node automatically as accurately as possible.
[0004] However, the inventors of the present application discovered in the process of implementing the invention that for directed tree topology, the root node can be determined by topological sorting. However, for undirected tree topology, there are relatively few algorithms for finding the root node. In the related art, a more common method is to select the node with the largest degree as the root node. This method is simple, but it is often impossible to find a more reasonable root node. Figure 1 An example of a solution to find the root node is shown below: Figure 1 As shown, the most reasonable root node in the actual network topology is the node in box 1, but the node with the largest degree will be box node 2, which is a large deviation.
[0005] Figure 2 This example shows another solution for finding the root node, which is to disconnect the leaf nodes one by one and use the remaining one or two nodes as the root node. This method also has disadvantages. Figure 2 As shown, when there are asymmetric links, the selected root node will tend to be the longer link, such as the two nodes in box 3. This offset sometimes makes the tree layout more balanced, but for the actual network topology, the more reasonable root node should still be the node in box 4. Summary of the invention
[0006] In view of this, an embodiment of the present invention provides a method, an apparatus and an electronic device for finding an optimal root node of an undirected tree graph, so as to facilitate accurate and automatic finding of a reasonable root node.
[0007] In order to achieve the above-mentioned invention object, the following technical scheme is adopted:
[0008] In a first aspect, an embodiment of the present invention provides a method for finding an optimal root node of an undirected tree graph, the method comprising the steps of:
[0009] Get all nodes of the undirected tree graph;
[0010] Starting from the edge of the undirected tree graph, folding the nodes according to a preset folding rule until at most two center points remain;
[0011] Expand the nodes outward from the center point according to a preset expansion rule;
[0012] According to the preset root node screening rules, the node that is closest to the central node and meets the preset root node screening rules is determined as the optimal root node in the network represented by the undirected tree; the preset root node screening rules include: network type, node type of the root node in the corresponding type of network and the level of the network where the root node is located.
[0013] Optionally, the node includes: a leaf node and a bridge node, the node carries node attributes, the node attributes include: a link attribute and a children attribute, and the bridge node is an isolated node adjacent to at least two clusters;
[0014] Starting from the edge of the undirected tree graph, the nodes are folded according to a preset folding rule until at most two center points remain, including:
[0015] According to the node attributes of the node, traverse and obtain a set of leaf nodes with a first link attribute and a set of bridge nodes with a second link attribute in the undirected tree graph; the first link attribute is having a unique adjacent point, and the second link attribute is having two adjacent points;
[0016] Traversing the leaf nodes in the leaf node set, for a first leaf node, if it is detected that the only adjacent point of the first leaf node is not a bridge node or a leaf node, determining the adjacent point as a parent node of the first leaf node;
[0017] Add the first leaf node to the children attribute of the parent node, delete the first leaf node from the link attribute of the parent node, and delete it from the topology map data;
[0018] The leaf node set and the bridge node set are updated.
[0019] Optionally, starting from the edge of the undirected tree graph, folding the nodes according to a preset folding rule until at most two center points remain further comprises:
[0020] Traversing the bridge nodes in the bridge node set, for a first bridge node, searching for adjacent points from the first bridge node to both sides, and detecting whether the adjacent points are endpoints, until the adjacent points are found to be endpoints;
[0021] Arrange the edges and nodes between the endpoints obtained on both sides into a link set in the order of connection;
[0022] The bridge nodes in the link set are deleted from the bridge node set.
[0023] Optionally, after deleting the bridge node in the link set from the bridge node set, the method further comprises: for each edge in the link set, detecting whether there is a non-empty link in the links attribute of each edge;
[0024] If so, the link of this edge is released and a new link set is formed.
[0025] Optionally, after forming the new link set, the method further comprises: creating a new edge between two endpoints;
[0026] The edges and corresponding adjacent points of the original node link set between the two endpoints are deleted from the links attributes of the two endpoints, and the two endpoints are added to the links attributes of the new link set, and the corresponding newly created edges are created;
[0027] If one of the two endpoints is a leaf node and the other is not a leaf node, then add the leaf node to the children attribute of the other non-leaf node;
[0028] Delete the leaf node from the link attribute of another non-leaf node, and delete the leaf node from the topology map data;
[0029] The above steps are iterated until the number of nodes in the topology data is less than or equal to 2, and the remaining one or two nodes are used as center points.
[0030] Optionally, the step of determining, according to a preset root node screening rule, a node that is closest to the central node and meets the preset root node screening rule as the optimal root node in the network represented by the undirected tree comprises: traversing all nodes to find a set of candidate nodes that meet the preset root node screening rule;
[0031] If the set of candidate nodes is empty, one or two center points are returned as the optimal root nodes according to the set number of root nodes.
[0032] Optionally, the method further comprises: if the set of nodes to be selected is not empty, starting from the central node, sequentially expanding the nodes to find the optimal root node;
[0033] Searching the set of candidate nodes for all target nodes that meet preset screening rules;
[0034] Sort the target nodes in ascending order according to the shortest path length to the central node;
[0035] According to the number of set root nodes, the first n target nodes are selected as the optimal root nodes to be returned; n is the smaller value between the number of nodes that meet the preset screening rules and the number of set root nodes.
[0036] Optionally, after searching all target nodes in the nodes that meet the preset screening rules from the set of candidate nodes, the method further comprises: if no target node that meets the preset screening rules is found in the nodes, expanding the topology map data once;
[0037] Traverse all current nodes. For each node i, if the children attribute of the node i is not empty, add all nodes k in the children to the current node of the topology data, and find the connection edge with the node i according to the link attribute of the node k, and add the node k to the link attribute of the node i. Each node k corresponds to the connection edge of the node i.
[0038] Count all the edges in the current topology data. For each edge l, if the links attribute of the edge l is not empty, release the link of the edge l.
[0039] According to the link set of the links attribute of the link edge l, all nodes in the link set are added to the current node, and according to the first and last edges of the link set, the two endpoints and their respective adjacent nodes are added to each other's link attributes to reconnect them;
[0040] Repeat the above steps until all target nodes that meet the preset screening rules are found in the set of candidate nodes;
[0041] Sort the target nodes in ascending order according to the shortest path length to the central node;
[0042] According to the number of set root nodes, the first n target nodes are selected as the optimal root nodes to be returned; n is the smaller value between the number of nodes that meet the preset screening rules and the number of set root nodes.
[0043] Optionally, the method further includes: presetting the number of root nodes, and configuring preset screening rules for the root nodes.
[0044] In a second aspect, the present invention also provides an apparatus for finding an optimal root node of an undirected tree graph, comprising: a node acquisition program module, used to acquire all nodes of the undirected tree graph; a folding program module, used to fold the nodes starting from the edge of the undirected tree graph according to a preset folding rule until at most two center points remain; an expansion program module, used to expand the nodes outward from the center point according to a preset expansion rule;
[0045] A determination program module is used to determine, according to a preset root node screening rule, a node that is closest to the central node and meets the preset root node screening rule as the optimal root node in the network represented by the undirected tree; the preset root node screening rule includes: network type, node type of the root node in the corresponding type of network, and the level of the network where the root node is located.
[0046] In a third aspect, an embodiment of the present invention provides an electronic device, comprising: one or more processors; a memory; one or more executable programs are stored in the memory, and the one or more processors read the executable program code stored in the memory and run the program corresponding to the executable program code to execute the method for finding the optimal root node of an undirected tree graph as described in any one of the first aspects.
[0047] The method, device and electronic device for finding the optimal root node of an undirected tree graph provided by the embodiment of the present invention start from the edge of the undirected tree graph, fold the nodes according to the preset folding rules, so that only two center points or one center point are left, and then expand outward from the center point according to the preset expansion rules, and then find the optimal root node according to the preset root node screening rules. In this way, the automatic root node search scheme is optimized, so that the determined root node is more reasonable, thereby facilitating the accurate automatic search of reasonable root nodes. BRIEF DESCRIPTION OF THE DRAWINGS
[0048] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0049] Figure 1 A schematic diagram of a solution for finding a root node in the related art is illustrated;
[0050] Figure 2 Another schematic diagram of a solution for finding a root node in the related art is illustrated;
[0051] Figure 3 A schematic diagram of a method flow chart for finding an optimal root node of an undirected tree graph according to an embodiment of the present invention;
[0052] Figure 4 A schematic flow chart of a method for finding an optimal root node of an undirected tree graph according to another embodiment of the present invention;
[0053] Figure 5 A schematic flow chart of a method for finding an optimal root node of an undirected tree graph according to another embodiment of the present invention;
[0054] Figure 6 A schematic block diagram of the architecture of a device for finding an optimal root node of an undirected tree graph according to an embodiment of the present invention;
[0055] Figure 7 The present invention is a schematic block diagram of an electronic device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0056] The embodiments of the present invention are described in detail below with reference to the accompanying drawings.
[0057] It should be clear that the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0058] The method for finding the optimal root node of an undirected tree graph provided by an embodiment of the present invention can be applied to network topology drawing and graph layout scenarios, so as to facilitate accurate and automatic finding of a reasonable root node in an undirected tree graph.
[0059] It should be noted that the method can be solidified in a certain manufactured physical product in the form of software, and when the user uses the product, the method flow of the present application can be reproduced.
[0060] Figure 3 A schematic diagram of a method for finding the optimal root node of an undirected tree graph according to an embodiment of the present invention; Figure 3 As shown, the method for finding the optimal root node of an undirected tree graph provided by an embodiment of the present invention comprises the steps of:
[0061] S110. Obtain all nodes of the undirected tree graph.
[0062] In this embodiment, all nodes (nodes are also called nodes) of the undirected tree graph can be obtained by traversal; in some embodiments, the topological information of the undirected tree graph is known, and the topological graph data includes a set of nodes, wherein each node is an object and needs to carry node attribute information, and the node attribute information includes at least the following fields: id: the unique identifier of the node; link: the set of all adjacent edges and adjacent points of the node, each adjacent point corresponds to an adjacent edge; children: the set of collapsed child nodes under the node; folded: whether the node is folded, false if not folded, and the default value of not folded is the initial value.
[0063] Each edge in the network topology diagram is an object and also carries edge attributes, which must contain at least the following fields: node1: one endpoint of the edge; node2: the other endpoint of the edge; links: the links contained in the edge.
[0064] In order to realize a solution of automatically finding a reasonable root node in an undirected tree graph, in some embodiments, the method further includes: presetting the number of root nodes and configuring preset screening rules for the root nodes.
[0065] Among them, rootNum: represents the number of root nodes, which can be set to, 1, less than or equal to N root nodes, 2, unlimited.
[0066] Rule: represents the filtering rule of the root node, that is, a method for judging a single attribute of a node or combining multiple attributes of a node based on the attribute values of the node. The filtering rule can be customized according to the characteristics and experience of different network types or business scenarios. For example, in a network topology scenario, the node type filtering rule of the root node is set to must be a router and the level is greater than 3, etc.
[0067] S120 , starting from the edge of the undirected tree graph, fold the nodes according to a preset folding rule until at most two center points remain.
[0068] Among them, in an undirected tree graph, a node at the edge of the graph without child nodes is a leaf node, also called a terminal node, which is a node with a degree (number of connections) of 1. There are also definitions based on its initial degree of 0, which are essentially the same.
[0069] The parent node of a leaf node is the only node connected to the leaf node. In a relative sense, a leaf node can also be considered as a child node of its parent node.
[0070] The folding rule can be to fold upward one by one starting from the leaf nodes, or to fold all nodes with a certain node attribute at the same time.
[0071] In some embodiments, the node includes: a leaf node and a bridge node, the node carries node attributes, the node attributes include: a link attribute and a children attribute, and the bridge node is an isolated node adjacent to at least two clusters;
[0072] The step of folding the nodes starting from the edge of the undirected tree graph according to a preset folding rule until at most two center points remain (step S120) includes:
[0073] According to the node attributes of the node, a leaf node set with a first link attribute and a bridge node set with a second link attribute in the undirected tree graph are traversed to obtain; wherein the first link attribute has a unique adjacent point, and the second link attribute has two adjacent points.
[0074] In this embodiment, in the current undirected tree graph, all leaf nodes with only one adjacent point in the attribute link and bridge nodes with only two adjacent points are found and marked as the current leaf node set and the current bridge node set.
[0075] Traverse the leaf nodes in the leaf node set. For the first leaf node, if it is detected that the only adjacent point of the first leaf node is not a bridge node or a leaf node, determine the adjacent point as the parent node of the first leaf node; add the first leaf node to the children attribute of the parent node, delete the first leaf node from the link attribute of the parent node, and delete it from the topology map data; update the leaf node set and the bridge node set.
[0076] In this embodiment, the current leaf nodes are traversed, and for each leaf node, if the only adjacent point of the leaf node is not a bridge node or a leaf node, it is determined to be the parent node of the leaf node. The leaf node is added to the children attribute of its parent node, and the leaf node is deleted from the link attribute of its parent node. Finally, the leaf node is deleted from the topology map data, and the current leaf node set and bridge node set are updated.
[0077] Furthermore, step S120 also includes: traversing the bridge nodes in the bridge node set, for the first bridge node, searching for adjacent points from the first bridge node to both sides, and detecting whether the adjacent points are endpoints, until the adjacent points are found to be endpoints; arranging the edges and nodes between the endpoints obtained on both sides into a link set according to the connection order; and deleting the bridge nodes in the link set from the bridge node set.
[0078] In this embodiment, by traversing the current bridge node, for each bridge node, by searching for adjacent points on both sides and detecting whether it is a bridge node or an endpoint, if the adjacent point is not a bridge node, it is an endpoint, otherwise continue to search for the adjacent point of the adjacent point until an endpoint is encountered. The edges and nodes between the two endpoints are arranged into a link set in the order of connection. All nodes in the link set (all current bridge nodes) are deleted from the bridge node set and no longer traversed, thereby saving traversal resources and improving the efficiency of automatic root node search.
[0079] As an optional embodiment, after deleting the bridge node in the link set from the bridge node set, the method further includes: for each edge in the link set, detecting whether there is a non-empty link in the links attribute of each edge; if so, releasing the link of the edge and forming a new link set.
[0080] In this embodiment, for each edge in the set, if there is a non-empty link in the links attribute of the edge, the link of the edge is released and a new link set is formed to achieve link contraction.
[0081] Furthermore, after forming a new link set, the method also includes: creating a new edge between two endpoints; deleting the edge and corresponding adjacent points of the original node link set between the two endpoints from the links attributes of the two endpoints, and adding the two endpoints to the links attributes of the new link set, and corresponding to the newly created edge; if one of the two endpoints is a leaf node and the other is not a leaf node, adding the leaf node to the children attribute of the other non-leaf node; deleting the leaf node from the link attribute of the other non-leaf node, and deleting the leaf node from the topology map data; iteratively executing the above steps until the number of nodes in the topology map data is less than or equal to 2, and taking the remaining one or two nodes as the center point.
[0082] In this embodiment, a new edge is created, node1 and node2 of the edge are set as the two endpoints, and links is the node link set between the two endpoints. The edges and corresponding adjacent points originally connected to the links of the two endpoints are deleted from the links attributes of the two endpoints, and the two endpoints are added to each other's links attributes and correspond to the newly created edge, so that the link can be contracted, which is convenient for improving the efficiency of subsequent root node search.
[0083] Furthermore, by adding the leaf nodes in the two endpoints to the children attribute of another non-leaf node, and then deleting the leaf nodes from the link attribute of another non-leaf node, and deleting the leaf nodes from the topology data, the links are further shrunk. If the number of nodes in the topology is greater than 2, repeat the above steps until the number of nodes in the topology is less than or equal to 2, and stop the iteration, and use the remaining one or two nodes as the center point.
[0084] S130, expanding the nodes outward from the center point according to a preset expansion rule;
[0085] S140. According to a preset root node screening rule, a node that is closest to the central node and meets the preset root node screening rule is determined as the optimal root node in the network represented by the undirected tree; the preset root node screening rule includes: network type, node type of the root node in the corresponding type of network, and the level of the network where the root node is located.
[0086] Please see Figure 4 As shown, in some embodiments, step S140 includes: S141a, traverse all nodes to find a set of candidate nodes that meet the preset screening rules of the root node. S143a, if the set of candidate nodes is empty, return one or two center points as the optimal root node according to the set number of root nodes.
[0087] In this embodiment, if the set of nodes to be selected is empty, indicating that there is no node that meets the conditions, one or two center points are returned as the optimal root nodes according to the preset number of root nodes.
[0088] For the case where the candidate node set is not empty, see Figure 5 As shown, in other embodiments, step S140 also includes: S141b, if the set of nodes to be selected is not empty, starting from the central node, expand the nodes in turn to find the optimal root node; S143b, search for all target nodes in the nodes that meet the preset screening rules from the set of nodes to be selected; S145b, sort the target nodes from small to large according to the shortest path length to the central node; S147b, according to the number of set root nodes, select the first n target nodes as the optimal root nodes to be returned; n is the smaller value between the number of nodes that meet the preset screening rules and the number of set root nodes.
[0089] In some other optional embodiments, after searching all target nodes in the nodes that meet the preset screening rules from the set of nodes to be selected (S143b), the method further includes: if no target node that meets the preset screening rules is found in the nodes, expanding the topology map data once;
[0090] Traverse all current nodes. For each node i, if the children attribute of the node i is not empty, add all nodes k in the children to the current node of the topology data, and find the connection edge with the node i according to the link attribute of the node k, and add the node k to the link attribute of the node i. Each node k corresponds to the connection edge of the node i.
[0091] Count all the edges in the current topology data. For each edge l, if the links attribute of the edge l is not empty, release the link of the edge l.
[0092] According to the link set of the links attribute of the link edge l, all nodes in the link set are added to the current node, and according to the first and last edges of the link set, the two endpoints and their respective adjacent nodes are added to each other's link attributes to reconnect them;
[0093] Repeat the above steps until all target nodes that meet the preset screening rules are found in the set of candidate nodes;
[0094] The target nodes are sorted from small to large according to the shortest path length to the central node; according to the number of set root nodes, the first n target nodes are selected as the optimal root nodes to be returned; n is the smaller value between the number of nodes that meet the preset screening rules and the number of set root nodes.
[0095] In this embodiment, by counting all the edges in the current topology graph, for each edge, if the links attribute of the edge is not empty, the link of the edge is released, that is: the two endpoints of the edge are obtained, and the two endpoints are deleted from each other's link attribute respectively, and according to the link set of the links attribute of the edge, all the nodes in the set are added to the current node, and according to the first and last edges of the link set, the two endpoints and their respective adjacent nodes are added to each other's link attributes, and reconnected until the target node that meets the preset filtering rules is found, and then a reasonable root node is found.
[0096] According to the above disclosure, the method for finding the optimal root node of an undirected tree graph provided by the embodiment of the present invention starts from the edge of the undirected tree graph, folds the nodes according to the preset folding rules, so that only two center points or one center point are left, and then expands outward from the center point according to the preset expansion rules, and then finds the optimal root node according to the preset root node screening rules. In this way, the automatic root node search scheme is optimized, making the determined root node more reasonable, thereby facilitating accurate and automatic search for reasonable root nodes.
[0097] Furthermore, the user can independently configure the preset screening rules, and the method for automatically finding the optimal root node of the undirected tree graph that can be independently configured is a method for automatically finding the optimal root node of the undirected tree graph that can be independently configured. Figure 1 and Figure 2 The illustrated method for finding the root node is optimized and can be configured accordingly according to different application scenarios and information, so that the root node found is more in line with the actual situation and more reasonable.
[0098] Embodiment 2
[0099] Figure 6 This is a schematic block diagram of the device architecture for finding the optimal root node of an undirected tree graph according to an embodiment of the present invention. Figure 6 As shown, based on the same technical concept as the aforementioned embodiments, the present invention also provides an embodiment of a device for finding the optimal root node of an undirected tree graph, including: a node acquisition program module 210, used to obtain all nodes of the undirected tree graph; a folding program module 220, used to fold the nodes starting from the edge of the undirected tree graph according to a preset folding rule until at most two center points remain; an expansion program module 230, used to expand the nodes outward from the center point according to a preset expansion rule; a determination program module 240, used to determine, according to a preset root node screening rule, the node closest to the center node and meeting the preset root node screening rule as the optimal root node in the network represented by the undirected tree; the preset root node screening rule includes: network type, node type of the root node in the corresponding type network, and the level of the network in which the root node is located.
[0100] The device of this embodiment can be used to perform Figure 1 The technical solution of the method embodiment shown has similar implementation principles and technical effects to those of the first embodiment, which will not be described in detail here and can be referenced by each other.
[0101] In addition, it is understandable that Figure 6 The device shown is also suitable for executing the step processes in other embodiments of Example 1. For the sake of brevity, please refer to the relevant description in Example 1, and the remaining embodiments will not be repeated here.
[0102] Embodiment 3
[0103] The present invention also provides an electronic device according to an embodiment, comprising: one or more processors; a memory; one or more executable programs are stored in the memory, and the one or more processors read the executable program code stored in the memory and run the program corresponding to the executable program code to execute the method for finding the optimal root node of an undirected tree graph as described in any one of Embodiment 1.
[0104] Figure 7FIG. 1 is a schematic diagram of the structure of an embodiment of an electronic device of the present invention, which can implement any method described in Embodiment 1 of the present invention, such as Figure 7 As shown, as an optional embodiment, the above-mentioned electronic device may include: a shell 41, a processor 42, a memory 43, a circuit board 44 and a power supply circuit 45, wherein the circuit board 44 is arranged inside the space enclosed by the shell 41, and the processor 42 and the memory 43 are arranged on the circuit board 44; the power supply circuit 45 is used to supply power to various circuits or devices of the above-mentioned electronic device; the memory 43 is used to store executable program codes; the processor 42 runs the program corresponding to the executable program code by reading the executable program code stored in the memory 43, and is used to execute the method for finding the optimal root node of an undirected tree graph as described in any of the above-mentioned embodiments one.
[0105] The specific execution process of the above steps by the processor 42 and the steps further executed by the processor 42 by running the executable program code can be found in the description of the first embodiment of the method for finding the optimal root node of an undirected tree graph of the present invention, which will not be repeated here.
[0106] The electronic device exists in various forms, including but not limited to: (1) Mobile communication devices: This type of device is characterized by having mobile communication functions and its main goal is to provide voice and data communications. Such terminals include: smart phones, multimedia phones, functional phones, and low-end phones. (2) Ultra-mobile personal computer devices: This type of device belongs to the category of personal computers, has computing and processing functions, and generally also has mobile Internet access features. Such terminals include: PDA, MID and UMPC devices, such as iPad. (3) Portable entertainment devices: This type of device can display and play multimedia content. Such devices include: audio and video playback modules (such as iPod), handheld game consoles, e-books, as well as smart toys and portable car navigation devices. (4) Servers: Devices that provide computing services. The server's composition includes processors, hard disks, memory, device buses, etc. The server is similar to the general computer architecture, but because it needs to provide highly reliable services, it has higher requirements in terms of processing power, stability, reliability, security, scalability, manageability, etc. (5) Other electronic devices with data interaction functions.
[0107] An embodiment of the present invention also provides a computer-readable storage medium, which stores one or more programs. The one or more programs can be executed by one or more processors to implement the method of finding the optimal root node of an undirected tree graph as described in any of the above-mentioned embodiments.
[0108] In summary, according to the description of the above embodiments, the method and device for finding the optimal root node of an undirected tree graph disclosed in the embodiments of the present invention starts from the edge of the undirected tree graph, folds the nodes according to the preset folding rules, so that only two center points or one center point are left, and then expands outward from the center point according to the preset expansion rules, and then finds the optimal root node according to the preset root node screening rules. In this way, the automatic root node search scheme is optimized, making the determined root node more reasonable, thereby facilitating accurate and automatic search for reasonable root nodes.
[0109] Furthermore, the user can independently configure the preset screening rules, and the method for automatically finding the optimal root node of the undirected tree graph that can be independently configured is a method for automatically finding the optimal root node of the undirected tree graph that can be independently configured. Figure 1 and Figure 2 The illustrated method for finding the root node is optimized and can be configured accordingly according to different application scenarios and information, so that the root node found is more in line with the actual situation and more reasonable.
[0110] It should be noted that, in this article, if the description involves the relational terms such as first and second, it is only used to distinguish one entity or operation from another entity or operation, and does not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0111] Each embodiment in this specification is described in a related manner, and the same or similar parts between the embodiments can be referenced to each other, and each embodiment focuses on the differences from other embodiments.
[0112] A person skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through a computer program, and the program can be stored in a computer-readable storage medium, and when the program is executed, it can include the processes of the embodiments of the above-mentioned methods. The storage medium can also be a disk, an optical disk, a read-only memory (ROM) or a random access memory (RAM).
[0113] The above is only a specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any changes or substitutions that can be easily thought of by a person skilled in the art within the technical scope disclosed by the present invention should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.
Claims
1. A method for finding the optimal root node of an undirected tree graph, characterized in that: The method comprises the steps of: Get all nodes of the undirected tree graph; Starting from the edge of the undirected tree graph, folding the nodes according to a preset folding rule until at most two center points remain; Expand the nodes outward from the at most two center points according to a preset expansion rule; According to a preset root node screening rule, a node that is closest to the central node and meets the preset root node screening rule is determined as an optimal root node in the network represented by the undirected tree graph; The preset root node screening rules include: network type, node type of the root node in the corresponding type of network and the level of the network where the root node is located.
2. The method for finding the optimal root node of an undirected tree graph according to claim 1, characterized in that: The nodes include leaf nodes and bridge nodes. The nodes carry node attributes, which include link attributes and children attributes. The bridge node is an isolated node adjacent to at least two clusters. Starting from the edge of the undirected tree graph, the nodes are folded according to a preset folding rule until at most two center points remain, including: According to the node attributes of the node, traverse and obtain a set of leaf nodes with a first link attribute and a set of bridge nodes with a second link attribute in the undirected tree graph; the first link attribute is having a unique adjacent point, and the second link attribute is having two adjacent points; Traversing the leaf nodes in the leaf node set, for a first leaf node, if it is detected that the only adjacent point of the first leaf node is not a bridge node or a leaf node, determining the adjacent point as a parent node of the first leaf node; Add the first leaf node to the children attribute of the parent node, delete the first leaf node from the link attribute of the parent node, and delete it from the topology map data; The leaf node set and the bridge node set are updated.
3. The method for finding the optimal root node of an undirected tree graph according to claim 2, characterized in that: The step of folding the nodes starting from the edge of the undirected tree graph according to a preset folding rule until at most two center points remain also includes: Traversing the bridge nodes in the bridge node set, for a first bridge node, searching for adjacent points from the first bridge node to both sides, and detecting whether the adjacent points are endpoints, until the adjacent points are found to be endpoints; Arrange the edges and nodes between the endpoints obtained on both sides into a link set in the order of connection; The bridge nodes in the link set are deleted from the bridge node set.
4. The method for finding the optimal root node of an undirected tree graph according to claim 3, characterized in that: After deleting the bridge nodes in the link set from the bridge node set, the method further comprises: for each edge in the link set, detecting whether there is a non-empty link in the links attribute of each edge; If so, the link of this edge is released and a new link set is formed.
5. The method for finding the optimal root node of an undirected tree graph according to claim 4, characterized in that: After forming the new link set, the method further includes: creating a new edge between the two endpoints; The edges and corresponding adjacent points of the original node link set between the two endpoints are deleted from the links attributes of the two endpoints, and the two endpoints are added to the links attributes of the new link set, and the corresponding newly created edges are created; If one of the two endpoints is a leaf node and the other is not a leaf node, then add the leaf node to the children attribute of the other non-leaf node; Delete the leaf node from the link attribute of another non-leaf node, and delete the leaf node from the topology map data; The above steps are iterated until the number of nodes in the topology data is less than or equal to 2, and the remaining one or two nodes are used as center points.
6. The method for finding the optimal root node of an undirected tree graph according to claim 1 or 5, characterized in that: The step of determining, according to the preset root node screening rule, the node closest to the central node and meeting the preset root node screening rule as the optimal root node in the network represented by the undirected tree comprises: traversing all nodes to find a set of candidate nodes meeting the preset root node screening rule; If the set of candidate nodes is empty, one or two center points are returned as the optimal root nodes according to the set number of root nodes.
7. The method for finding the optimal root node of an undirected tree graph according to claim 6, characterized in that: The method further comprises: if the set of nodes to be selected is not empty, starting from the central node, sequentially expanding the nodes to find the optimal root node; Searching the set of candidate nodes for all target nodes that meet preset screening rules; Sort the target nodes in ascending order according to the shortest path length to the central node; According to the number of set root nodes, the first n target nodes are selected as the optimal root nodes to be returned; n is the smaller value between the number of nodes that meet the preset screening rules and the number of set root nodes.
8. The method for finding the optimal root node of an undirected tree graph according to claim 7, characterized in that: After searching all target nodes in the nodes that meet the preset screening rules from the set of candidate nodes, the method further includes: if no target node that meets the preset screening rules is found in the nodes, expanding the topology map data once; Traverse all current nodes. For each node i, if the children attribute of the node i is not empty, add all nodes k in the children to the current node of the topology data, and find the connection edge with the node i according to the link attribute of the node k, and add the node k to the link attribute of the node i. Each node k corresponds to the connection edge of the node i. Count all the edges in the current topology data. For each edge l, if the links attribute of the edge l is not empty, release the link of the edge l. According to the link set of the links attribute of the link edge l, all nodes in the link set are added to the current node, and according to the first and last edges of the link set, the two endpoints and their respective adjacent nodes are added to each other's link attributes to reconnect them; Repeat the above steps until all target nodes that meet the preset screening rules are found in the set of candidate nodes; Sort the target nodes in ascending order according to the shortest path length to the central node; According to the number of set root nodes, the first n target nodes are selected as the optimal root nodes to be returned; n is the smaller value between the number of nodes that meet the preset screening rules and the number of set root nodes.
9. The method for finding the optimal root node of an undirected tree graph according to claim 1, characterized in that: The method further includes: presetting the number of root nodes and configuring preset screening rules for the root nodes.
10. A device for finding the optimal root node of an undirected tree graph, characterized in that: The device comprises: A node acquisition program module is used to obtain all nodes of the undirected tree graph; A folding program module, used to fold the nodes starting from the edge of the undirected tree graph according to a preset folding rule until at most two center points remain; An expansion program module, used to expand the nodes outward from the at most two center points according to a preset expansion rule; A determination program module is used to determine, according to a preset root node screening rule, a node that is closest to the central node and meets the preset root node screening rule as the optimal root node in the network represented by the undirected tree graph; the preset root node screening rule includes: network type, node type of the root node in the corresponding type of network, and the level of the network where the root node is located.
11. An electronic device, characterized in that: include: One or more processors; Memory; One or more executable programs are stored in the memory, and the one or more processors read the executable program code stored in the memory and run the program corresponding to the executable program code to execute the method for finding the optimal root node of an undirected tree graph as described in any one of claims 1 to 9.
