如何将自定义图形适合boost图形库模板?
我对 C++ 模板很生疏,而且我正在使用 boost 图形库(一个致命的组合)。我在网上搜索过,但找不到任何关于如何采用自定义图形结构并将其足够适合 BGL(增强图形库)的直接说明,以便我可以使用增强图形遍历算法。有熟悉图书馆的人可以帮助我吗?
编辑:所以,我遇到的主要问题是在哪里找到源,其中将任意图映射到 BGL 图的总要求。我对模板真的很陌生,所以我很难阅读 BGL 的规范/示例。也许我应该寻找模板的一般来源?
I'm rusty on C++ templates and I'm using the boost graph library (a fatal combination). I've searched the web and can't find any direct instructions on how to take a custom graph structure and fit enough of it to BGL (boost graph library) that I can use boosts graph traversing algorithms. Anyone familiar enough with the library to help me out?
EDIT: So, the main problem I've been having is where to find a source where the total requirements to map an arbitrary graph to a BGL graph. I'm really new to templates so it's hard for me to read BGL's specification/examples. Maybe I should look for a general source on templates?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我的建议是完全放弃使用 BGL,除非您已经在其上编写了大量代码。我最近正在测试它以供将来在一个大型图形分析项目中使用,我发现由于过于复杂且设计不当的 API,它几乎无法使用。
BGL 中没有简单的任务,只有复杂的任务,由于 BGL 的模板层次结构过于复杂,我一直在与编译器作斗争。几乎没有有用的文档(至少没有真正需要的地方),并且没有足够的示例只会使问题变得更加严重。这不是写代码的方法。
我建议切换到 LEMON。它稳定,用 C++ 编写,易于理解和编码,提供多种专门形式的图形来支持不同的使用需求,并且支持 BFS 和 DFS 搜索/访问者功能。它还具有自己的相当于节点/边的属性映射,因此您应该能够将自己的图形结构和其他数据放入其中。
尝试柠檬;它味道好得多,并且会减少溃疡。 ;-)
My suggestion would be to abandon use of BGL entirely unless you already have a significant amount of code written on top of it. I was testing it out recently for future use on a large graph analysis project, and I found it to be almost unusable due to an overly complex and poorly designed API.
There are no simple tasks in BGL, only complex ones, and I was constantly fighting the compiler due to the excessively complicated template hierarchy that BGL has. Little to no useful documentation (at least not where it's really needed) and not enough examples only aggravate matters. That's no way to write code.
I'd recommend switching to LEMON. It's stable, written in C++, easy-to-understand and code in, offers several specialized forms of graphs to support different usage needs, and it supports both BFS and DFS search/visitor functions. It also has its own equivalent of property maps for nodes/edges, so you should be able to fit your own graph structure and other data onto it.
Try LEMON; it tastes a lot better and will cause fewer ulcers. ;-)
据我了解,该方法是针对您的图形类型专门化
boost::graph_traits
结构。这会为 BGL 配置它需要了解您的图的各种重要属性。然后,您可以为图形的专用类型graph_traits
专门化全局模板函数,以实现可能适用于您的特定类型图形的任何 boost 图形接口。BGL 文档中有一个示例:
http://www.boost。 org/doc/libs/1_43_0/libs/graph/doc/leda_conversion.html
那里有几个不同接口的链接,它们指示如果您想要的话,您需要为您的图形专门化哪些全局模板函数支持该接口。接口的完整列表位于:
http://www.boost.org/ doc/libs/1_43_0/libs/graph/doc/graph_concepts.html
The approach, as I understand it, is to specialize the
boost::graph_traits
structure for your graph type. This configures BGL with various important properties it needs to know about your graph. You then specialize global template functions for your graph's specialized type ofgraph_traits
to implement whatever boost graph interfaces might apply to your specific kind of graph.An example is right there in the BGL documentation:
http://www.boost.org/doc/libs/1_43_0/libs/graph/doc/leda_conversion.html
There are links for several of the different interfaces there, which indicate which global template functions you'll need to specialize for your graph if you want to support that interface. The full list of interfaces is here:
http://www.boost.org/doc/libs/1_43_0/libs/graph/doc/graph_concepts.html