找到两个图节点之间的所有路径 [英] Find all paths between two graph nodes
问题描述
我的工作Dijkstras算法的implemtation检索路线在网络上相互连接的节点之间的最短路径。我有implentation工作。它返回所有的最短路径给所有当我通过起始节点到算法中的节点。
I am working on an implemtation of Dijkstras Algorithm to retrieve the shortest path between interconnected nodes on a network of routes. I have the implentation working. It returns all the shortest paths to all the nodes when I pass the start node into the algorithm.
我的提问: 如何去有关检索从节点A的所有可能路径要说节点G或从节点A甚至所有可能的路径,并返回到节点A
My Question: How does one go about retrieving all possible paths from Node A to say Node G or even all possible paths from Node A and back to Node A
推荐答案
查找所有可能的路径是一个很难的问题,因为有简单的路径指数数。即使找到第k最短路径[或最长路径]有 NP难。
Finding all possible paths is a hard problem, since there are exponential number of simple paths. Even finding the kth shortest path [or longest path] are NP-Hard.
一个可能的解决您的所有路径[或所有路径达到一定长度] 取值
到 T
是 BFS 的,不保持一个访问
设置,或加权版本 - 你可能需要使用统一成本搜索
One possible solution to find all paths [or all paths up to a certain length] from s
to t
is BFS, without keeping a visited
set, or for the weighted version - you might want to use uniform cost search
注意,还具有周期每图形[它不是一个 DAG 的]可能存在的路径无限多在取值
到 T
。
Note that also in every graph which has cycles [it is not a DAG] there might be infinite number of paths between s
to t
.
这篇关于找到两个图节点之间的所有路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!