Graph database-based power grid equipment reachability query method and system
Technical Field
The invention relates to the field of power topology data query, in particular to a graph database-based power grid equipment reachability query method and system.
Background
With the development of smart grid technology, a large number of primary grid devices are put into use, and the explosive increase of the device quantity brings a serious challenge to the management and query of the grid devices and the topological connection thereof. Meanwhile, a rapid analysis method for equipment accessibility is urgently needed for applications such as reconstruction of a power distribution network, detection and adjustment of an operation mode, auxiliary decision-making of fault treatment and the like. However, the conventional relational database is inefficient in realizing functions such as large-scale graph data storage and topology analysis, and no reachability analysis algorithm designed for device topology is available at present.
Disclosure of Invention
The invention aims to solve the technical problems that the existing relational database is low in efficiency in realizing the reachability analysis of large-scale graph data and lacks a reachability analysis algorithm designed aiming at equipment topology.
According to a first aspect, an embodiment of the present invention provides a graph database-based power grid device reachability query method, including: establishing a graph model of physical connection of the power grid equipment according to the topological connection relation among the power grid equipment to obtain an initial connected component index tree; searching a nearest common ancestor node between two power grid devices according to the initial connected component index tree, and judging whether the nearest common ancestor node is a non-root node or not; and when the nearest common ancestor node is a non-root node, determining that the two power grid devices can be reached.
Optionally, when the nearest common ancestor node is not a non-root node, it is determined that the two grid devices are unreachable.
Optionally, after a graph model of physical connection of the grid devices is established, and an initial connected component index tree is obtained, and before a closest common ancestor node between the two grid devices is found according to the initial connected component index tree, the grid device reachability query method further includes: when the graph model changes the topology, updating the initial connected component index tree to generate a connected component index tree after the topology is changed; and replacing the initial connected component index tree by the connected component index tree after the topology is changed.
Optionally, updating the initial connected component index tree includes: searching a currently running version along a directed edge representing topology change operation in the version diagram of the initial connected component index tree to obtain the connected component index tree after the topology is changed; when the version index node corresponding to the currently running version exists, the connected component index tree after the topology is changed is a connected component index tree taking the version index node as a root node; and when the version index node does not exist, establishing a newly added version graph, wherein the connected component index tree after the topology is changed is the corrected connected component index tree of the newly added node.
Optionally, updating the initial connected component index tree, further includes: correcting the connected component index tree of the newly added node, including: and searching a corresponding subgraph of the nearest common ancestor node of which the edge to be deleted is connected with the two power grid devices in the connected component index tree of the newly added node, and performing depth-first search on a connected component index subtree of the corresponding subgraph to obtain the connected component index tree with the changed topology.
According to a second aspect, an embodiment of the present invention provides a grid device reachability query system based on a graph database, including: the power grid equipment graph model building module is used for building a graph model of physical connection of the power grid equipment according to the topological connection relation of the power grid equipment to obtain an initial connected component index tree; the reachability detection module is used for searching a nearest common ancestor node between the two power grid devices according to the initial connected component index tree and judging whether the nearest common ancestor node is a non-root node or not; and when the nearest common ancestor node is a non-root node, determining that the two power grid devices can be reached.
Optionally, when the reachability detection module determines that the nearest common ancestor node is not a non-root node, it is determined that the two grid devices are unreachable.
Optionally, the grid device reachability query system further includes: an initial connected component index tree updating module, configured to update the initial connected component index tree when the graph model changes topology, and generate a connected component index tree after topology is changed; and replacing the initial connected component index tree by the connected component index tree after the topology is changed.
Optionally, the initial connected component index tree updating module includes: a topology-changed connected component index tree obtaining sub-module, configured to search a currently running version in a version diagram of the initial connected component index tree along a directed edge representing a topology change operation, to obtain a topology-changed connected component index tree; when the version index node corresponding to the currently running version exists, the connected component index tree after the topology is changed is a connected component index tree taking the version index node as a root node; and when the version index node does not exist, establishing a newly added version graph, wherein the connected component index tree after the topology is changed is the corrected connected component index tree of the newly added node.
Optionally, the initial connected component index tree updating module further includes: the correction submodule is used for correcting the connected component index tree of the newly added node; and searching a corresponding subgraph of the nearest common ancestor node of which the edge to be deleted is connected with the two power grid devices in the connected component index tree of the newly added node, and performing depth-first search on a connected component index subtree of the corresponding subgraph to obtain the connected component index tree with the changed topology.
According to a third aspect, an embodiment of the present invention provides a non-transitory computer-readable storage medium storing computer instructions for causing a computer to execute the power grid device reachability query method of the first aspect or any one of the alternatives of the first aspect.
According to a fourth aspect, an embodiment of the present invention provides a computer program product comprising a computer program stored on a non-transitory computer-readable storage medium, the computer program comprising program instructions that, when executed by a computer, cause the computer to perform the power grid device reachability query method of the first aspect or any one of the alternatives of the first aspect.
According to the graph database-based power grid equipment reachability query method and system, the reachability of the two equipment can be judged by searching whether a nearest common ancestor node of the two equipment nodes is a non-root node in the connected component index tree, so that the reachability query function of the power grid equipment is realized, and the efficiency is greatly improved when large-scale graph data and intensive reachability query tasks are faced; and when the operation mode of the power grid system is changed and the graph model changes the topology, the new index information can be generated by updating the initial connected component index tree to provide efficient reachability query, so that the adaptivity and the real-time performance of the reachability query method of the power grid equipment are improved.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, and it is obvious that the drawings in the following description are some embodiments of the present invention, and other drawings can be obtained by those skilled in the art without creative efforts.
Fig. 1 is a flowchart of a graph database-based power grid device reachability query method according to embodiment 1 of the present invention;
fig. 2 is a schematic diagram of an actual connection of the power grid devices in embodiment 1 of the present invention;
FIG. 3 is a diagram of a connected component index tree according to embodiment 1 of the present invention;
FIG. 4 is another schematic diagram of the actual connection of the devices in embodiment 1 of the present invention;
FIG. 5 is another diagram of a connected component index tree according to embodiment 1 of the present invention;
fig. 6 is another flowchart of a graph database-based grid device reachability query method according to embodiment 1 of the present invention;
FIG. 7 is a flowchart of updating an initial connected component index tree according to embodiment 1 of the present invention;
FIG. 8 is a schematic diagram of an operation mode version diagram in embodiment 1 of the present invention
Fig. 9A is a schematic structural diagram of a grid device reachability query system based on a graph database according to embodiment 2 of the present invention;
fig. 9B is another schematic structural diagram of the grid device reachability query system based on the graph database according to embodiment 2 of the present invention;
fig. 10 is a schematic structural diagram of an initial connected component index tree updating module in embodiment 2 of the present invention;
fig. 11 is a schematic structural diagram of an electronic device in embodiment 3 of the present invention.
Detailed Description
The technical solutions of the present invention will be described clearly and completely with reference to the accompanying drawings, and it should be understood that the described embodiments are some, but not all embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
In addition, the technical features involved in the different embodiments of the present invention described below may be combined with each other as long as they do not conflict with each other.
Example 1
The embodiment of the invention provides a graph database-based power grid equipment reachability query method, the flow of which is shown in figure 1, and the power grid equipment reachability query method comprises the following steps:
step S1: and establishing a graph model of the physical connection of the power grid equipment according to the topological connection relation among the power grid equipment to obtain an initial connected component index tree.
Step S2: searching a nearest common ancestor node between two power grid devices according to the initial connected component index tree, and judging whether the nearest common ancestor node is a non-root node or not; and when the nearest common ancestor node is a non-root node, the two power grid devices are judged to be reachable.
The power grid equipment reachability query method provided by the embodiment of the invention realizes the reachability query function of the power grid equipment and improves the query efficiency.
In a preferred embodiment, when the nearest common ancestor node is not a non-root node, it is determined that the two grid devices are unreachable.
Specifically, in an embodiment, the graph model in step S1 is divided into a power grid device topology graph model, a connected component index tree model, and a version graph model. The power grid equipment topological graph model is unique, a connected component index tree with the node as a root exists for each node in the version graph model, and leaf nodes of all the connected index trees contain and only contain all equipment nodes in the power grid topological graph model.
Furthermore, the initial connected component index tree can be obtained by performing depth-first search in a power grid topological graph, each non-root node in the initial connected component index tree is a connected component in the device topological graph of the corresponding version graph, and directed edges exist among child nodes of the root node in the initial connected component index tree to represent the relationship among a plurality of connected components.
Specifically, in one embodiment, fig. 2 is an exemplary diagram of the topology model of the power grid device, where nodes with numbers represent actual devices with physical entities and edges represent physical connections between the physical devices. Fig. 3 is an initial connected component index tree of the physical topology of the grid device of fig. 2, in which nodes a and B represent connected components shown by the dotted line range where the corresponding letter is located in the device topology (fig. 2), that is, node a represents a connected component formed by nodes 1, 2, 3, and 4, and node B represents a connected component formed by nodes 5, 6, and 7. In fig. 3, the R node is a connected component node of the whole graph, and V0 is a root node of the connected component index tree. In fig. 2, the nodes other than the root node V0 are connected component nodes. The solid lines in the index tree of connected components represent dependencies, and the child nodes are the subsets of connected components represented by the parent node. The initial connected component index tree can be realized by the existing algorithms such as simple depth-first search or Tarjan algorithm. For example, in FIG. 3, the nearest common ancestor of device node 1 and device node 3 is node A, and node A is a non-root node, then the two devices are reachable from each other. After edges 1-5 are deleted and the connected component index tree is maintained, the device topology is as shown in fig. 4, the connected component index tree is as shown in fig. 5, node V2 is the root node of the connected component index tree at this time, and the nearest common ancestor of device node 1 and device node 7 is node V2, so that the two devices are not reachable with each other.
In a preferred embodiment, as shown in fig. 6, after a graph model of physical connections of the grid devices is established and an initial connected component index tree is obtained, and before a nearest common ancestor node between two grid devices is searched according to the initial connected component index tree, the grid device reachability query method further includes:
step S3: when the graph model changes the topology, updating the initial connected component index tree to generate a connected component index tree after the topology is changed; and replacing the initial connected component index tree by the connected component index tree after the topology is changed.
Specifically, as shown in fig. 7, updating the initial connected component index tree mainly includes the following steps:
step S31: searching a currently running version along a directed edge representing topology change operation in the version diagram of the initial connected component index tree to obtain the connected component index tree after the topology is changed; when a version index node corresponding to a currently running version exists, the connected component index tree after the topology is changed is a connected component index tree taking the version index node as a root node; and when the version index node does not exist, establishing a newly added version graph, wherein the connected component index tree after the topology is changed is the corrected connected component index tree of the newly added node.
Further, the version graph is a directed acyclic graph, which has a unique source node and the source node is an initial version node, the directed edge represents an edge in the topology graph of the device through addition and deletion, and a version corresponding to a directed exit node of the version graph can be converted into a version corresponding to an entry node.
Specifically, in an embodiment, fig. 4 is a topology diagram formed by deleting edges 1-5 from the device topology diagram shown in fig. 2, and fig. 5 is a corresponding connected component index tree. Fig. 8 is version nodes of different versions of the power grid topology), each node in the graph represents one version of the device topology, and each directed edge represents a delete edge operation corresponding to a difference between the two versions. For example, the device network topology shown in fig. 2 corresponds to the V0 node in fig. 8, while the device network topology shown in fig. 4 corresponds to the V2 node in fig. 8.
Further, as shown in fig. 7, updating the initial connected component index tree further includes:
step S32: correcting the connected component index tree of the newly added node, including: and searching a corresponding subgraph of the nearest common ancestor node of the two power grid devices connected with the edge to be deleted in the newly added node connected component index tree, and performing depth-first search on a connected component index subtree of the corresponding subgraph to obtain the connected component index tree after the topology is changed.
Specifically, in one embodiment, as shown in fig. 8, V0 is the parent node of V2, and the connected component index tree corresponding to fig. 3 is the prototype tree of V2 version. If the nearest common ancestor of the node 1 and the node 5 is R, the reconstructed connected component index tree has the edge between the two sub-connected components a and B of R deleted, and the connected component tree of the V2 version is shown in fig. 5.
According to the graph database-based power grid equipment reachability query method, the reachability query function of the power grid equipment is achieved, and the reachability query efficiency is improved; and when the operation mode of the power grid system is changed, the new index information is generated by updating the initial connected component index tree to provide efficient reachability query, so that the adaptivity and the real-time performance of the reachability query method of the power grid equipment are improved.
Example 2
An embodiment of the present invention provides a grid device reachability query system based on a graph database, as shown in fig. 9A, including: the power grid equipment graph model building module 1 is used for building a graph model of physical connection of power grid equipment according to the topological connection relation of the power grid equipment to obtain an initial connected component index tree; the reachability detection module 2 is used for searching a nearest common ancestor node between the two power grid devices according to the initial connected component index tree and judging whether the nearest common ancestor node is a non-root node; and when the nearest common ancestor node is a non-root node, the two power grid devices are judged to be reachable.
The graph database-based power grid equipment reachability query system provided by the embodiment of the invention has the function of power grid equipment reachability query and improves reachability query efficiency.
In a preferred embodiment, when the reachability detection module 2 determines that the nearest common ancestor node is not a non-root node, it determines that the two grid devices are unreachable.
In a preferred embodiment, as shown in fig. 9B, the grid device reachability query system further includes: an initial connected component index tree updating module 3, configured to update the initial connected component index tree when the graph model changes topology, and generate a connected component index tree after topology is changed; and replacing the initial connected component index tree by the connected component index tree after the topology is changed.
Further, as shown in fig. 10, the initial connected component index tree updating module 3 includes: a topology-changed connected component index tree obtaining sub-module 31, configured to search a currently running version in the version map of the initial connected component index tree along a directed edge indicating a topology change operation, so as to obtain a topology-changed connected component index tree; when a version index node corresponding to a currently running version exists, the connected component index tree after the topology is changed is a connected component index tree taking the version index node as a root node; and when the version index node does not exist, establishing a newly added version graph, wherein the connected component index tree after the topology is changed is the corrected connected component index tree of the newly added node.
Further, as shown in fig. 10, the initial connected component index tree updating module 3 further includes: a modification submodule 32, configured to modify the connected component index tree of the newly added node; and searching a corresponding subgraph of the nearest common ancestor node of the edge to be deleted, which is connected with the two power grid devices, in the connected component index tree of the newly added node, and performing depth-first search on a connected component index subtree of the corresponding subgraph to obtain the connected component index tree after the topology is changed.
According to the graph database-based power grid equipment reachability query system, the reachability query function of the power grid equipment is achieved through the power grid equipment graph model building module 1 and the reachability detection module 2, the reachability query efficiency of the system is improved, and efficient reachability query can be provided when the operation mode of the power grid system is changed through the setting of the initial connected component index tree updating module 3, so that the adaptivity and the real-time performance of the power grid equipment reachability query system are improved.
Example 3
An embodiment of the present invention provides a non-transitory computer storage medium, where a computer-executable instruction is stored, and the computer-executable instruction may execute the graph database-based power grid device reachability query method in any embodiment 1 described above. The storage medium may be a magnetic Disk, an optical Disk, a Read-only Memory (ROM), a Random Access Memory (RAM), a flash Memory (FlashMemory), a Hard Disk (Hard Disk Drive, abbreviated as HDD) or a Solid State Drive (SSD), etc.; the storage medium may also comprise a combination of memories of the kind described above.
It will be understood by those skilled in the art that all or part of the processes of the methods of the embodiments described above can be implemented by hardware related to instructions of a computer program, and the program can be stored in a computer readable storage medium, and when executed, can include the processes of the embodiments of the methods described above. The storage medium may be a magnetic disk, an optical disk, a read-only memory (ROM), a Random Access Memory (RAM), or the like.
Example 4
An embodiment of the present invention provides an electronic device for executing a power grid device reachability query method, a schematic structural diagram of which is shown in fig. 11, where the electronic device includes: one or more processors 410 and a memory 420, with one processor 410 being an example in fig. 11.
The electronic device performing the power grid device reachability query method may further include: an input device 430 and an output device 440.
The processor 410, the memory 420, the input device 430, and the output device 440 may be connected by a bus or other means, as exemplified by the bus connection in fig. 11.
Processor 410 may be a Central Processing Unit (CPU). The Processor 410 may also be other general purpose processors, Digital Signal Processors (DSPs), Application Specific Integrated Circuits (ASICs), Field Programmable Gate Arrays (FPGAs) or other Programmable logic devices, discrete Gate or transistor logic devices, discrete hardware components, or combinations thereof. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
The memory 420 is a non-transitory computer readable storage medium, and can be used to store non-transitory software programs, non-transitory computer executable programs, and modules, such as program instructions/modules corresponding to the power grid device reachability query method in the embodiment of the present application, and the processor 410 executes various functional applications and data processing of the server by running the non-transitory software programs, instructions, and modules stored in the memory 420, that is, implementing the power grid device reachability query method in the above method embodiment.
The memory 420 may include a storage program area and a storage data area, wherein the storage program area may store an operating system, an application program required for at least one function; the storage data area may store data created from use of the processing device of the grid equipment reachability inquiry, and the like. Further, the memory 420 may include high speed random access memory, and may also include non-transitory memory, such as at least one magnetic disk storage device, flash memory device, or other non-transitory solid state storage device. In some embodiments, memory 420 may optionally include memory located remotely from processor 410, which may be connected to a grid device reachability query facility over a network. Examples of such networks include, but are not limited to, the internet, intranets, local area networks, mobile communication networks, and combinations thereof.
The input device 430 may receive input numeric or character information and generate key signal inputs related to user settings and function control of the processing device of the grid equipment reachability inquiry operation. The output device 440 may include a display device such as a display screen.
One or more modules are stored in the memory 420, which when executed by the one or more processors 410 perform the method shown in fig. 1.
The product can execute the method provided by the embodiment of the invention, and has corresponding functional modules and beneficial effects of the execution method. Details of the technique not described in detail in the present embodiment may be specifically referred to the relevant description in the embodiments shown in fig. 1 to 8.
It should be understood that the above examples are only for clarity of illustration and are not intended to limit the embodiments. Other variations and modifications will be apparent to persons skilled in the art in light of the above description. And are neither required nor exhaustive of all embodiments. And obvious variations or modifications therefrom are within the scope of the invention.