Index-based minimum spanning tree query method, system, device and medium

By shrinking cycles into vertices in a directed graph and building an index, the problem of low query efficiency in existing technologies is solved, and fast querying of the minimum spanning tree is achieved.

CN116701405BActive Publication Date: 2026-01-02GUANGZHOU UNIVERSITY
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310811846.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-07-03
Publication Date
2026-01-02
Estimated Expiration
2043-07-03

AI Technical Summary

Technical Problem

Existing minimum spanning tree query methods are inefficient, requiring traversal of the entire graph for each query and resulting in repeated calculations of cycle information.

Method used

By shrinking the loops in the directed graph into a single vertex, an index for the candidate set and an index for the join set are generated. The indexes are then used to perform queries to obtain the minimum spanning tree.

Benefits of technology

It reduces query time, avoids redundant calculations in loops, and improves query efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116701405B_ABST
    Figure CN116701405B_ABST
Patent Text Reader

Abstract

The application provides a directed graph-based index-based minimum spanning tree query method, system, device and medium, and relates to the technical field of directed graphs, wherein the method comprises the following steps: obtaining the edges and vertices of a network structure setting directed graph of a network to be queried to obtain a directed graph; contracting a loop in the directed graph into a single vertex, recording the current loop information as an alternative set index, and recording the minimum connection out edge of the loop as a connection set index; performing a query on the connection set index, and obtaining a minimum edge according to the alternative set index to query a minimum spanning tree. The application utilizes the vertex contraction feature, contracts a minimum edge loop into a single vertex, and generates alternative set and connection set indexes for storage. Through the indexes, a large number of repeatedly calculated parts are recorded as alternative set indexes, the connection information between loops is recorded, and traversal is directly performed on the connection set to replace searching on the graph, so that the query time is greatly reduced.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present document relates to the technical field of directed graph, and particularly relates to a minimum spanning tree query method based on index in a directed graph, a system, a device and a medium. BACKGROUND

[0002] The minimum spanning tree refers to, in a directed graph, given a query vertex, finding a tree taking the query vertex as a root node, all vertices are on the tree, and the sum of the weights of the tree is minimum. The minimum spanning tree has a wide range of applications. In the field of communication, it is used to realize minimum cost connection and control, in the database, it can be used as reachability query, and in the field of natural language, the minimum spanning tree can be used for syntax analysis processing. The existing minimum spanning tree query method is instant calculation, and the query process is accelerated by using data structure or algorithm design. The existing minimum spanning tree query method has the following problems:

[0003] 1) Low algorithm efficiency, each query needs to traverse the whole graph, and a large amount of calculation time is needed;

[0004] 2) Repetitive calculation, a large amount of loop information in the graph is repeatedly calculated for different vertex queries. SUMMARY

[0005] The present application provides a minimum spanning tree query method based on index in a directed graph, a system, a device and a medium, which aims to solve the above problems.

[0006] The present application provides a minimum spanning tree query method based on index in a directed graph, comprising:

[0007] S1, obtaining the edges and vertices of the network structure setting of the network to be queried to obtain a directed graph;

[0008] S2, contracting the loop in the directed graph into a single vertex, and recording the current loop information as an alternative set index, and recording the minimum connection out edge of the loop as a connection set index;

[0009] S3, querying on the connection set index, and obtaining the minimum edge according to the alternative set index to query the minimum spanning tree.

[0010] The present application provides a minimum spanning tree query system based on index in a directed graph, comprising:

[0011] A directed graph module is configured to obtain the edges and vertices of the network structure setting of the network to be queried to obtain a directed graph;

[0012] A loop contraction module is configured to contract the loop in the directed graph into a single vertex, and record the current loop information as an alternative set index, and record the minimum connection out edge of the loop as a connection set index.

[0013] a minimum spanning tree module for querying on the connection set index and obtaining the minimum edge from the alternative set index to query the minimum spanning tree.

[0014] The present application provides an electronic device, comprising:

[0015] a processor; and

[0016] a memory arranged to store computer executable instructions that, when executed, cause the processor to perform the steps of the index-based minimum spanning tree query method in a directed graph as described above.

[0017] The present application provides a storage medium for storing computer executable instructions that, when executed, implement the steps of the index-based minimum spanning tree query method in a directed graph as described above.

[0018] By employing the embodiments of the present application, the minimum edge loop is contracted into a single vertex by using the vertex contraction feature, and the alternative set and connection set index are generated and stored. By indexing, the part of a large number of repeated calculations is recorded as the alternative set index, the connection information between loops is recorded, and the traversal is directly performed on the connection set instead of searching on the graph, thereby greatly reducing the query time. BRIEF DESCRIPTION OF DRAWINGS

[0019] In order to more clearly illustrate the technical solutions in the one or more embodiments of the present application or the prior art, the drawings needed to be used in the embodiment or prior art description will be briefly introduced as follows. Obviously, the drawings in the following description are only some embodiments described in the present application, and other drawings can be obtained by those skilled in the art without any creative effort on the basis of these drawings.

[0020] Figure 1 a flow chart of the index-based minimum spanning tree query method in a directed graph of the embodiments of the present application;

[0021] Figure 2 a schematic diagram of the index-based minimum spanning tree query system in a directed graph of the embodiments of the present application;

[0022] Figure 3 a directed graph diagram of the embodiments of the present application;

[0023] Figure 4 a schematic diagram of the alternative set index of the embodiments of the present application;

[0024] Figure 5 a schematic diagram of the connection set index of the embodiments of the present application. DETAILED DESCRIPTION

[0025] In order for those skilled in the technical field to better understand the technical solutions in the one or more embodiments of the present specification, the technical solutions in the one or more embodiments of the present specification will be clearly and completely described below in conjunction with the drawings in the one or more embodiments of the present specification. Obviously, the described embodiments are only a part of the embodiments of the present specification, rather than all the embodiments. Based on the one or more embodiments of the present specification, all other embodiments obtained by those skilled in the art without creative labor should belong to the protection scope of the present document.

[0026] Method embodiments

[0027] According to the embodiments of the present application, a directed graph based on index minimum spanning tree query method is provided, Figure 1 The flow chart of the directed graph based on index minimum spanning tree query method of the embodiments of the present application is shown according to Figure 1 The directed graph based on index minimum spanning tree query method of the embodiments of the present application specifically includes:

[0028] S1, obtaining the edge and vertex of the network structure setting of the network to be queried to obtain a directed graph;

[0029] S2, contracting the loop in the directed graph into a single vertex, and recording the current loop information as the candidate set index and recording the minimum connection out edge of the loop as the connection set index; specifically including:

[0030] (a) traversing all the vertices in the graph, calculating the minimum weight in edge of each vertex and its vertex as the input of step b calculation;

[0031] (b) for each vertex u, recursively find its in edge vertex, if it returns to vertex u, we get a minimum value loop, after traversing all the vertices, we get all the minimum value loops. And record the current minimum value loop information, store the points and edges in the loop as the candidate set index. For the current minimum value loop C, if the vertices in the loop exist contracted vertices, that is, the minimum value loop C' has been saved, we need to record the minimum edge pointing to C' as the connection edge and record the connection vertex of the connection edge in the connection set index corresponding to the out edge index and in edge index of C and C';

[0032] (c) contracting all loops into a new vertex v', and modifying the edge weight from other vertices to the new vertex v', subtracting the minimum edge weight in the minimum value loop of the vertex from the original weight, and contracting the edges of the whole graph;

[0033] (d) if the current graph has no loop, the candidate set and the connection set are constructed, otherwise repeat steps (a) to (d).

[0034] As Figure 4 is a schematic diagram of the alternative set index of an embodiment of the present application, Figure 5 is a schematic diagram of the connection set index of an embodiment of the present application.

[0035] S3, querying on the connection set index and obtaining the minimum edge according to the alternative set index, querying the minimum spanning tree. Specifically comprising:

[0036] (a) Given a query vertex v, find the loop C to which it belongs in the connection set index;

[0037] (b) Taking the vertex v as the root node, determining the loop in which the current root node is located according to the alternative set information, deleting the incoming edge in the loop, and adding the remaining edge to the minimum spanning tree;

[0038] (c) If the loop C has a connection edge pointing to other smaller loops in the connection set, go to the smaller loop along the connection outgoing edge and take the connection vertex as the root node, repeat step (b); if the loop has a connection edge pointed to by other larger loops in the connection set, go to the larger loop along the connection edge and take the loop C as the root node, repeat step (b); if the loop has been searched, skip the loop;

[0039] (d) If all the traversed loops, the smaller loops pointed to and the larger loops pointed to by them are searched, the search is ended, and the minimum spanning tree query is ended.

[0040] Specifically, the specific content of modeling the city-scale road network and the large-scale social network in S1 in the embodiment of the present application is that the city-scale road network and the large-scale social network are represented by a graph structure, wherein the vertex on the graph structure is an intersection or a user, the edge on the graph structure is a road or a user relationship, and when there is a one-way relationship between the vertex u and the vertex v, there is an edge from u to v. As Figure 3 is a schematic diagram of a directed graph of an embodiment of the present application;

