Create an undirected graph and move it using BFS in QuickGraph

I am trying to figure out how to create a new instance of an undirected weighted graph using QuickGraph for C #. My goal is to create an undirected weighted graph filled with a random number of nodes and randomly generated start and end nodes, the shortest path of which can be found using the Width search algorithm. The documentation is not so much, therefore, if someone can provide any help that will be appreciated.

+4
source share
2 answers

Richard, QuickGraph does not do any of this for you, it only makes available events that you can subscribe to. By subscribing to these events, you can respond accordingly. From the admittedly missing QuickGraph documentation on Depth First Search (yes, I understand that you are doing BFS, not DFS, but the concept of how to subscribe to events is the same):

  • InitializeVertex, called at each vertex before starting the calculation,
  • DiscoverVertex, called when the vertex is first encountered,
  • ExamineEdge called at each outer end of each vertex after it is detected,
  • TreeEdge is called on each edge when it becomes a member of the edges that form the search tree.
  • FinishVertex is called at the vertex after all of its outer edges have been added to the search tree and all adjacent vertices have been detected (but before their outer edges have been checked).

By the way, open Reflector and take a look at QuickGraph.Algorithms.Observers. And your shortest path would be easier with a different method than BFS.

+2
source

There is no documentation for this algorithm; but there is the next best thing (or maybe even the best thing): a Unit Test!

If you download QuickGraph sources and find BreadthFirstAlgorithmSearchTest.BreadthFirstSearchAll (), you will see an example of using an algorithm that runs BFS on all oriented graphs in a test project.

+1
source

Source: https://habr.com/ru/post/1302602/


All Articles