I\'m trying to decide between going with a pre-made graph/node network library or to roll my own.
I\'m implementing some graph search algorithms which might require
I recently gave the boost graph library a trial for Dijkstras shortest path problem. Results:
Very High performance
Very little code needed
Very flexible and extensible
Hard to understand or debug
Advice: Use it but before you do so read The Boost Graph Library: User Guide and Reference Manual
I rolled my own. You shouldn't follow that example, unless you're absolutely certain you need to.
Still, it's a great learning experience, if you're graph theory is rusty.
I had lots of "fun" with combining digraphs using EBNF operators, and doing epsilon elimination and Hopcroft-based minimisation. Especially with the minimisation, if you can call desperately trying to find good information and figure out how it works "fun" :-(
If you do roll your own, I recommend separating high level operations from the low level digraph data structures - different classes, not just different methods. I didn't - and pretty soon I'll be refactoring heavily because of that poor decision.
Some graphs annotate nodes, some annotate edges, some both. Sometimes two annotations are useful, even if they're just foreign keys for some external data. For example in finite state machines, an edge may be annotated with an input and an output. You're likely to be interested in determinism WRT the input but not the output, so having them both hidden behind a single ID is a pain - and that's besides the whole issue of secondary containers for the what-does-this-ID-refer-to lookups.
Also, sometimes you just want to work with things that weren't designed explicitly as a digraph IYSWIM - e.g. a bunch of data structure nodes that link to each other.
IOW, it's useful to be able to plug in different digraph representations, yet still use the same high-level tools for many operations.
IMO I got it right when I wrote a 'tree tool' class which does things like iterating and subscripting in treeview order and XML element tag order. The underlying tree representation is pluggable (policy based template). With digraphs, I messed up.
Anyway, I don't know what Boost or any other graph library actually provides, but if it provides what you need I say use it. It'll save a lot of headaches.
This really isn't a concise answer, its more of adding to what has already been said.
The solution to this problem depends on the context of the problem. If you wish to get a great understanding how graph algorithms, and software works. Write your own. If you want to get an advanced knowledge of graph algorithms and structures or to implement them into your own program then learn a standard graph library. (See the reasons for using reusable code)
The best of both worlds. Do both. If you are stretched for time, get a book on this or follow tutorials and the examples.
Another suggestion: Ask a new pointed question about what is the {best, most reliable, easiest to learn} graph library for {describe a very general problem}? This will help you choose what to learn, rather than trying at random to find the best one that suits your needs. Someone has already seen this problem, ask for advice.
Using Reusable Code: