这些表将是Node(NodeID) INT)和Edge(EdgeID INT,NodeID1 INT,NodeID2 INT)
在有向图中寻找循环的性能良好的解决方案是什么? b $ b
解决方案解决方案结果非常简单明了,但稍微长一点: 生成所有通过图的路径的列表,使得没有路径多于一次包含相同的边。
从这些信息中,我们获取开始的路径列表并在同一个节点结束。
从这个最终边的列表中,我们根据前两步的计算重新构建所有循环的路径。
我发布了 TSQL 在我的博客上。
There are already a couple of questions on finding cycles, but I did not find a solution in SQL (MSSQL preferred).
The tables would be Node (NodeID INT) and Edge (EdgeID INT, NodeID1 INT, NodeID2 INT)
What would be a well-performing solution to find cycles in a directed graph?
解决方案The solution turned out quite simple and straightforward, but a bit longer:
First the list of all paths through the graph is generated, such that no path contains the same edge more than once.
From this information, we take the list of paths that start and end in the same node.
From this list of "final" edges we reconstruct all paths with cycles based on the calculation of the previous two steps.
I posted the complete solution in TSQL on my blog.
更多推荐
使用SQL查找有向图中的周期
发布评论