[0041] Specifically, the hierarchical tree index of the directed graph needs to be generated in S2 in the embodiment of the present application. First, all vertices in the graph are traversed to calculate the minimum weight in-edge of each vertex and the vertex thereof as the input for the following calculation. For each vertex u, the in-edge vertex thereof is recursively searched. If the vertex u is returned, a minimum value loop is obtained. After all vertices are traversed, all minimum value loops are obtained. The information of the current minimum value loop is recorded, and the points and edges in the loop are stored as the candidate set index. For the current minimum value loop C, if the vertex in the loop has a contraction vertex, that is, the minimum value loop C' has been saved, the minimum edge pointing to C' is recorded as the connection edge, and the connection vertex of the connection edge is recorded in the connection set index corresponding to the out-edge index and the in-edge index of C and C', respectively. Then, all loops are contracted into a new vertex v', and the edge weight from other vertices to the new vertex v' is modified by subtracting the minimum edge weight in the minimum value loop of the vertex from the original weight. The edge contraction is performed on the whole graph. If the current graph has no loop, the candidate set and the deletion set are constructed, otherwise the above steps are repeated. For example Figure 1 After the minimum in-edge of each vertex is obtained, two minimum value loops, v2, v3 and v4, v5, v6, can be calculated. After the loop is contracted into a vertex and the above operation is repeated, a minimum value loop v1, (v4, v5, v6) can be calculated. Assuming that the loop v4, v5, v6 is C', and the current minimum value loop v1, (v4, v5, v6) is C, the connection edge of v1 pointing to C' is recorded in the in-edge index of C' and the out-edge index of C.

[0042] Specifically, the original graph in S3 is searched from the query vertex, the minimum edge is searched according to the index, and the minimum spanning tree is obtained. First, find the query vertex v, which belongs to the loop C in the connection set index. Then, taking the vertex v as the root node, according to the alternative set information, determine the loop where the current root node is located, delete the incoming edge in the loop, and add the remaining edge to the minimum spanning tree. If the loop C has a connection edge pointing to other smaller loops in the connection set, go to the smaller loop along the connection outgoing edge, and take the connection vertex as the root node, repeat the edge deletion operation and the minimum spanning tree addition operation; if the loop has a connection edge pointed to by other larger loops in the connection set, go to the larger loop along the connection edge, and take the loop C as the root node, repeat the edge deletion operation and the minimum spanning tree addition operation; if the loop has been searched, skip the loop. Finally, if all the traversed loops, the smaller loops pointed to by the loop and the larger loops pointed to by the loop are searched, the search is ended, and the minimum spanning tree query is ended. Taking the drawing as an example, the minimum spanning tree of the current query v1, first find the loop where v1 is located, which is c3, delete the incoming edge A2 of v1, and add the remaining minimum edge A3 to the minimum spanning tree; then in the connection set, there is a smaller loop C1 in the outgoing edge index of C3, then record V5 as the connection vertex, and repeat the above operation in the C1 loop; there is a larger loop C4 in the incoming edge index of C3, then record C3 as the connection vertex, and repeat the above operation in the C4 loop.

[0043] According to the embodiment of the present application, the following beneficial effects are achieved:

[0044] 1. The present application shrinks the loops in the graph into vertices, records the information of each loop, constructs the alternative set and the connection index, queries the index, queries on the connection set, and obtains the minimum edge according to the alternative set to query the minimum spanning tree.

[0045] 2. The present application avoids a large amount of repeated calculation of loops, and stores the minimum loop information in the alternative set index by pre-computation, and stores the connection information between loops in the connection set index.

[0046] 3. The present application reduces a large amount of search time, and changes the search from the graph to the index, so that the search space size is greatly reduced.

[0047] System embodiment

[0048] According to the embodiment of the present application, a directed graph index-based minimum spanning tree query system is provided, Figure 2 The schematic diagram of the directed graph index-based minimum spanning tree query system of the embodiment of the present application is shown in Figure 2 The directed graph index-based minimum spanning tree query system of the embodiment of the present application specifically comprises:

[0049] The directed graph construction module 201 is configured to obtain edges and vertices of a network structure setting directed graph of a network to be queried to obtain the directed graph;

[0050] The loop contraction module 202 is configured to contract a loop in the directed graph into a single vertex, and record current loop information as an alternative set index and record a minimum connection edge of the loop as a connection set index;

