A method for calculating the shortest routing path between nodes in a tree-shaped network
By initializing the data table in a tree network and sorting by level numbers, finding and comparing child nodes and intermediate nodes, the problems of complex logic and high resource consumption in the existing technology are solved, and fast and efficient route calculation is achieved.
Patent Information
- Application Number
- CN202210186908.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-02-28
- Publication Date
- 2025-06-24
- Estimated Expiration
- 2042-02-28
AI Technical Summary
The existing method of calculating the shortest route is complex logic, the calculation takes a long time and the resource consumes a lot, resulting in high costs and poor user experience.
By initializing the data table, record the level number and corresponding nodes of the tree network node from the leaf node to the root node, sort from large to small by level number, find the child nodes and intermediate nodes of the common level number, and compare to determine the shortest route.
It realizes fast calculation of the shortest route, reduces delay and resource consumption, and improves computing efficiency and availability.
Smart Images

Figure CN114501574B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and particularly relates to a method for calculating the shortest routing path between tree network nodes. Background Art
[0002] With the rapid growth of the scale of the Internet, the research focus of next-generation core routers is shifting towards scalable architectures. The tree structure is a non-linear structure that is quite widely used in daily life. For example, the layout of existing network communication base station equipment is also like this. Each base station node is distributed at different geographical locations and forms a parent-child relationship according to the size of administrative units. In this business scenario of realizing communication between two base station nodes, it is necessary to find the shortest path to reduce resource consumption. However, since there is a parent-child relationship between nodes, and this parent-child relationship is a many-to-many relationship, there will be many routing paths, but there is only one shortest path.
[0003] In most calculation methods, the entire tree network diagram is read, each node is traversed, and the route is calculated by an exhaustive method, or the height difference between two nodes needs to be judged before calculation, and different logical processes are performed according to the height difference. These methods have no problems in terms of calculation results, but there will be the following problems in the process: 1. The logic is complex, errors are likely to occur, and the generality is insufficient, and different business logics need to be processed; 2. The calculation takes a relatively long time and the user experience is not good; 3. More physical resources such as CPU, memory, disk, etc. are used, resulting in an increase in cost.
[0004] In view of the above problems, the present invention provides a method for calculating the shortest routing path between tree network nodes, which can quickly calculate the shortest path, reduce latency and cost, and improve availability and efficiency. Summary of the Invention
[0005] Object of the Invention: The object of the present invention is to provide a method for calculating the shortest routing path between tree network nodes, which solves the problems of complex logic, long calculation time, large resource consumption and high cost existing in the existing methods for calculating the shortest path. The present invention can quickly calculate the shortest path, reduce latency and cost, and improve availability and efficiency.
[0006] Technical Solution: A method for calculating the shortest routing path between tree network nodes of the present invention includes the following steps:
[0007] (1) Initialize the data table. The data table includes all level numbers of the tree network nodes from the leaf nodes to the root node, and the nodes corresponding to the level numbers. After initialization, the nodes corresponding to the level numbers are empty;
[0008] (2) Select the source node, and place the source node at the node position corresponding to its level number in the data table; query the parent node of the source node, which is denoted as the first child node, and place the first child node at the node position corresponding to its level number; query the parent node of the first child node, which is denoted as the second child node, and place the second child node at the node position corresponding to its level number; repeat the query multiple times. Query the parent node of the (N - 1)th child node, which is denoted as the Nth child node. The Nth child node is the root node, and place the Nth child node at the node position corresponding to its level number, where N is a positive integer;
[0009] (3) Select the target node, and place the target node at the node position corresponding to its level number in the data table; query the parent node of the target node, which is denoted as the first intermediate node, and place the first intermediate node at the node position corresponding to its level number; query the parent node of the first intermediate node, which is denoted as the second intermediate node, and place the second intermediate node at the node position corresponding to its level number; repeat the query multiple times. Query the parent node of the (M - 1)th intermediate node, which is denoted as the Mth intermediate node. The Mth intermediate node is the root node, and place the Mth intermediate node at the node position corresponding to its level number, where M is a positive integer;
[0010] (4) Sort in descending order of the level number, and sequentially find the child nodes and intermediate nodes with the same level number and compare them. The comparison process is as follows: Determine whether there are identical nodes among the child nodes and intermediate nodes with the same level number. If there are identical nodes, the comparison ends. If there are no identical nodes, determine whether the child nodes and intermediate nodes with the same level number can be interconnected. If they can be interconnected, the comparison ends. If they cannot be interconnected, compare the child nodes and intermediate nodes with the next same level number until there are identical nodes or they can be interconnected among the child nodes and intermediate nodes with the same level number, and then the comparison ends;
[0011] (5) After there are identical nodes or they can be interconnected among the child nodes and intermediate nodes with the same level number, select the routing route from this child node to the source node, select the routing route from this intermediate node to the target node, and select the routing route between this child node and this intermediate node. The sum of these three routing routes is the shortest routing route, and end this method.
[0012] Further, before step (4), if the source node can be interconnected with the Xth intermediate node, where X is a positive integer from 1 to M, then the sum of the routing route from the Xth intermediate node to the target node and the routing route from the Xth intermediate node to the source node is the shortest routing route, and end this method.
[0013] Further, before step (4), if the target node can be interconnected with the Y-th child node, where Y is a positive integer from 1 to N, then the sum of the routing route from the Y-th child node to the source node and the routing route from the Y-th child node to the target node is the shortest routing route, and this method ends.
[0014] Further, before step (4), if the source node is the X-th intermediate node, where X is a positive integer from 1 to M, then the routing route from the X-th intermediate node to the target node is the shortest routing route, and this method ends.
[0015] Further, before step (4), if the target node is the Y-th child node, where Y is a positive integer from 1 to N, then the routing route from the Y-th child node to the source node is the shortest routing route, and this method ends.
[0016] Advantages of the present invention: The present invention can reduce the time consumed in calculating the shortest path between nodes in a tree-shaped network, reduce the user response time and resource consumption; at the same time, the implementation idea of this calculation method is easy to understand and does not need to be adjusted according to different business logics, which has universality; ultimately, the present invention can quickly calculate the shortest route, reduce latency and cost, and improve availability and efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] Figure 1 is a tree-shaped network topology diagram;
[0018] Figure 2 is a schematic diagram of Embodiment 1;
[0019] Figure 3 is a schematic diagram of Embodiment 2;
[0020] Figure 4 is a schematic diagram of Embodiment 3;
[0021] Figure 5 is a schematic diagram of Embodiment 4;
[0022] Figure 6 is a schematic diagram of Embodiment 5. DETAILED DESCRIPTION OF THE INVENTION
[0023] The present invention will be further described below with reference to the drawings and embodiments:
[0024] As Figure 1 shown, the overall network topology diagram is a tree-shaped structure with parent-child and sibling relationships from top to bottom, and the selection between any two points does not require judging the height difference between them.
[0025] Embodiment 1
[0026] As Figure 2As shown in the figure, the tree - shaped network topology diagram of this embodiment takes the node structure L3 - 0 of a single local area network as the root node as an example. It is divided into four - layer structures in total. The actual scenario is not limited by the number of layers. Each sibling node in the fourth layer can be connected and communicate with each other. Taking L6 - 1 as the source node and L6 - 3 as the target node as an example, then calculate the shortest routing path.
[0027] A method for calculating the shortest routing path between nodes in a tree - shaped network of the present invention includes the following steps:
[0028] (1) Initialize the data table. The data table includes all level numbers of the tree - shaped network nodes from the leaf nodes to the root node, and the nodes corresponding to the level numbers; after initialization, the nodes corresponding to the level numbers are empty; according to the topology diagram of this embodiment, the finally obtained data table is shown in Table 1.
[0029] Table 1 Data table after initialization in Embodiment 1
[0030] Level number Source node and corresponding child nodes Destination node and corresponding intermediate nodes 3 Empty Empty 4 Empty Empty 5 Empty Empty 6 Empty Empty
[0031] (2) Select the source node, and put the source node into the position of the node corresponding to the level number in the data table according to its level number; query the parent node of the source node and record it as the first child node, and put the first child node into the position of the node corresponding to the level number according to its level number; query the parent node of the first child node and record it as the second child node, and put the second child node into the position of the node corresponding to the level number according to its level number; repeat the query multiple times. Query the parent node of the (N - 1)th child node and record it as the Nth child node. The Nth child node is the root node, and put the Nth child node into the position of the node corresponding to the level number according to its level number, where N is a positive integer.
[0032] Taking L6 - 1 as the source node in this embodiment, put the source node into the data table according to its level number; then query the parent node of the source node and put it into the position of the node corresponding to the level number according to its level number; continue to query the parent node upward and put it into the data table until the queried parent node is the root node, and put the root node into the position of the node corresponding to the level number according to its level number, obtaining the data table shown in Table 2.
[0033] Table 2 Data table after querying the source node in Embodiment 1
[0034] Level number Source node and corresponding child nodes Destination node and corresponding intermediate nodes 3 L3-0 Empty 4 L4-1 Empty 5 L5-1 Empty 6 L6-1 Empty
[0035] (3) Select the target node, and place the target node at the node position corresponding to its level number in the data table; query the parent node of the target node and record it as the first intermediate node, and place the first intermediate node at the node position corresponding to its level number; query the parent node of the first intermediate node and record it as the second intermediate node, and place the second intermediate node at the node position corresponding to its level number; repeat the query multiple times, query the parent node of the (M - 1)th intermediate node and record it as the Mth intermediate node, the Mth intermediate node is the root node, and place the Mth intermediate node at the node position corresponding to its level number, where M is a positive integer;
[0036] Taking L6 - 3 in this embodiment as the target node, place the target node in the data table according to its level number; then query the parent node of the target node and place it at the node position corresponding to its level number; continue to query the parent node upward and place it in the data table until the queried parent node is the root node, and place the root node at the node position corresponding to its level number, obtaining the data table as shown in Table 3;
[0037] Table 3 Data table after querying the target node in Embodiment 1
[0038] Level number Source node and corresponding child nodes Destination node and corresponding intermediate nodes 3 L3-0 L3-0 4 L4-1 L4-2 5 L5-1 L5-2 6 L6-1 L6-3
[0039] (4) Sort in descending order of the level number, and sequentially find the child nodes and intermediate nodes with the same level number and compare them. The comparison process is as follows: Determine whether there are the same nodes among the child nodes and intermediate nodes with the same level number. If there are the same nodes, the comparison ends. If there are no same nodes, determine whether the child nodes and intermediate nodes with the same level number can be interconnected. If they can be interconnected, the comparison ends. If they cannot be interconnected, compare the child nodes and intermediate nodes with the next same level number until there are the same nodes or they can be interconnected among the child nodes and intermediate nodes with the same level number, and then the comparison ends;
[0040] According to the data in Table 3 of this embodiment, sort them in descending order of the level number, and sequentially find the child nodes and intermediate nodes with the same level number and compare them. First, compare L5-1 and L5-2 with the same level number 5. The comparison process is as follows: Determine whether L5-1 and L5-2 have the same nodes. If they have the same nodes, the comparison ends. If they do not have the same nodes, determine whether L5-1 and L5-2 can be interconnected. If they can be interconnected, the comparison ends. Finally, it is found that L5-1 and L5-2 neither have the same nodes nor can be interconnected. Then, compare the child nodes and intermediate nodes with the next same level number, that is, compare L4-1 and L4-2. The comparison process is as follows: Determine whether L4-1 and L4-2 have the same nodes. If they have the same nodes, the comparison ends. If they do not have the same nodes, determine whether L4-1 and L4-2 can be interconnected. If they can be interconnected, the comparison ends. Finally, it is found that L4-1 and L4-2 do not have the same nodes, but can be interconnected, and the comparison ends;
[0041] (5) After there are the same nodes or they can be interconnected between the child nodes and intermediate nodes with the same level number, select the routing route from this child node to the source node, select the routing route from this intermediate node to the target node, and select the routing route between this child node and this intermediate node. The sum of these three routing routes is the shortest routing route, and end this method;
[0042] According to this embodiment, it is known that L4-1 and L4-2 do not have the same nodes, but can be interconnected. Then, select the routing route from this child node to the source node, that is, the routing route L1 + L2 from L4-1 to the source node L6-1, select the routing route from this intermediate node to the target node, that is, the routing route L3 + L4 from L4-2 to the target node L6-3, and select the routing route between this child node and this intermediate node, that is, the routing route L5 from L4-1 to L4-2. The sum of these three routing routes L1 + L2 + L3 + L4 + L5 is the shortest routing route.
[0043] Embodiment 2
[0044] As Figure 3 shown, take the topology diagram with the node structure L3-0 of a single local area network as the root node in the tree-shaped network topology diagram of this embodiment as an example. It is divided into four layers in total. The actual scenario is not limited by the floor height. The sibling nodes in the fourth layer can be connected and communicate with each other. Take L4-1 as the source node and L6-4 as the target node as an example, and then calculate the shortest routing route.
[0045] For the method for calculating the shortest routing route between the nodes of the tree-shaped network in this embodiment, steps (1) to (3) are the same as steps (1) to (3) of Embodiment 1, so they will not be described repeatedly. Finally, the data table shown in Table 4 is obtained;
[0046] Table 4 Data table after querying the target node in Example 2
[0047]
[0048]
[0049] Then make a judgment. If the source node can be interconnected with the X-th intermediate node, where X is a positive integer from 1 to M, then the sum of the routing route from the X-th intermediate node to the target node and the routing route from the X-th intermediate node to the source node is the shortest routing route, and this method ends;
[0050] According to the topology diagram of this embodiment, it is known that the source node L4-1 and the intermediate node L4-2 can be interconnected. Then the routing route from the intermediate node to the target node is the routing route L6 + L7 from L4-2 to the target node L6-4, and the routing route from the intermediate node to the source node is the routing route L8 from L4-1 to L4-2. The sum of the two routing routes L6 + L7 + L8 is the shortest routing route.
[0051] Example 3
[0052] As Figure 4 shown, the tree-shaped network topology diagram of this embodiment takes the topology diagram with the node structure L3-0 of a single local area network as the root node as an example, and is divided into four layers in total. The actual scenario is not limited by the layer height. The sibling nodes in the fourth layer can be connected and communicate with each other. Taking L6-1 as the source node and L4-2 as the target node as an example, then calculate the shortest routing route.
[0053] A method for calculating the shortest routing route between nodes in a tree-shaped network in this embodiment, steps (1) to (3) are the same as steps (1) to (3) in Example 1, so they will not be described repeatedly. Finally, the data table shown in Table 5 is obtained;
[0054] Table 5 Data table after querying the target node in Example 3
[0055] Level number Source node and corresponding child nodes Destination node and corresponding intermediate nodes 3 L3-0 L3-0 4 L4-1 L4-2 5 L5-1 6 L6-1
[0056] Then make a judgment. If the target node can be interconnected with the Y-th child node, where Y is a positive integer from 1 to N, then the sum of the routing route from the Y-th child node to the source node and the routing route from the Y-th child node to the target node is the shortest routing route, and this method ends;
[0057] According to the topology diagram of this embodiment, it is known that the child node L4-1 and the target node L4-2 can be interconnected. Then the routing route from the child node to the source node is the routing route L9 + L10 from L4-1 to the source node L6-1, and the routing route from the child node to the target node is the routing route L11 from L4-1 to L4-2. The sum of the two routing routes L9 + L10 + L11 is the shortest routing route.
[0058] Example 4
[0059] As Figure 5 shown, the tree network topology diagram of this embodiment takes the topology diagram with the node structure L3-0 of a single local area network as the root node as an example, and is divided into four layers in total. The actual scenario is not limited by the floor height. The sibling nodes in the fourth layer can be connected and communicate with each other. Taking L6-2 as the source node and L3-0 as the target node as an example, the shortest routing path is then calculated.
[0060] For a method for calculating the shortest routing path between tree network nodes in this embodiment, steps (1) to (3) are the same as steps (1) to (3) of Embodiment 1, so they will not be described repeatedly. Finally, the data table shown in Table 6 is obtained;
[0061] Table 6 Data table after querying the target node in Example 4
[0062] Level number Source node and corresponding child nodes Destination node and corresponding intermediate nodes 3 L3-0 L3-0 4 L4-1 5 L5-1 6 L6-2
[0063] Then make a judgment. If the target node is the Yth child node, where Y is a positive integer from 1 to N, then the routing path from the Yth child node to the source node is the shortest routing path, and this method ends;
[0064] According to the topology diagram of this embodiment, it is known that the target node is the third child node, and the routing path L12 + L13 + L14 from the third child node to the source node is the shortest routing path.
[0065] Example 5
[0066] As Figure 6 shown, the tree network topology diagram of this embodiment takes the topology diagram with the node structure L3-0 of a single local area network as the root node as an example, and is divided into four layers in total. The actual scenario is not limited by the floor height. The sibling nodes in the fourth layer can be connected and communicate with each other. Taking L4-2 as the source node and L6-5 as the target node as an example, the shortest routing path is then calculated.
[0067] For a method for calculating the shortest routing path between tree network nodes in this embodiment, steps (1) to (3) are the same as steps (1) to (3) of Embodiment 1, so they will not be described repeatedly. Finally, the data table shown in Table 7 is obtained;
[0068] Table 7 Data table after querying the target node in Example 5
[0069] Level number Source node and corresponding child nodes Destination node and corresponding intermediate nodes 3 L3-0 L3-0 4 L4-2 L4-2 5 L5-2 6 L6-5
[0070] Then make a judgment. If the source node is the Xth intermediate node, where X is a positive integer from 1 to M, then the routing path from the Xth intermediate node to the target node is the shortest routing path, and this method ends.
[0071] According to the topological diagram of this implementation, it can be known that the source node is the second intermediate node, and the routing path L15+L16 from the second intermediate node to the target node is the shortest routing path.
Claims
1. A method for calculating the shortest routing path between tree - shaped network nodes, characterized in that, Including the following steps: (1) Initialize the data table, which includes all level numbers of the tree - shaped network nodes from the leaf nodes to the root node, and the nodes corresponding to the level numbers. After initialization, the nodes corresponding to the level numbers are empty. Among them, at least one node with the same level number in the tree - shaped network nodes is interconnected. (2) Select the source node, and place the source node at the position of the node corresponding to its level number in the data table. Query the parent node of the source node and record it as the first sub - node, and place the first sub - node at the position of the node corresponding to its level number. Query the parent node of the first sub - node and record it as the second sub - node, and place the second sub - node at the position of the node corresponding to its level number. Repeat the query multiple times. Query the parent node of the (N - 1)th sub - node and record it as the Nth sub - node. The Nth sub - node is the root node, and place the Nth sub - node at the position of the node corresponding to its level number, where N is a positive integer. (3) Select the target node, and place the target node at the position of the node corresponding to its level number in the data table. Query the parent node of the target node and record it as the first intermediate node, and place the first intermediate node at the position of the node corresponding to its level number. Query the parent node of the first intermediate node and record it as the second intermediate node, and place the second intermediate node at the position of the node corresponding to its level number. Repeat the query multiple times. Query the parent node of the (M - 1)th intermediate node and record it as the Mth intermediate node. The Mth intermediate node is the root node, and place the Mth intermediate node at the position of the node corresponding to its level number, where M is a positive integer. (4) Sort in descending order according to the level number, and sequentially find the sub - nodes and intermediate nodes with the same level number and compare them. The comparison process is as follows: Determine whether there are the same nodes among the sub - nodes and intermediate nodes with the same level number. If there are the same nodes, the comparison ends. If there are no same nodes, determine whether the sub - nodes and intermediate nodes with the same level number can be interconnected. If they can be interconnected, the comparison ends. If they cannot be interconnected, compare the sub - nodes and intermediate nodes with the next same level number until there are the same nodes or they can be interconnected among the sub - nodes and intermediate nodes with the same level number, and then the comparison ends. (5) After there are the same nodes or they can be interconnected among the sub - nodes and intermediate nodes with the same level number, select the routing route from this sub - node to the source node, select the routing route from this intermediate node to the target node, and select the routing route between this sub - node and this intermediate node. The sum of these three routing routes is the shortest routing route, and end this method. (6) Among them, before step (4), if the source node can be interconnected with the Xth intermediate node, where X is a positive integer from 1 to M, then the sum of the routing route from the Xth intermediate node to the target node and the routing route from the Xth intermediate node to the source node is the shortest routing route, and end this method. (7) Before step (4), if the target node can be interconnected with the Yth sub - node, where Y is a positive integer from 1 to N, then the sum of the routing route from the Yth sub - node to the source node and the routing route from the Yth sub - node to the target node is the shortest routing route, and end this method. Before step (4), if the source node is the X-th intermediate node, where X is a positive integer from 1 to M, the routing path from the X-th intermediate node to the target node is the shortest routing path, and this method ends; Before step (4), if the target node is the Y-th child node, where Y is a positive integer from 1 to N, the routing path from the Y-th child node to the source node is the shortest routing path, and this method ends.
Citation Information
Patent Citations
Routing creation method and router
CN102437963A
Method, device and system for obtaining path between two nodes of tree structure data
CN107679049A