QuickGraph - 是否有算法可以找到一组顶点的所有父级(直到根顶点)
在 QuickGraph 中 - 是否有算法可以查找一组顶点的所有父级(直到根顶点)。换句话说,所有顶点的下方某处(在通往叶节点的路上)都有一个或多个顶点输入。因此,如果顶点是节点,边是依赖关系,则找到将受给定节点集影响的所有节点。
如果不是的话,编写自己的算法有多难?
In QuickGraph - is there algorithm for find all parents (up to root vertex's) of a set of vertex's. In other words all vertex's which have somewhere under them (on the way to the leaf nodes) one or more of the vertexs input. So if the vertexs were Nodes, and the edges were a depends on relationship, find all nodes that would be impacted by a given set of nodes.
If not how hard is it to write one's own algorithms?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
以下是我在给定顶点上完成前驱搜索的方法:
请注意,如果您事先知道根,则可以在 dfs.Compute() 方法中指定它(即 dfs .计算(0))。
-道格
Here's what I've used to accomplish a predecessor search on a given vertex:
Note that if you know your root beforehand, you can specify it in the
dfs.Compute()
method (i.e.dfs.Compute(0)
).-Doug
您要么需要维护一个反转图,要么在该图上创建一个反转每个边的包装器。
QuickGraph 具有 ReversedBi DirectionGraph 类,它是专门用于此目的的包装器,但由于泛型类型不兼容,它似乎无法与算法类一起使用。
我必须创建自己的包装器类:
然后在此包装器上运行 DFS 或 BFS:
Doug 的答案不正确,因为 DFS 只会访问下游子图。前任观察者没有帮助。
You either need to maintain a reversed graph, or create a wrapper over the graph that reverses every edge.
QuickGraph has the ReversedBidirectionalGraph class that is a wrapper intended just for that, but it does not seem to work with the algorithm classes because of generic type incompatibility.
I had to create my own wrapper class:
Then run DFS or BFS on this wrapper:
Doug's answer is not correct, because DFS will only visit the downstream subgraph. The predecessor observer does not help.
我使用了Doug的答案,发现如果一个顶点有多个父级,他的解决方案只提供其中一个父级。我不知道为什么。
因此,我创建了自己的版本,如下所示:
I used Doug's answer and found out that if there are more than one parent for a vertex, his solution only provides one of the parents. I am not sure why.
So, I created my own version which is as follows: