创建无向图并在 QuickGraph 中使用 BFS 遍历它
我试图弄清楚如何使用 QuickGraph for C# 创建无向加权图的新实例。
我的目标是创建一个无向加权图,其中填充了随机数量的节点以及随机生成的起始和结束节点,其最短路径可以使用广度优先搜索算法找到。
文档内容不多,因此如果有人可以提供任何帮助,我们将不胜感激。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Richard,QuickGraph 不会为您执行任何操作,它只会提供您可以订阅的事件。通过订阅这些事件,您可以做出相应的回应。来自公认缺乏深度优先搜索的 QuickGraph 文档(是的,我知道你正在执行 BFS 而不是 DFS,但如何订阅事件的概念是相同的):
顺便说一下,打开 Reflector 并查看 QuickGraph.Algorithms.Observers。使用与 BFS 不同的方法,您的最短路径要求会更容易。
Richard, QuickGraph does not do any of this for you, it only makes events available which you can subscribe to. By subscribing to those events you can respond accordingly. From the admittedly lacking QuickGraph documentation on Depth First Search (yes, I realize you're doing BFS and not DFS, but the concept of how to subscribe to events is the same):
By the way, open up Reflector and take a look at QuickGraph.Algorithms.Observers. And your shortest path requirement would be easier with a different method than BFS.
目前还没有该算法的文档;但还有下一个最好的事情(或者甚至更好的事情):单元测试!
如果您下载 QuickGraph 源代码,并找到
BreadthFirstAlgorithmSearchTest.BreadthFirstSearchAll()
,您将看到该算法的示例用法,该算法在测试项目中的所有有向图上运行 BFS。There's no documentation for this algorithm yet; but there's the next best thing (or perhaps even a better thing): a Unit Test!
If you download the QuickGraph sources, and find the
BreadthFirstAlgorithmSearchTest.BreadthFirstSearchAll()
, you will see an example usage of the algorithm which runs BFS on all the directed graphs in the test project.Github 上有一个简短的帖子,其中有一个有用的基本示例,说明如何设置 BFS 并从中获取一些结果。
特定于您的应用程序的其他详细信息(创建随机图等)显然不属于此示例的一部分。
来源:
https://github.com/YaccConstructor/QuickGraph/issues/189#issuecomment- 487493207
There was a brief thread on Github which had a useful basic example of how to setup BFS and get some results from it.
The other details specific to your application (creating a random graph, etc.) are obviously not part of this example.
Source:
https://github.com/YaccConstructor/QuickGraph/issues/189#issuecomment-487493207