[go: up one dir, main page]

CN111309989A - Graph database-based shortest path query method and related equipment - Google Patents

Graph database-based shortest path query method and related equipment Download PDF

Info

Publication number
CN111309989A
CN111309989A CN202010090371.9A CN202010090371A CN111309989A CN 111309989 A CN111309989 A CN 111309989A CN 202010090371 A CN202010090371 A CN 202010090371A CN 111309989 A CN111309989 A CN 111309989A
Authority
CN
China
Prior art keywords
node
nodes
adjacent
queue
query
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202010090371.9A
Other languages
Chinese (zh)
Inventor
江佳宸
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Ping An Technology Shenzhen Co Ltd
Original Assignee
Ping An Technology Shenzhen Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Ping An Technology Shenzhen Co Ltd filed Critical Ping An Technology Shenzhen Co Ltd
Priority to CN202010090371.9A priority Critical patent/CN111309989A/en
Publication of CN111309989A publication Critical patent/CN111309989A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/90Details of database functions independent of the retrieved data types
    • G06F16/903Querying
    • G06F16/90335Query processing
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/90Details of database functions independent of the retrieved data types
    • G06F16/901Indexing; Data structures therefor; Storage structures
    • G06F16/9017Indexing; Data structures therefor; Storage structures using directory or table look-up
    • G06F16/902Indexing; Data structures therefor; Storage structures using directory or table look-up using more than one table in sequence, i.e. systems with three or more layers

Landscapes

  • Engineering & Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Data Mining & Analysis (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Software Systems (AREA)
  • Computational Linguistics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

本申请涉及大数据领域,本申请公开了一种基于图数据库的最短路径查询方法及相关设备,所述方法包括:创建队列,当获取到源节点及目标节点时,将所述源节点存放至所述队列中,查询与所述源节点相邻的所有其它节点,将所述所有相邻节点存放至所述队列中,依次遍历所述队列中的所有节点,查询与所述节点相邻的所有其它节点,并通过循环遍历查询与目标节点一致的相邻节点,由此获得最短路径。本申请通过对图数据库中各节点进行循环遍历检测获得相邻节点,并对相邻节点进行监控获得目标节点,以此获得最短路径,可以提高路径查询的速度和效率。

Figure 202010090371

The present application relates to the field of big data. The present application discloses a graph database-based shortest path query method and related equipment. The method includes: creating a queue, and when a source node and a target node are obtained, storing the source node in a In the queue, query all other nodes adjacent to the source node, store all the adjacent nodes in the queue, traverse all the nodes in the queue in turn, and query the nodes adjacent to the node. All other nodes, and query the adjacent nodes consistent with the target node through loop traversal, thereby obtaining the shortest path. In the present application, adjacent nodes are obtained by cyclic traversal detection of each node in the graph database, and target nodes are obtained by monitoring the adjacent nodes, so as to obtain the shortest path, which can improve the speed and efficiency of path query.

Figure 202010090371

Description

基于图数据库的最短路径查询方法及相关设备Shortest path query method and related equipment based on graph database

技术领域technical field

本申请涉及大数据领域,特别涉及一种基于图数据库的最短路径查询方法及相关设备。The present application relates to the field of big data, and in particular, to a shortest path query method and related equipment based on a graph database.

背景技术Background technique

关系网络是由数据巨大的节点和节点之间错综复杂的关系共同构成的网络结构。现实世界中,包含着各种类似的关系网络,例如社交网络、资金网络等。关系网络从数学的视角看,是一个有着复杂的拓扑结构特征的图。图数据库也称为面向/基于图的数据库,其基本含义是以图这种数据结构来存储和查询数据。图数据库中的主要元素是节点和边。在实际应用中,往往用节点来表示实体或者概念,而节点之间相连的边则用于表示节点(实体或概念)之间的关系。这种基于图的抽象结构易于表示复杂的关系数据,因此图数据库被广泛应用于关系网络。A relational network is a network structure composed of nodes with huge data and intricate relationships between nodes. In the real world, there are various similar relationship networks, such as social networks, financial networks, etc. From a mathematical point of view, a relational network is a graph with complex topological features. A graph database is also known as a graph-oriented/graph-based database, and its basic meaning is to store and query data as a graph as a data structure. The main elements in a graph database are nodes and edges. In practical applications, nodes are often used to represent entities or concepts, and edges connected between nodes are used to represent relationships between nodes (entities or concepts). This graph-based abstract structure is easy to represent complex relational data, so graph databases are widely used in relational networks.

在图数据库中,一种常用的查询是查找无权图中两点之间的最短路径。对于最短路径查询,传统的方法是使用广度优先遍历(BFS)算法,从其中一点出发查找最短路径,直到找到另一个点为止。超级节点指某个节点度数显著大于平均节点度数的节点。在实际的网络中,由于节点度数(边数)分布极度不均,广度优先遍历算法往往会导致大量不必要的计算,从而导致查询过程非常缓慢。In graph databases, a common query is to find the shortest path between two points in an unweighted graph. For the shortest path query, the traditional method is to use the breadth-first traversal (BFS) algorithm to find the shortest path from one point until another point is found. A super node refers to a node whose degree is significantly greater than the average node degree. In the actual network, due to the extremely uneven distribution of node degrees (edges), the breadth-first traversal algorithm often leads to a large number of unnecessary computations, resulting in a very slow query process.

发明内容SUMMARY OF THE INVENTION

本申请的目的在于针对现有技术的不足,提供一种基于图数据库的最短路径查询方法及相关设备,通过对图数据库中各节点的节点度数的检测以及在获取到新的节点后循环遍历检测,以此获得最短路径,可以提高路径查询的速度和效率。The purpose of this application is to provide a shortest path query method and related equipment based on a graph database in view of the deficiencies of the prior art. , so as to obtain the shortest path, which can improve the speed and efficiency of path query.

为达到上述目的,本申请的技术方案提供一种基于图数据库的最短路径查询方法及相关设备。In order to achieve the above purpose, the technical solution of the present application provides a shortest path query method and related equipment based on a graph database.

本申请公开了一种基于图数据库的最短路径查询方法,包括以下步骤:The present application discloses a shortest path query method based on a graph database, comprising the following steps:

创建队列,当获取到源节点及目标节点时,将所述源节点存放至所述队列中;Create a queue, and store the source node in the queue when the source node and the target node are obtained;

查询与所述源节点相邻的所有相邻节点,若所有相邻节点中任一相邻节点与所述目标节点一致,则结束本次查询,将所述与目标节点一致的相邻节点与所述源节点之间的路径设置为最短路径,若所有相邻节点中任一相邻节点与所述目标节点都不一致,则将所有相邻节点存放至所述队列中;Query all adjacent nodes adjacent to the source node, if any adjacent node in all adjacent nodes is consistent with the target node, end this query, and compare the adjacent nodes consistent with the target node with the target node. The path between the source nodes is set as the shortest path, and if any adjacent node in all adjacent nodes is inconsistent with the target node, then all adjacent nodes are stored in the queue;

依次遍历所述队列中的所有节点,查询与当前遍历的节点相邻的所有相邻节点,并对所有相邻节点进行监控,若监控到任一相邻节点与所述目标节点一致时,结束本次查询,将所述与目标节点一致的相邻节点与所述源节点之间的路径设置为最短路径,若所有相邻节点中任一相邻节点与所述目标节点都不一致,则将所有相邻节点存放至所述队列中,重复本步骤,直到在所述队列中查询到与当前遍历的目标节点一致的节点为止。Traverse all nodes in the queue in turn, query all adjacent nodes adjacent to the currently traversed node, and monitor all adjacent nodes. If any adjacent node is monitored to be consistent with the target node, end In this query, the path between the adjacent node consistent with the target node and the source node is set as the shortest path. If any adjacent node in all adjacent nodes is inconsistent with the target node, the All adjacent nodes are stored in the queue, and this step is repeated until a node consistent with the currently traversed target node is queried in the queue.

较佳地,所述查询与所述源节点相邻的所有其它节点,包括:Preferably, the query is performed on all other nodes adjacent to the source node, including:

预设节点度数阈值,所述节点度数阈值用于判定任一节点相邻的节点最大数;A preset node degree threshold, the node degree threshold is used to determine the maximum number of nodes adjacent to any node;

对查询的节点进行监控,若监控到当前查询的节点为源节点时,则查询与所述源节点相邻的所有其它节点,若监控到当前查询的节点为非源节点时,则将所述当前查询的节点的节点度数与所述节点度数阈值进行比较,若所述当前查询的节点的节点度数大于节点度数阈值,则丢弃所述当前查询的节点。Monitor the queried node, if the currently queried node is a source node, query all other nodes adjacent to the source node, and if the currently queried node is a non-source node, then The node degree of the currently queried node is compared with the node degree threshold, and if the node degree of the currently queried node is greater than the node degree threshold, the currently queried node is discarded.

较佳地,所述将所述源节点存放至所述队列中之后,包括:Preferably, after storing the source node in the queue, it includes:

将所述源节点的状态设置为未访问;setting the state of the source node to unvisited;

则查询与所述源节点相邻的所有其它节点之后,包括:Then after querying all other nodes adjacent to the source node, including:

将所述源节点的状态设置为已访问。Set the state of the source node to visited.

较佳地,所述若所有相邻节点中任一相邻节点与所述目标节点都不一致,则将所有相邻节点存放至所述队列中之后,包括:Preferably, if any adjacent node in all adjacent nodes is inconsistent with the target node, then all adjacent nodes are stored in the queue, including:

将所述队列中的所有相邻节点的状态设置为未访问。Set the status of all neighboring nodes in the queue to unvisited.

较佳地,所述依次遍历所述队列中的所有节点,查询与当前遍历的节点相邻的所有相邻节点,包括:Preferably, traversing all nodes in the queue in sequence, and querying all adjacent nodes adjacent to the currently traversed node, including:

依次检测所述队列中的所有节点,若所述队列中任一节点的状态为已访问时,则将所述节点从所述队列中删除;Detecting all nodes in the queue in turn, if the status of any node in the queue is visited, then delete the node from the queue;

若所述节点的状态为未访问时,则查询与所述节点相邻的所有相邻节点,当所述节点的所有相邻节点查询完毕后,将所述节点的状态设置为已访问。If the state of the node is not visited, all adjacent nodes adjacent to the node are queried, and when all adjacent nodes of the node are queried, the state of the node is set to visited.

较佳地,所述重复本步骤,直到在所述队列中查询到与当前遍历的目标节点一致的节点为止,包括:Preferably, the step is repeated until a node consistent with the currently traversed target node is queried in the queue, including:

监控所述队列的存储状态;monitoring the storage status of the queue;

若监控到所述队列中的节点为空,则结束本次查询,若监控到所述队列中的节点不为空,则重复本步骤,直到在相邻节点中查询与所述目标节点一致的节点为止。If it is monitored that the node in the queue is empty, the query ends. If it is monitored that the node in the queue is not empty, repeat this step until the adjacent nodes are queried for the same target node. up to the node.

较佳地,所述重复本步骤,直到在所述队列中查询到与当前遍历的目标节点一致的节点为止,包括:Preferably, the step is repeated until a node consistent with the currently traversed target node is queried in the queue, including:

预设节点跳数阈值,所述节点跳数阈值用于判定当前队列中的节点最大数;a preset node hop count threshold, where the node hop count threshold is used to determine the maximum number of nodes in the current queue;

监控队列中的节点总数,若队列中的节点总数大于所述节点跳数阈值,则结束本次查询,若队列中的节点总数小于等于所述节点跳数阈值,则重复本步骤,直到在相邻节点中查询与所述目标节点一致的节点为止。Monitor the total number of nodes in the queue. If the total number of nodes in the queue is greater than the node hop threshold, end the query. If the total number of nodes in the queue is less than or equal to the node hop threshold, repeat this step until the corresponding node hop threshold is reached. The neighbor nodes are queried for nodes that are consistent with the target node.

本申请还公开了一种基于图数据库的最短路径查询装置,所述装置包括:The present application also discloses a shortest path query device based on a graph database, the device comprising:

数据获取模块:设置为创建队列,当获取到源节点及目标节点时,将所述源节点存放至所述队列中;Data acquisition module: set to create a queue, when the source node and the target node are acquired, the source node is stored in the queue;

第一查询模块:设置为查询与所述源节点相邻的所有相邻节点,若所有相邻节点中任一相邻节点与所述目标节点一致,则结束本次查询,将所述与目标节点一致的相邻节点与所述源节点之间的路径设置为最短路径,若所有相邻节点中任一相邻节点与所述目标节点都不一致,则将所有相邻节点存放至所述队列中;The first query module: set to query all adjacent nodes adjacent to the source node, if any adjacent node in all adjacent nodes is consistent with the target node, end this query, and compare the adjacent nodes with the target node. The path between the adjacent node with the same node and the source node is set as the shortest path. If any adjacent node in all adjacent nodes is inconsistent with the target node, all adjacent nodes are stored in the queue. middle;

第二查询模块:设置为依次遍历所述队列中的所有节点,查询与当前遍历的节点相邻的所有相邻节点,并对所有相邻节点进行监控,若监控到任一相邻节点与所述目标节点一致时,结束本次查询,将所述与目标节点一致的相邻节点与所述源节点之间的路径设置为最短路径,若所有相邻节点中任一相邻节点与所述目标节点都不一致,则将所有相邻节点存放至所述队列中,重复本步骤,直到在所述队列中查询到与当前遍历的目标节点一致的节点为止。Second query module: set to traverse all nodes in the queue in sequence, query all adjacent nodes adjacent to the currently traversed node, and monitor all adjacent nodes. When the target node is consistent, end this query, and set the path between the adjacent node consistent with the target node and the source node as the shortest path, if any adjacent node in all adjacent nodes and the If the target nodes are inconsistent, all adjacent nodes are stored in the queue, and this step is repeated until a node consistent with the currently traversed target node is queried in the queue.

本申请还公开了一种计算机设备,所述计算机设备包括存储器和处理器,所述存储器中存储有计算机可读指令,所述计算机可读指令被一个或多个所述处理器执行时,使得一个或多个所述处理器执行上述所述查询方法的步骤。The present application also discloses a computer device, the computer device includes a memory and a processor, the memory stores computer-readable instructions, and when the computer-readable instructions are executed by one or more of the processors, cause One or more of the processors perform the steps of the query method described above.

本申请还公开了一种存储介质,所述存储介质可被处理器读写,所述存储介质存储有计算机指令,所述计算机可读指令被一个或多个处理器执行时,使得一个或多个处理器执行上述所述查询方法的步骤。The present application also discloses a storage medium that can be read and written by a processor, and the storage medium stores computer instructions that, when executed by one or more processors, cause one or more Each processor executes the steps of the query method described above.

本申请的有益效果是:本申请通过对图数据库中各节点进行循环遍历检测获得相邻节点,并对相邻节点进行监控获得目标节点,以此获得最短路径,可以提高路径查询的速度和效率。The beneficial effects of the present application are: the present application obtains adjacent nodes by performing cyclic traversal detection on each node in the graph database, and monitors the adjacent nodes to obtain the target node, thereby obtaining the shortest path, which can improve the speed and efficiency of path query .

附图说明Description of drawings

图1为本申请第一个实施例的一种基于图数据库的最短路径查询方法的流程示意图;1 is a schematic flowchart of a graph database-based shortest path query method according to the first embodiment of the application;

图2为本申请第二个实施例的一种基于图数据库的最短路径查询方法的流程示意图;2 is a schematic flowchart of a graph database-based shortest path query method according to a second embodiment of the application;

图3为本申请第三个实施例的一种基于图数据库的最短路径查询方法的流程示意图;3 is a schematic flowchart of a graph database-based shortest path query method according to a third embodiment of the application;

图4为本申请第四个实施例的一种基于图数据库的最短路径查询方法的流程示意图;4 is a schematic flowchart of a graph database-based shortest path query method according to a fourth embodiment of the present application;

图5为本申请第五个实施例的一种基于图数据库的最短路径查询方法的流程示意图;5 is a schematic flowchart of a method for querying the shortest path based on a graph database according to the fifth embodiment of the present application;

图6为本申请实施例的一种基于图数据库的最短路径查询装置结构示意图。FIG. 6 is a schematic structural diagram of a shortest path query apparatus based on a graph database according to an embodiment of the present application.

具体实施方式Detailed ways

为了使本申请的目的、技术方案及优点更加清楚明白,以下结合附图及实施例,对本申请进行进一步详细说明。应当理解,此处所描述的具体实施例仅仅用以解释本申请,并不用于限定本申请。In order to make the purpose, technical solutions and advantages of the present application more clearly understood, the present application will be described in further detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application, but not to limit the present application.

本技术领域技术人员可以理解,除非特意声明,这里使用的单数形式“一”、“一个”、“所述”和“该”也可包括复数形式。应该进一步理解的是,本申请的说明书中使用的措辞“包括”是指存在所述特征、整数、步骤、操作、元件和/或组件,但是并不排除存在或添加一个或多个其他特征、整数、步骤、操作、元件、组件和/或它们的组。It will be understood by those skilled in the art that the singular forms "a", "an", "the" and "the" as used herein can include the plural forms as well, unless expressly stated otherwise. It should be further understood that the word "comprising" used in the specification of this application refers to the presence of stated features, integers, steps, operations, elements and/or components, but does not preclude the presence or addition of one or more other features, Integers, steps, operations, elements, components and/or groups thereof.

本申请第一个实施例的一种基于图数据库的最短路径查询方法流程如图1所示,本实施例包括以下步骤:The flowchart of a graph database-based shortest path query method according to the first embodiment of the present application is shown in FIG. 1 , and this embodiment includes the following steps:

步骤s101,创建队列,当获取到源节点及目标节点时,将所述源节点存放至所述队列中;Step s101, creating a queue, and storing the source node in the queue when the source node and the target node are obtained;

具体的,当在一个图数据库中查询两点之间的最短距离时,首先要获取这两个节点的名称,例如节点A和节点B,并任意的将这两个节点设置为源节点和目标节点,由于只是计算节点A和节点B的最短距离,无论是节点A到节点B还是节点B到节点A,最短距离应该是唯一的,因此可以忽略方向性,例如,如果将节点A设置为源节点,那么节点B为目标节点,如果将节点B设置为源节点,那么节点A为目标节点。Specifically, when querying the shortest distance between two points in a graph database, first obtain the names of the two nodes, such as node A and node B, and arbitrarily set these two nodes as the source node and the target Node, since only the shortest distance between node A and node B is calculated, whether it is node A to node B or node B to node A, the shortest distance should be unique, so the directionality can be ignored, for example, if node A is set as the source node, then node B is the target node, if node B is set as the source node, then node A is the target node.

具体的,在获取源节点和目标节点之前还需设置一个队列,所述队列用于存储节点,所述存储的节点用于计算与之相邻的节点,将已经计算过的节点进行删除,并在所述相邻节点中再次计算与之相邻的节点,经过循环查询和计算,最终在相邻节点中查询到目标节点,在初始状态下,所述队列首次存储的是源节点,而通过对所述源节点的查询,可以获取与所述源节点相邻的节点。Specifically, before acquiring the source node and the target node, a queue needs to be set up, and the queue is used to store the nodes, and the stored nodes are used to calculate the adjacent nodes, delete the nodes that have been calculated, and In the adjacent nodes, the adjacent nodes are calculated again, and after cyclic query and calculation, the target node is finally queried in the adjacent nodes. In the initial state, the queue stores the source node for the first time, and through the By querying the source node, nodes adjacent to the source node can be obtained.

步骤s102,查询与所述源节点相邻的所有相邻节点,若所有相邻节点中任一相邻节点与所述目标节点一致,则结束本次查询,将所述与目标节点一致的相邻节点与所述源节点之间的路径设置为最短路径,若所有相邻节点中任一相邻节点与所述目标节点都不一致,则将所有相邻节点存放至所述队列中;Step s102, query all adjacent nodes adjacent to the source node, if any adjacent node in all adjacent nodes is consistent with the target node, end this query, and compare the adjacent nodes consistent with the target node. The path between the adjacent node and the source node is set as the shortest path, if any adjacent node in all adjacent nodes is inconsistent with the target node, then all adjacent nodes are stored in the queue;

具体的,根据所述队列中的源节点进行查询,获取到与所述源节点相邻的所有其它节点,这时可在所述相邻节点中进行比对,所述比对是将所述相邻节点的名称与目标节点的名称依次进行比对,当在依次比对过程中,如果有任何一个相邻节点的名称与所述目标节点的名称一致,那么本次查询结束,剩余的相邻节点停止与所述目标节点的比对,所述与目标节点名称一致的相邻节点与源节点之间的距离为最短路径,如果经过比对,相邻节点中的所有节点都与所述目标节点不一致,那么可将所述相邻节点都存放至所述队列中,等待下一轮的查询。Specifically, according to the source node in the queue, all other nodes adjacent to the source node are obtained, and then a comparison can be performed in the adjacent nodes, and the comparison is to compare the The names of adjacent nodes are compared with the names of the target nodes in turn. During the sequential comparison, if the name of any adjacent node is consistent with the name of the target node, the query ends, and the remaining The adjacent node stops the comparison with the target node, and the distance between the adjacent node whose name is consistent with the target node and the source node is the shortest path. If the target nodes are inconsistent, all the adjacent nodes can be stored in the queue to wait for the next round of query.

步骤s103,依次遍历所述队列中的所有节点,查询与当前遍历的节点相邻的所有相邻节点,并对所有相邻节点进行监控,若监控到任一相邻节点与所述目标节点一致时,结束本次查询,将所述与目标节点一致的相邻节点与所述源节点之间的路径设置为最短路径,若所有相邻节点中任一相邻节点与所述目标节点都不一致,则将所有相邻节点存放至所述队列中,重复本步骤,直到在所述队列中查询到与当前遍历的目标节点一致的节点为止。Step s103, traverse all the nodes in the queue in turn, query all adjacent nodes adjacent to the node currently traversed, and monitor all adjacent nodes, if any adjacent node is monitored to be consistent with the target node When the query ends, the path between the adjacent node that is consistent with the target node and the source node is set as the shortest path. If any adjacent node in all adjacent nodes is inconsistent with the target node , all adjacent nodes are stored in the queue, and this step is repeated until a node consistent with the currently traversed target node is queried in the queue.

具体的,当经过第一轮查询后,所述队列中存储的是源节点及与所述源节点相邻的节点,这时可对所述队列中的所有节点依次进行遍历查询,用以获得所有节点相邻的节点;例如,假设队列中有源节点A,与源节点A相邻的有节点C、节点D和节点E,那么依次查询节点A的相邻节点、节点C的相邻节点、节点D的相邻节点及节点E的相邻节点,在对所述相邻节点的查询过程中,可对所述相邻节点进行监控,如果监控到任一相邻节点与所述目标节点一致,那么就可结束本次查询,将所述与所述目标节点一致的相邻节点与所述源节点之间的路径设置为最短路径;例如,在对节点C的相邻节点的查询过程中如果查询到有一个节点与所述目标节点一致,则停止对节点D和节点E的查询;如果对队列中的所有节点遍历查询后,没有发现与所述目标节点一致的节点,这时可将当前查询到的所有相邻节点存储在所述队列中,并进行下一轮查询,通过对队列中的节点进行循环遍历,直到在相邻节点中查询得到与所述目标节点一致的节点为止。Specifically, after the first round of query, the source node and the nodes adjacent to the source node are stored in the queue. At this time, all nodes in the queue can be traversed and queried in turn to obtain Nodes adjacent to all nodes; for example, if there is source node A in the queue, and node C, node D, and node E are adjacent to source node A, then query the adjacent nodes of node A and the adjacent nodes of node C in turn , the adjacent node of node D and the adjacent node of node E, in the process of querying the adjacent node, the adjacent node can be monitored, if any adjacent node and the target node are monitored. is consistent, then the query can be ended, and the path between the adjacent node that is consistent with the target node and the source node is set as the shortest path; for example, in the query process of the adjacent nodes of node C If there is a node consistent with the target node in the query, stop querying node D and node E; if after traversing and querying all nodes in the queue, no node consistent with the target node is found, then you can Store all the adjacent nodes currently queried in the queue, and perform the next round of query, by traversing the nodes in the queue in a loop, until the adjacent nodes are queried to obtain a node consistent with the target node .

本实施例中,通过对图数据库中各节点进行循环遍历检测获得相邻节点,并对相邻节点进行监控获得目标节点,以此获得最短路径,可以提高路径查询的速度和效率。In this embodiment, adjacent nodes are obtained by cyclic traversal detection of each node in the graph database, and target nodes are obtained by monitoring adjacent nodes, thereby obtaining the shortest path, which can improve the speed and efficiency of path query.

图2为本申请第二个实施例的一种基于图数据库的最短路径查询方法流程示意图,如图所示,所述步骤s102,查询与所述源节点相邻的所有其它节点,包括:FIG. 2 is a schematic flowchart of a graph database-based shortest path query method according to the second embodiment of the present application. As shown in the figure, in step s102, query all other nodes adjacent to the source node, including:

步骤s201,预设节点度数阈值,所述节点度数阈值用于判定任一节点相邻的节点最大数;Step s201, preset a node degree threshold, and the node degree threshold is used to determine the maximum number of nodes adjacent to any node;

具体的,在对所述源节点进行查询前,可在系统中预设节点度数阈值,所述节点度数阈值用于判定任一节点相邻的节点最大数,所述节点度数指的是任意一个节点相关联的边数;当任一节点的节点度数大于所述阈值时,可跳过对所述节点的查询,由于节点度数越高,运算量越大,因此避免大量的运算导致降低效率。Specifically, before querying the source node, a node degree threshold can be preset in the system, and the node degree threshold is used to determine the maximum number of adjacent nodes to any node, and the node degree refers to any one The number of edges associated with the node; when the node degree of any node is greater than the threshold, the query for the node can be skipped. Since the higher the node degree, the greater the amount of operations, so avoiding a large number of operations and reducing efficiency.

步骤s202,对查询的节点进行监控,若监控到当前查询的节点为源节点时,则查询与所述源节点相邻的所有其它节点,若监控到当前查询的节点为非源节点时,则将所述当前查询的节点的节点度数与所述节点度数阈值进行比较,若所述当前查询的节点的节点度数大于节点度数阈值,则丢弃所述当前查询的节点。Step s202, monitor the queried node, if the currently queried node is a source node, query all other nodes adjacent to the source node, and if the currently queried node is a non-source node, then The node degree of the currently queried node is compared with the node degree threshold, and if the node degree of the currently queried node is greater than the node degree threshold, the currently queried node is discarded.

具体的,在对节点的查询过程中,可以对所述节点进行监控,如果当前查询的节点是源节点,由于源节点是起始节点,因此不用进行节点度数阈值的判断,因为无论判断结果如何,都要进行查询计算,这时可直接查询与所述源节点相邻的所有其它节点;而如果当前查询的节点不是源节点,这时就要将当前查询的节点的节点度数与所述节点度数阈值进行比较,如果所述当前查询的节点的节点度数大于所述节点度数阈值,则停止对当前节点的查询。Specifically, in the process of querying a node, the node can be monitored. If the node currently queried is the source node, since the source node is the starting node, there is no need to judge the node degree threshold, because no matter what the judgment result is In this case, all other nodes adjacent to the source node can be directly queried; and if the currently queried node is not the source node, then the node degree of the currently queried node must be compared with the node degree of the source node. The degree threshold is compared, and if the node degree of the node currently queried is greater than the node degree threshold, the query of the current node is stopped.

本实施例中,通过设置节点度数阈值,并对当前查询的节点的节点度数进行判定,可以避免大量的运算导致降低效率。In this embodiment, by setting a node degree threshold and determining the node degree of the node currently queried, it is possible to avoid a large number of operations and reduce efficiency.

在一个实施例中,所述步骤s101,将所述源节点存放至所述队列中之后,包括:In one embodiment, the step s101, after the source node is stored in the queue, includes:

将所述源节点的状态设置为未访问;setting the state of the source node to unvisited;

则查询与所述源节点相邻的所有其它节点之后,包括:Then after querying all other nodes adjacent to the source node, including:

将所述源节点的状态设置为已访问。Set the state of the source node to visited.

具体的,初始状态下所述队列中只有一个源节点,这时可将所述源节点的状态设置为未访问,而对所述源节点进行查询后,获得与所述源节点相邻的节点之后,可将所述源节点的状态设置为已访问,用以说明源节点已经查询过,通过后续对源节点状态的判定,可以不用再次查询,例如,在下一轮的查询中,如果发现源节点的状态是已访问,则不用对所述源节点再次查询,减少运算,提高查询效率。Specifically, in the initial state, there is only one source node in the queue, then the state of the source node can be set as unvisited, and after querying the source node, the nodes adjacent to the source node can be obtained. Afterwards, the state of the source node can be set as visited to indicate that the source node has already been queried. Through subsequent determination of the state of the source node, there is no need to query again. For example, in the next round of query, if the source node is found If the state of the node is visited, the source node does not need to be queried again, which reduces operations and improves query efficiency.

本实施例中,通过对源节点状态的设置,并在查询时对源节点进行状态判定,可以减少运算,提高查询效率。In this embodiment, by setting the state of the source node and determining the state of the source node when querying, the operation can be reduced and the query efficiency can be improved.

在一个实施例中,所述步骤s103,若所有相邻节点中任一相邻节点与所述目标节点都不一致,则将所有相邻节点存放至所述队列中之后,包括:In one embodiment, in the step s103, if any adjacent node among all adjacent nodes is inconsistent with the target node, after storing all adjacent nodes in the queue, the process includes:

将所述队列中的所有相邻节点的状态设置为未访问。Set the status of all neighboring nodes in the queue to unvisited.

具体的,当将与所述源节点相邻的所有相邻节点都存放至队列之后,还可将所述队列中的所有相邻节点的状态设置为未访问,用以和已访问的节点进行区分,以便下一轮进行查询时将已访问的节点进行排除,避免冗余查询,导致效率降低。Specifically, after all the adjacent nodes adjacent to the source node are stored in the queue, the state of all adjacent nodes in the queue can also be set to be unvisited, so as to communicate with the visited nodes. Differentiate, so that the visited nodes can be excluded in the next round of query to avoid redundant query, resulting in reduced efficiency.

本实施例中,通过对相邻节点的状态的设定,可将未访问的相邻节点与已访问的源节点进行区分,减少重复运算,提高查询效率。In this embodiment, by setting the states of adjacent nodes, the adjacent nodes that have not been visited can be distinguished from the source nodes that have been visited, so as to reduce repeated operations and improve query efficiency.

图3为本申请第三个实施例的一种基于图数据库的最短路径查询方法流程示意图,如图所示,所述步骤s103,依次遍历所述队列中的所有节点,查询与当前遍历的节点相邻的所有相邻节点,包括:FIG. 3 is a schematic flowchart of a method for querying the shortest path based on a graph database according to the third embodiment of the present application. As shown in the figure, in step s103, all nodes in the queue are traversed in sequence, and the query and the currently traversed node are traversed sequentially. All adjacent nodes, including:

步骤s301,依次检测所述队列中的所有节点,若所述队列中任一节点的状态为已访问时,则将所述节点从所述队列中删除;Step s301, sequentially detect all nodes in the queue, if the status of any node in the queue is visited, delete the node from the queue;

具体的,当对队列中的节点进行遍历查询时,首先检测所述节点的状态,如果所述队列中任一节点的状态为已访问时,则可将所述节点删除,对所述状态为已访问的节点不再进行查询。Specifically, when a traversal query is performed on a node in the queue, the state of the node is first detected. If the state of any node in the queue is visited, the node can be deleted, and the state of the node can be deleted. Nodes that have been visited are no longer queried.

步骤s302,若所述节点的状态为未访问时,则查询与所述节点相邻的所有相邻节点,当所述节点的所有相邻节点查询完毕后,将所述节点的状态设置为已访问。Step s302, if the state of the node is not visited, query all adjacent nodes adjacent to the node, and after the query of all adjacent nodes of the node is completed, set the state of the node to access.

具体的,对于状态为未访问的节点,则可以查询与所述节点相邻的所有其它节点,当对所述未访问的节点进行查询后,获得与所述未访问节点相邻的所有其它节点之后,可将所述为访问节点的状态设置为已访问。Specifically, for a node whose status is unvisited, all other nodes adjacent to the node can be queried, and after the unvisited node is queried, all other nodes adjacent to the unvisited node are obtained. Afterwards, the state of the visited node can be set to visited.

本实施例中,通过在队列中对节点的状态的判定,将状态为已访问的节点进行删除,可以减少重复运算,提高查询效率。In this embodiment, by judging the state of the node in the queue, the node whose state is visited is deleted, which can reduce repeated operations and improve query efficiency.

图4为本申请第四个实施例的一种基于图数据库的最短路径查询方法流程示意图,如图所示,所述步骤s103,重复本步骤,直到在所述队列中查询到与当前遍历的目标节点一致的节点为止,包括:4 is a schematic flowchart of a graph database-based shortest path query method according to the fourth embodiment of the application. As shown in the figure, in step s103, this step is repeated until a query that is related to the current traversal is found in the queue. Until the node with the same target node, including:

步骤s401,监控所述队列的存储状态;Step s401, monitoring the storage state of the queue;

具体的,还可监控所述队列的存储状态,当对队列中的节点进行查询前,通过监控可以获取到所述队列当前的存储状态,所述存储状态包括队列中是否还有节点,由于在对节点的查询过程中,对于已访问的节点都会删除,如果所有节点都已经删除,说明源节点和目标节点之间不连通,没有路径可供查询,因此可以输出无路径结果。Specifically, the storage status of the queue can also be monitored. Before querying the nodes in the queue, the current storage status of the queue can be obtained through monitoring. The storage status includes whether there are any nodes in the queue. In the process of querying nodes, the visited nodes will be deleted. If all nodes have been deleted, it means that the source node and the target node are not connected, and there is no path for querying, so the no-path result can be output.

步骤s402,若监控到所述队列中的节点为空,则结束本次查询,若监控到所述队列中的节点不为空,则重复本步骤,直到在相邻节点中查询与所述目标节点一致的节点为止。Step s402, if it is monitored that the node in the queue is empty, end this query, if it is monitored that the node in the queue is not empty, then repeat this step until the query is in the adjacent node and the target. until the node matches the node.

具体的,当监控到当前队列中没有任何节点时,这时可结束本次查询,说明源节点和目标节点之间不连通,没有路径可供查询,如果队列中的节点不为空,则继续重复本步骤,直到在相邻节点中查询与所述目标节点一致的节点为止。Specifically, when it is monitored that there are no nodes in the current queue, the query can be ended at this time, indicating that there is no connection between the source node and the target node, and there is no path to query. If the nodes in the queue are not empty, continue This step is repeated until a node consistent with the target node is queried among adjacent nodes.

本实施例中,通过检测队列中的存储状态,当队列的存储状态为空时,结束查询,可以减少无效运算,提高查询效率。In this embodiment, by detecting the storage state in the queue, when the storage state of the queue is empty, the query is ended, which can reduce invalid operations and improve query efficiency.

图5为本申请第五个实施例的一种基于图数据库的最短路径查询方法流程示意图,如图所示,所述步骤s103,重复本步骤,直到在所述队列中查询到与当前遍历的目标节点一致的节点为止,包括:FIG. 5 is a schematic flowchart of a method for querying the shortest path based on a graph database according to the fifth embodiment of the present application. As shown in the figure, in step s103, this step is repeated until a query related to the current traversal is found in the queue. Until the node with the same target node, including:

步骤s501,预设节点跳数阈值,所述节点跳数阈值用于判定当前队列中的节点最大数;Step s501, preset a node hop count threshold, and the node hop count threshold is used to determine the maximum number of nodes in the current queue;

具体的,还可预设节点跳数阈值,所述节点跳数阈值用于判定当前队列中的节点最大数。Specifically, a node hop count threshold may also be preset, and the node hop count threshold is used to determine the maximum number of nodes in the current queue.

步骤s502,监控队列中的节点总数,若队列中的节点总数大于所述节点跳数阈值,则结束本次查询,若队列中的节点总数小于等于所述节点跳数阈值,则重复本步骤,直到在相邻节点中查询与所述目标节点一致的节点为止。Step s502, monitor the total number of nodes in the queue, if the total number of nodes in the queue is greater than the node hop count threshold, end this query, if the total number of nodes in the queue is less than or equal to the node hop count threshold, repeat this step, Until a node that is consistent with the target node is queried among the adjacent nodes.

具体的,当对队列中的节点进行遍历查询前,还可监控队列中的节点总数,当通过监控发现当前队列中的节点总数大于所述节点跳数阈值时,由于节点数太多会导致运算量太大,查询效率很低,因此不适合继续查询,因此可以结束本次查询,如果队列中的节点总数小于等于所述节点跳数阈值,这时可以继续对队列中的节点进行遍历查询,并循环遍历查询步骤,直到在相邻节点中查询与所述目标节点一致的节点为止。Specifically, before performing a traversal query on the nodes in the queue, the total number of nodes in the queue can also be monitored. When it is found through monitoring that the total number of nodes in the current queue is greater than the node hop threshold, the number of nodes is too large. If the total number of nodes in the queue is less than or equal to the node hop threshold, then you can continue to traverse and query the nodes in the queue. And loop through the query steps until a node consistent with the target node is queried in the adjacent nodes.

本实施例中,通过对队列中的节点进行节点总数的判断,避免节点数过多导致的运算量过大,提高查询效率。In this embodiment, by judging the total number of nodes on the nodes in the queue, excessive computation load caused by too many nodes is avoided, and the query efficiency is improved.

本申请实施例的一种基于图数据库的最短路径查询装置结构如图6所示,包括:The structure of a graph database-based shortest path query device according to an embodiment of the present application is shown in FIG. 6 , including:

数据获取模块601、第一查询模块602及第二查询模块603;其中,数据获取模块601与第一查询模块602相连,第一查询模块602与第二查询模块603相连;数据获取模块601设置为创建队列,当获取到源节点及目标节点时,将所述源节点存放至所述队列中;第一查询模块602设置为查询与所述源节点相邻的所有相邻节点,若所有相邻节点中任一相邻节点与所述目标节点一致,则结束本次查询,将所述与目标节点一致的相邻节点与所述源节点之间的路径设置为最短路径,若所有相邻节点中任一相邻节点与所述目标节点都不一致,则将所有相邻节点存放至所述队列中;第二查询模块603设置为依次遍历所述队列中的所有节点,查询与当前遍历的节点相邻的所有相邻节点,并对所有相邻节点进行监控,若监控到任一相邻节点与所述目标节点一致时,结束本次查询,将所述与目标节点一致的相邻节点与所述源节点之间的路径设置为最短路径,若所有相邻节点中任一相邻节点与所述目标节点都不一致,则将所有相邻节点存放至所述队列中,重复本步骤,直到在所述队列中查询到与当前遍历的目标节点一致的节点为止。Data acquisition module 601, first query module 602 and second query module 603; wherein, the data acquisition module 601 is connected with the first query module 602, and the first query module 602 is connected with the second query module 603; the data acquisition module 601 is set to Create a queue, and store the source node in the queue when the source node and the target node are obtained; the first query module 602 is set to query all adjacent nodes adjacent to the source node, if all adjacent nodes are adjacent Any adjacent node in the node is consistent with the target node, then end the query, and set the path between the adjacent node consistent with the target node and the source node as the shortest path, if all adjacent nodes If any adjacent node is inconsistent with the target node, all adjacent nodes are stored in the queue; the second query module 603 is set to traverse all the nodes in the queue in turn, and query and the currently traversed node All adjacent nodes are adjacent, and all adjacent nodes are monitored. If any adjacent node is monitored to be consistent with the target node, the query ends, and the adjacent node consistent with the target node is compared with the target node. The path between the source nodes is set as the shortest path, if any adjacent node in all adjacent nodes is inconsistent with the target node, then all adjacent nodes are stored in the queue, and this step is repeated until The queue is queried until a node consistent with the currently traversed target node is found.

本申请实施例还公开了一种计算机设备,所述计算机设备包括存储器和处理器,所述存储器中存储有计算机可读指令,所述计算机可读指令被一个或多个所述处理器执行时,使得一个或多个所述处理器执行上述各实施例中所述查询方法中的步骤。An embodiment of the present application further discloses a computer device, the computer device includes a memory and a processor, the memory stores computer-readable instructions, and when the computer-readable instructions are executed by one or more of the processors , causing one or more of the processors to execute the steps in the query methods described in the foregoing embodiments.

本申请实施例还公开了一种存储介质,所述存储介质可被处理器读写,所述存储器存储有计算机可读指令,所述计算机可读指令被一个或多个处理器执行时,使得一个或多个处理器执行上述各实施例中所述查询方法中的步骤。The embodiment of the present application further discloses a storage medium, the storage medium can be read and written by a processor, the memory stores computer-readable instructions, and when the computer-readable instructions are executed by one or more processors, causes One or more processors execute the steps in the query methods described in the above embodiments.

本领域普通技术人员可以理解实现上述实施例方法中的全部或部分流程,是可以通过计算机程序来指令相关的硬件来完成,该计算机程序可存储于一计算机可读取存储介质中,该程序在执行时,可包括如上述各方法的实施例的流程。其中,前述的存储介质可为磁碟、光盘、只读存储记忆体(Read-Only Memory,ROM)等非易失性存储介质,或随机存储记忆体(Random Access Memory,RAM)等。Those of ordinary skill in the art can understand that the realization of all or part of the processes in the methods of the above embodiments can be accomplished by instructing relevant hardware through a computer program, and the computer program can be stored in a computer-readable storage medium, and the program is During execution, it may include the processes of the embodiments of the above-mentioned methods. The aforementioned storage medium may be a non-volatile storage medium such as a magnetic disk, an optical disk, a read-only memory (Read-Only Memory, ROM), or a random access memory (Random Access Memory, RAM).

以上所述实施例的各技术特征可以进行任意的组合,为使描述简洁,未对上述实施例中的各个技术特征所有可能的组合都进行描述,然而,只要这些技术特征的组合不存在矛盾,都应当认为是本说明书记载的范围。The technical features of the above-described embodiments can be combined arbitrarily. For the sake of brevity, all possible combinations of the technical features in the above-described embodiments are not described. However, as long as there is no contradiction between the combinations of these technical features, All should be regarded as the scope described in this specification.

以上所述实施例仅表达了本申请的几种实施方式,其描述较为具体和详细,但并不能因此而理解为对本申请专利范围的限制。应当指出的是,对于本领域的普通技术人员来说,在不脱离本申请构思的前提下,还可以做出若干变形和改进,这些都属于本申请的保护范围。因此,本申请专利的保护范围应以所附权利要求为准。The above-mentioned embodiments only represent several embodiments of the present application, and the descriptions thereof are relatively specific and detailed, but should not be construed as a limitation on the scope of the patent of the present application. It should be noted that, for those skilled in the art, without departing from the concept of the present application, several modifications and improvements can be made, which all belong to the protection scope of the present application. Therefore, the scope of protection of the patent of the present application shall be subject to the appended claims.

Claims (10)

1.一种基于图数据库的最短路径查询方法,其特征在于,包括以下步骤:1. a shortest path query method based on graph database, is characterized in that, comprises the following steps: 创建队列,当获取到源节点及目标节点时,将所述源节点存放至所述队列中;Create a queue, and store the source node in the queue when the source node and the target node are obtained; 查询与所述源节点相邻的所有相邻节点,若所有相邻节点中任一相邻节点与所述目标节点一致,则结束本次查询,将所述与目标节点一致的相邻节点与所述源节点之间的路径设置为最短路径,若所有相邻节点中任一相邻节点与所述目标节点都不一致,则将所有相邻节点存放至所述队列中;Query all adjacent nodes adjacent to the source node, if any adjacent node in all adjacent nodes is consistent with the target node, end this query, and compare the adjacent nodes consistent with the target node with the target node. The path between the source nodes is set as the shortest path, and if any adjacent node in all adjacent nodes is inconsistent with the target node, then all adjacent nodes are stored in the queue; 依次遍历所述队列中的所有节点,查询与当前遍历的节点相邻的所有相邻节点,并对所有相邻节点进行监控,若监控到任一相邻节点与所述目标节点一致时,结束本次查询,将所述与目标节点一致的相邻节点与所述源节点之间的路径设置为最短路径,若所有相邻节点中任一相邻节点与所述目标节点都不一致,则将所有相邻节点存放至所述队列中,重复本步骤,直到在所述队列中查询到与当前遍历的目标节点一致的节点为止。Traverse all nodes in the queue in turn, query all adjacent nodes adjacent to the currently traversed node, and monitor all adjacent nodes. If any adjacent node is monitored to be consistent with the target node, end In this query, the path between the adjacent node consistent with the target node and the source node is set as the shortest path. If any adjacent node in all adjacent nodes is inconsistent with the target node, the All adjacent nodes are stored in the queue, and this step is repeated until a node consistent with the currently traversed target node is queried in the queue. 2.如权利要求1所述的基于图数据库的最短路径查询方法,其特征在于,所述查询与所述源节点相邻的所有其它节点,包括:2. The shortest path query method based on a graph database as claimed in claim 1, wherein the querying all other nodes adjacent to the source node comprises: 预设节点度数阈值,所述节点度数阈值用于判定任一节点相邻的节点最大数;A preset node degree threshold, the node degree threshold is used to determine the maximum number of nodes adjacent to any node; 对查询的节点进行监控,若监控到当前查询的节点为源节点时,则查询与所述源节点相邻的所有其它节点,若监控到当前查询的节点为非源节点时,则将所述当前查询的节点的节点度数与所述节点度数阈值进行比较,若所述当前查询的节点的节点度数大于节点度数阈值,则丢弃所述当前查询的节点。Monitor the queried node, if the currently queried node is a source node, query all other nodes adjacent to the source node, and if the currently queried node is a non-source node, then The node degree of the currently queried node is compared with the node degree threshold, and if the node degree of the currently queried node is greater than the node degree threshold, the currently queried node is discarded. 3.如权利要求2所述的基于图数据库的最短路径查询方法,其特征在于,所述将所述源节点存放至所述队列中之后,包括:3. The shortest path query method based on a graph database according to claim 2, wherein after the source node is stored in the queue, the method comprises: 将所述源节点的状态设置为未访问;setting the state of the source node to unvisited; 在查询与所述源节点相邻的所有其它节点之后,包括:After querying all other nodes adjacent to the source node, including: 将所述源节点的状态设置为已访问。Set the state of the source node to visited. 4.如权利要求3所述的基于图数据库的最短路径查询方法,其特征在于,所述若所有相邻节点中任一相邻节点与所述目标节点都不一致,则将所有相邻节点存放至所述队列中之后,包括:4. the shortest path query method based on graph database as claimed in claim 3, is characterized in that, described if any adjacent node in all adjacent nodes is inconsistent with described target node, then all adjacent nodes are stored After entering the queue, including: 将所述队列中的所有相邻节点的状态设置为未访问。Set the status of all neighboring nodes in the queue to unvisited. 5.如权利要求4所述的基于图数据库的最短路径查询方法,其特征在于,所述依次遍历所述队列中的所有节点,查询与当前遍历的节点相邻的所有相邻节点,包括:5. The shortest path query method based on a graph database as claimed in claim 4, characterized in that, said traversing all the nodes in the queue successively, and querying all adjacent nodes adjacent to the currently traversed node, comprising: 依次检测所述队列中的所有节点,若所述队列中任一节点的状态为已访问时,则将所述节点从所述队列中删除;Detecting all nodes in the queue in turn, if the status of any node in the queue is visited, then delete the node from the queue; 若所述节点的状态为未访问时,则查询与所述节点相邻的所有相邻节点,当所述节点的所有相邻节点查询完毕后,将所述节点的状态设置为已访问。If the state of the node is not visited, all adjacent nodes adjacent to the node are queried, and when all adjacent nodes of the node are queried, the state of the node is set to visited. 6.如权利要求5所述的基于图数据库的最短路径查询方法,其特征在于,所述重复本步骤,直到在所述队列中查询到与当前遍历的目标节点一致的节点为止,包括:6. The shortest path query method based on a graph database as claimed in claim 5, wherein the step is repeated until a node consistent with the current traversed target node is queried in the queue, comprising: 监控所述队列的存储状态;monitoring the storage status of the queue; 若监控到所述队列中的节点为空,则结束本次查询,若监控到所述队列中的节点不为空,则重复本步骤,直到在相邻节点中查询到与所述目标节点一致的节点为止。If it is detected that the node in the queue is empty, the query ends, and if the node in the queue is monitored to be not empty, repeat this step until the adjacent nodes are queried that are consistent with the target node up to the node. 7.如权利要求5所述的基于图数据库的最短路径查询方法,其特征在于,所述重复本步骤,直到在所述队列中查询到与当前遍历的目标节点一致的节点为止,包括:7. The shortest path query method based on a graph database as claimed in claim 5, wherein the step is repeated until a node consistent with the current traversed target node is queried in the queue, comprising: 预设节点跳数阈值,所述节点跳数阈值用于判定当前队列中的节点最大数;a preset node hop count threshold, where the node hop count threshold is used to determine the maximum number of nodes in the current queue; 监控队列中的节点总数,若队列中的节点总数大于所述节点跳数阈值,则结束本次查询,若队列中的节点总数小于等于所述节点跳数阈值,则重复本步骤,直到在相邻节点中查询到与所述目标节点一致的节点为止。Monitor the total number of nodes in the queue. If the total number of nodes in the queue is greater than the node hop threshold, end the query. If the total number of nodes in the queue is less than or equal to the node hop threshold, repeat this step until the corresponding node hop threshold is reached. The neighbor nodes are queried until a node consistent with the target node is found. 8.一种基于图数据库的最短路径查询装置,其特征在于,所述装置包括:8. A shortest path query device based on a graph database, wherein the device comprises: 数据获取模块:设置为创建队列,当获取到源节点及目标节点时,将所述源节点存放至所述队列中;Data acquisition module: set to create a queue, when the source node and the target node are acquired, the source node is stored in the queue; 第一查询模块:设置为查询与所述源节点相邻的所有相邻节点,若所有相邻节点中任一相邻节点与所述目标节点一致,则结束本次查询,将所述与目标节点一致的相邻节点与所述源节点之间的路径设置为最短路径,若所有相邻节点中任一相邻节点与所述目标节点都不一致,则将所有相邻节点存放至所述队列中;The first query module: set to query all adjacent nodes adjacent to the source node, if any adjacent node in all adjacent nodes is consistent with the target node, end this query, and compare the adjacent nodes with the target node. The path between the adjacent node with the same node and the source node is set as the shortest path. If any adjacent node in all adjacent nodes is inconsistent with the target node, all adjacent nodes are stored in the queue. middle; 第二查询模块:设置为依次遍历所述队列中的所有节点,查询与当前遍历的节点相邻的所有相邻节点,并对所有相邻节点进行监控,若监控到任一相邻节点与所述目标节点一致时,结束本次查询,将所述与目标节点一致的相邻节点与所述源节点之间的路径设置为最短路径,若所有相邻节点中任一相邻节点与所述目标节点都不一致,则将所有相邻节点存放至所述队列中,重复本步骤,直到在所述队列中查询到与当前遍历的目标节点一致的节点为止。Second query module: set to traverse all nodes in the queue in sequence, query all adjacent nodes adjacent to the currently traversed node, and monitor all adjacent nodes. When the target node is consistent, end this query, and set the path between the adjacent node consistent with the target node and the source node as the shortest path, if any adjacent node in all adjacent nodes and the If the target nodes are inconsistent, all adjacent nodes are stored in the queue, and this step is repeated until a node consistent with the currently traversed target node is queried in the queue. 9.一种计算机设备,其特征在于,所述计算机设备包括存储器和处理器,所述存储器中存储有计算机可读指令,所述计算机可读指令被一个或多个所述处理器执行时,使得一个或多个所述处理器执行如权利要求1至7中任一项所述查询方法的步骤。9. A computer device, characterized in that the computer device comprises a memory and a processor, wherein computer-readable instructions are stored in the memory, and when the computer-readable instructions are executed by one or more of the processors, One or more of the processors are caused to perform the steps of the query method of any one of claims 1 to 7. 10.一种存储介质,其特征在于,所述存储介质可被处理器读写,所述存储介质存储有计算机指令,所述计算机可读指令被一个或多个处理器执行时,使得一个或多个处理器执行如权利要求1至7中任一项所述查询方法的步骤。10. A storage medium, characterized in that, the storage medium can be read and written by a processor, and the storage medium stores computer instructions that, when executed by one or more processors, cause one or more A plurality of processors execute the steps of the query method according to any one of claims 1 to 7.
CN202010090371.9A 2020-02-13 2020-02-13 Graph database-based shortest path query method and related equipment Pending CN111309989A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010090371.9A CN111309989A (en) 2020-02-13 2020-02-13 Graph database-based shortest path query method and related equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010090371.9A CN111309989A (en) 2020-02-13 2020-02-13 Graph database-based shortest path query method and related equipment

Publications (1)

Publication Number Publication Date
CN111309989A true CN111309989A (en) 2020-06-19

Family

ID=71159958

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010090371.9A Pending CN111309989A (en) 2020-02-13 2020-02-13 Graph database-based shortest path query method and related equipment

Country Status (1)

Country Link
CN (1) CN111309989A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113220945A (en) * 2021-04-28 2021-08-06 广州宸祺出行科技有限公司 Method and system for field retrieval and path display of data blood margin
CN117371634A (en) * 2023-10-27 2024-01-09 东风汽车股份有限公司 Path planning method, device, equipment and computer readable storage medium

Citations (13)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20130103671A1 (en) * 2011-10-24 2013-04-25 Konstantin Tretjakov Processing Search Queries In A Network Of Interconnected Nodes
CN104392010A (en) * 2014-12-23 2015-03-04 北京理工大学 Subgraph matching query method
WO2015077940A1 (en) * 2013-11-27 2015-06-04 华为技术有限公司 Sink node routing method and node device
CN105260828A (en) * 2015-09-25 2016-01-20 量子数聚(北京)科技有限公司 Genetic relation processing method and system between enterprises
CN108123827A (en) * 2017-11-09 2018-06-05 浙江万里学院 Large Scale Graphs method for searching shortest route based on level cohesion
CN108595603A (en) * 2018-04-20 2018-09-28 北京费马科技有限公司 Inquiry is without the method for point-to-point transmission shortest path and application in weight graph in chart database
CN109344208A (en) * 2018-08-14 2019-02-15 北京奇虎科技有限公司 Route query method, device and electronic device
CN109460491A (en) * 2018-10-19 2019-03-12 中山大学 Timing shortest path query method based on Neo4j database
CN109634987A (en) * 2018-11-22 2019-04-16 全球能源互联网研究院有限公司 The querying method and device of power grid chart database
CN109670049A (en) * 2018-11-19 2019-04-23 平安科技(深圳)有限公司 Map path query method, apparatus, computer equipment and storage medium
CN109743252A (en) * 2018-12-25 2019-05-10 广州供电局有限公司 Generation method, device, computer equipment and the storage medium in grid switching operation path
CN110472789A (en) * 2019-08-15 2019-11-19 国网甘肃省电力公司信息通信公司 A kind of logistics distribution shortest path first solved based on Grobner bases
CN110768899A (en) * 2019-11-05 2020-02-07 厦门亿联网络技术股份有限公司 Shortest path determination method and device, storage medium and electronic device

Patent Citations (13)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20130103671A1 (en) * 2011-10-24 2013-04-25 Konstantin Tretjakov Processing Search Queries In A Network Of Interconnected Nodes
WO2015077940A1 (en) * 2013-11-27 2015-06-04 华为技术有限公司 Sink node routing method and node device
CN104392010A (en) * 2014-12-23 2015-03-04 北京理工大学 Subgraph matching query method
CN105260828A (en) * 2015-09-25 2016-01-20 量子数聚(北京)科技有限公司 Genetic relation processing method and system between enterprises
CN108123827A (en) * 2017-11-09 2018-06-05 浙江万里学院 Large Scale Graphs method for searching shortest route based on level cohesion
CN108595603A (en) * 2018-04-20 2018-09-28 北京费马科技有限公司 Inquiry is without the method for point-to-point transmission shortest path and application in weight graph in chart database
CN109344208A (en) * 2018-08-14 2019-02-15 北京奇虎科技有限公司 Route query method, device and electronic device
CN109460491A (en) * 2018-10-19 2019-03-12 中山大学 Timing shortest path query method based on Neo4j database
CN109670049A (en) * 2018-11-19 2019-04-23 平安科技(深圳)有限公司 Map path query method, apparatus, computer equipment and storage medium
CN109634987A (en) * 2018-11-22 2019-04-16 全球能源互联网研究院有限公司 The querying method and device of power grid chart database
CN109743252A (en) * 2018-12-25 2019-05-10 广州供电局有限公司 Generation method, device, computer equipment and the storage medium in grid switching operation path
CN110472789A (en) * 2019-08-15 2019-11-19 国网甘肃省电力公司信息通信公司 A kind of logistics distribution shortest path first solved based on Grobner bases
CN110768899A (en) * 2019-11-05 2020-02-07 厦门亿联网络技术股份有限公司 Shortest path determination method and device, storage medium and electronic device

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
刘扬俊: "图的广度优先遍历和最短路径算法", pages 1 - 6, Retrieved from the Internet <URL:https://blog.csdn.net/qq_19782019/article/details/82659964?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522170713920116800186543538%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fall.%2522%257D&request_id=170713920116800186543538&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~first_rank_ecpm_v1~rank_v31_ecpm-1-82659964-null-null.142^v99^pc_search_result_base5&utm_term=图的广度优先遍历和最短路径算法%20刘俊扬&spm=1018.2226.3001.4187> *
杨晓光: "基于复杂网络的社区发现算法", 南京理工大学学报, vol. 40, no. 3, 30 June 2016 (2016-06-30), pages 1 - 5 *

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113220945A (en) * 2021-04-28 2021-08-06 广州宸祺出行科技有限公司 Method and system for field retrieval and path display of data blood margin
CN113220945B (en) * 2021-04-28 2024-05-31 广州宸祺出行科技有限公司 Method and system for field retrieval and path display of data blood edges
CN117371634A (en) * 2023-10-27 2024-01-09 东风汽车股份有限公司 Path planning method, device, equipment and computer readable storage medium

Similar Documents

Publication Publication Date Title
CN108768745B (en) A Cluster System Fragility Evaluation Method Based on Complex Networks
JP5797855B2 (en) Virus scanning method and virus scanning apparatus
CN109522428B (en) An external memory access method for graph computing system based on index positioning
CN111309989A (en) Graph database-based shortest path query method and related equipment
CN108959072A (en) A kind of group system elasticity assessment method based on complex network
CN104298541A (en) Data distribution algorithm and data distribution device for cloud storage system
CN102025563A (en) Network flow identification method based on Hash collision compensation
CN113992541B (en) Network flow measuring method, system, computer equipment, storage medium and application
CN111651641A (en) Graph query method, device and storage medium
CN112988892B (en) A method for managing hotspot data in a distributed system
CN106301868A (en) The method and apparatus determining the importance of network node
CN115665174B (en) A method, system, device and storage medium for synchronizing gradient data
CN115049103A (en) Parallel graph traversal method facing single-source shortest path
CN115049493A (en) Block chain data tracking method and device and electronic equipment
CN114926597A (en) Road element modeling method and system of military chess map
CN111078963B (en) Conversion method and device from NFA to DFA
CN110719191A (en) A Network Reliability Assessment Method for Secondary Failures
CN113392143B (en) A Construction and Processing Method of Reachability Query Index Oriented to Multi-Relational Graph
CN108334559A (en) Graph data processing method and device
CN115119241A (en) Wireless sensor network link fault detection method
CN116366538A (en) Path update and equivalent path planning method and related device in dynamic network
CN102750263B (en) Method for simplifying hyperlink network chart data of Internet
JP2022033195A5 (en)
CN116437414A (en) Route planning method, terminal and storage medium
CN119356985B (en) Database abnormality monitoring and processing method, device and medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
RJ01 Rejection of invention patent application after publication
RJ01 Rejection of invention patent application after publication

Application publication date: 20200619