Here is an example of my problem.
I would like to code this in C# in such a way so that I may interrogate the structure and find information such as:
- Total distance from A to B.
- Shortest distance from A to E (keeping in mind you can't go against the arrow's direction).
So I thought I would use an Adjacency List to model my graph, but then I thought this is a common thing, and started looking for libraries to help quicken the process (no need to re-invent the wheel .. etc.)
I came across this Library that was recommended a couple of time on various topics, but I am finding it real hard modelling my drawn graph above.
A possible solution is to model your graph as an
AdjacencyGraph<string, Edge<string>>
and construct aDictionary<Edge<string>, double>
cost dictionary, where costs are your distances.Your
_graph
is now:Then you can find the shortest path from A to E using:
This is adapted from the QuickGraph wiki. It prints: