Use a Graph Library/Node Network Library or Write My Own?

后端 未结 9 1858
逝去的感伤
逝去的感伤 2020-12-23 22:23

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

9条回答
  •  死守一世寂寞
    2020-12-23 22:55

    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.

提交回复
热议问题