[0051] The minimum spanning tree module 203 is configured to query on the connection set index, and obtain a minimum edge according to the alternative set index to query a minimum spanning tree.

[0052] The loop contraction module 202 is specifically configured to:

[0053] All vertices in the directed graph are traversed to calculate a minimum weight in edge and a corresponding vertex of each vertex;

[0054] For each vertex u obtained, a recursive search is performed on an in edge vertex thereof, if the vertex u is returned, a minimum value loop is obtained, after all vertices are traversed, all minimum value loops are obtained, and current minimum value loop information is recorded, and points and edges in the loop are stored as the alternative set index; for the current minimum value loop C, if there is a contraction vertex C' in the vertices in the loop, a minimum edge pointing to the contraction vertex C' is recorded as a connection edge, and a connection vertex of the connection edge is recorded in the connection set index corresponding to out edge index and in edge index of C and C' respectively;

[0055] All loops are contracted into a new vertex v', and an edge weight from other vertices to the new vertex v' is modified, that is, the original weight is reduced by a minimum edge weight in a minimum value loop of the vertex, and edge contraction is performed on the entire directed graph;

[0056] The above steps are repeatedly executed until there is no loop in the directed graph, and then the alternative set and the connection set are constructed.

[0057] The connection set index is directly used for querying in the minimum spanning tree module 203, all loops in the directed graph are broken, and a minimum edge is obtained according to the alternative set index, so that the minimum spanning tree is queried.

[0058] The minimum spanning tree module 203 is specifically configured to:

[0059] Given a query vertex V, a loop C to which the query vertex V belongs in the connection set index is found;

[0060] In the loop C, the in edge of the root node in the loop is deleted according to the alternative set index, and the remaining edges in the loop C are added to the minimum spanning tree with the root node as a root node;

[0061] If the loop C has connection edges pointing to other smaller loops in the connection set index, go along the connection out edges to the smaller loops and take the connection vertex as the root node, delete the in edges of the root node in the loop according to the alternative set index, and add the remaining edges in the loop C to the minimum spanning tree; if the loop has connection edges pointed by other larger loops in the connection set, go along the connection edges to the larger loops and take the loop C as the root node, delete the in edges of the root node in the loop according to the alternative set index, and add the remaining edges in the loop C to the minimum spanning tree; if the loop has been searched, skip the loop;

[0062] If all the traversed loops, the pointed smaller loops and the pointed larger loops are searched, the search is ended, and the minimum spanning tree query is ended.

[0063] Device embodiment one

[0064] The embodiment of the application provides an electronic device, comprising:

[0065] A processor; and

[0066] A memory arranged to store computer executable instructions which, when executed, cause the processor to perform the steps of the method embodiments described above.

[0067] Device embodiment two

[0068] The embodiment of the application provides a storage medium for storing computer executable instructions which, when executed, implement the steps of the method embodiments described above.

[0069] Finally, it should be noted that: the above embodiments are only used to illustrate the technical solutions of the application, and not to limit them; although the application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that: it can still modify the technical solutions recorded in the foregoing embodiments, or make equivalent replacement to part or all of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the scope of the technical solutions of the embodiments of the application.

Claims

1. A method for querying the minimum spanning tree in a directed graph based on an index, characterized in that, include: S1. Obtain the network structure of the network to be queried by setting the edges and vertices of the directed graph. S2. Shrink the loops in the directed graph into a single vertex, and record the current loop information as a candidate set index, and record the minimum outgoing edge of the loop as a connection set index. S3. Perform a query on the join set index and obtain the minimum edge based on the candidate set index, then query the minimum spanning tree; S2 specifically includes: S21. Traverse all vertices in the directed graph and calculate the minimum weight incoming edge of each vertex and its corresponding vertex. S22, For each vertex obtained in S21 u Recursively search for its incoming edge vertex, and if it returns to the vertex... u This yields a minimum value cycle. After traversing all vertices, all minimum value cycles are obtained; the information of the current minimum value cycle is recorded, and the vertices and edges in the cycle are stored as candidate set indices; for the current minimum value cycle... C If the vertices in the loop have shrinking vertices C’ Then it will point to C’ The smallest edge is recorded as a connecting edge, and the connecting vertices of the connecting edge are also recorded and stored in the connection set index. C and C’ Corresponding to the outgoing edge index and the incoming edge index; S23, shrink all loops into new vertices. v’ And modify other vertices to the new vertex. v’ The edge weights are calculated by subtracting the minimum edge weight in the minimum value cycle of that vertex from the original weights, and then the entire directed graph is shrunk. S24. Repeat S21-S23 until there are no loops in the directed graph, then the candidate set and connection set are completed; S3 specifically includes: S31, Given a query vertex V Find the loop to which it belongs in the join set index. C ; S32, on the ring road C In the middle, with the vertex V As the root node, based on the candidate set index, delete the incoming edges of the root node in the cycle, thus breaking the cycle. C Add the remaining edges to the minimum spanning tree; S33, if the ring road C If there is a connecting edge in the connection set index pointing to another smaller cycle, then follow the connecting edge to the smaller cycle and repeat S32 with the connecting vertex as the root node; if the cycle has a connecting edge in the connection set pointed to by another larger cycle, then follow the connecting edge to the larger cycle and repeat S32 with the cycle as the root node. C For the root node, repeat S32; if a loop has already been searched, skip that loop. S34. If all the loops that have been traversed have found both the smaller loops they point to and the larger loops they point to, then the search ends and the minimum spanning tree query ends.

2. The method according to claim 1, characterized in that, In step S3, the join set index is used directly for querying. The join set index is traversed, each cycle in the directed graph is broken, and the minimum edge is obtained according to the candidate set index, thereby completing the query for the minimum spanning tree.

3. A minimum spanning tree query system based on index in a directed graph, characterized in that, include: A directed graph construction module is used to obtain the network structure of the network to be queried, and to set the edges and vertices of the directed graph to obtain the directed graph. The loop shrinking module is used to shrink the loops in the directed graph into a single vertex, and record the current loop information as a candidate set index, and record the minimum outgoing edge of the loop as a connection set index. The minimum spanning tree module is used to query on the join set index and obtain the minimum edge based on the candidate set index, and then query the minimum spanning tree. The loop shrinking module is specifically used for: Traverse all vertices in the directed graph and calculate the minimum weight incoming edge for each vertex and its corresponding vertex. For each vertex obtained u Recursively search for its incoming edge vertex, and if it returns to the vertex... u This results in a minimum value cycle. After traversing all vertices, all minimum value cycles are obtained. It also records the information of the current minimum value cycle, storing the points and edges in the cycle as indices for the candidate set; for the current minimum value cycle... C If the vertices in the loop have shrinking vertices C’ Then it will point to C’ The smallest edge is recorded as a connecting edge, and the connecting vertices of the connecting edge are also recorded and stored in the connection set index. C and C’ Corresponding to the outgoing edge index and the incoming edge index; Shrink all loops into new vertices v’ And modify other vertices to the new vertex. v’ The edge weights are calculated by subtracting the minimum edge weight in the minimum value cycle of that vertex from the original weights, and then the entire directed graph is shrunk. Repeat the above steps until there are no loops in the directed graph, then the candidate set and connection set are completed; The minimum spanning tree module is specifically used for: Given a query vertex V Find the loop to which it belongs in the join set index. C ; On the ring road C In the middle, with the vertex V As the root node, based on the candidate set index, delete the incoming edges of the root node in the cycle, thus breaking the cycle. C Add the remaining edges to the minimum spanning tree; If the loop C If there are connecting edges in the connection set index pointing to other smaller cycles, then follow the outgoing edges to the smaller cycles, and using the connecting vertex as the root node, delete the incoming edges of the root node in the cycle according to the candidate set index, thus breaking the cycle. C Add the remaining edges to the minimum spanning tree; if the cycle has connecting edges in the connection set that are pointed to by other larger cycles, then follow the connecting edges to the larger cycle and use the cycle as the starting point. C As the root node, based on the candidate set index, delete the incoming edges of the root node in the cycle, thus breaking the cycle. C Add the remaining edges to the minimum spanning tree; If the loop has already been searched, skip that loop; The search ends and the minimum spanning tree query ends when all the smaller and larger loops pointed to by the traversed loops have been found.

4. The system according to claim 3, characterized in that, The minimum spanning tree module directly uses the join set index for querying, traverses the join set index, breaks each cycle in the directed graph, and obtains the minimum edge based on the candidate set index, thereby completing the query for the minimum spanning tree.

5. An electronic device, comprising: processor; as well as, A memory configured to store computer-executable instructions, which, when executed, cause the processor to perform the steps of the index-based minimum spanning tree query method for a directed graph as described in any one of claims 1-2.

6. A storage medium for storing computer-executable instructions, which, when executed, implement the steps of the index-based minimum spanning tree query method for a directed graph as described in any one of claims 1-2.

Citation Information

Patent Citations

  • Keyword search method of relational database

    CN104573039A

  • Minimum spanning tree reconstruction method and data processing apparatus

    CN108345631A