使用图形库/节点网络库或写我自己? [英] Use a Graph Library/Node Network Library or Write My Own?

查看:140
本文介绍了使用图形库/节点网络库或写我自己?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用pre-做图/节点的网络库或将要推出自己的决定。

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 some significant customization to the class structure of the node and/or edges.

我不知道该怎么做的原因是,我不能确定,如果一个pre-制作可能比让我自己放在第一位比较贵/麻烦定制。我也很好奇,但不如此,性能的权衡。

The reason I'm not sure what to do is that I'm unsure if customization of a pre-made might be more expensive/trouble than making my own in the first place. I'm also curious, but less so, of the performance trade-offs.

有没有人在那里与使用图书馆那里之一,并基于成功或失败的故事,建议直接的经验?我想听到的最糟糕的,这样无论我选择,我知道我进入。

Is there anyone out there have direct experience with using one of the libraries out there and have advice based on a success or failure story? I want to hear the worst so that whatever I chose, I know what I'm getting into.

有只有两个,我已经在我的搜索迄今发现:的 Boost Graph库(BGL) GOBLIN 。对其中任意一个,或者为他人建议,具体建议是大大pciated以及AP $ P $。 BGL似乎pretty该死的神秘。是否值得通过努力?

There are only two that I've found in my search so far: The Boost Graph Library (BGL) and GOBLIN. Specific advice on either of these, or suggestions for others is greatly appreciated as well. BGL seems pretty damn arcane. Is it worth struggling through?

推荐答案

我或许可以提供关于BGL一些指导。

I can perhaps provide a little guidance on the BGL.

该库是非常灵活的。这样做的成本是该语法可以很巴洛克,为了容纳所有的可能性。但是,它是足够柔韧的,简单的事情可以简单地进行。

The library is very flexible. The cost of this is that the syntax can be very baroque, in order to accommodate all the possibilities. However, it is sufficiently flexible that simple things can be done simply.

不幸的是,提升文档去的东西完全倾斜,只提供的全部复杂性的描述,没有简单的事情怎么可以一个暗示。

Unfortunately the boost documentation goes at things full tilt, providing a description only of the full complexity, without a hint of how simple things can be.

(任何足够先进的技术都与魔法无异。 - 阿瑟·克拉克什么,他应该说的是任何先进的技术,充分证明严重,都与魔法无异)

( "Any sufficiently advanced technology is indistinguishable from magic" - Arthur C. Clarke. What he should have said is "Any advanced technology, sufficiently badly documented, is indistinguishable from magic )

考虑:

typedef property_map<Graph, vertex_index_t>::type IndexMap;
IndexMap index = get(vertex_index, g);
typedef graph_traits<Graph>::vertex_iterator vertex_iter;
std::pair<vertex_iter, vertex_iter> vp;
for (vp = vertices(g); vp.first != vp.second; ++vp.first) {
   std::cout << index[*vp.first] <<  " ";
}

这是快速浏览怎么暗示我们打印出图中顶点的列表。然而,一个小的研究表明,顶点是不大于整数索引以上,且code可以大大简化到

This is how the "quick tour" suggests we print out a list of the graph vertices. However, a little study shows that a vertex is no more than an integer index, and the code can be greatly simplified to

for (int v = *vertices(g).first; v != *vertices(g).second; ++v)
    std::cout << v << " ";

也许还有不能用这种简化code来实现一些神奇的事情,但是对于每天都使用它合理的大幅度删减了结垢BGL语法,所以你可以看到你的编码是什么。

Perhaps there are some magical things that cannot be achieved with this simplified code, but for every day use it reasonable to drastically prune the syntax that encrust BGL so you can see what your are coding.

有时精心句法不能被除去。 (或许我刚才没有注意到潜在的道理)。然后我通常用一个小效用函数封装复杂ABD从我工作的算法保持它了。

Sometimes the elaborate syntax cannot be removed. ( Or perhaps I have just not noticed the underlying truth ). Then I usually use a little utility function to encapsulate the complexity abd keep it away from the algorithm I am working on.

例如,我经常需要遍历顶点的孩子

For example, I often need to loop over the children of a vertex

vector<int> getVertexChildren( int v )
{
    vector<int> vc;
    typedef std::pair<graph_traits<graph_t>::out_edge_iterator, graph_traits<graph_t>::out_edge_iterator> out_edge_iter_pair_t;
    for( out_edge_iter_pair_t ep = out_edges(v,m_tree);
        ep.first != ep.second; ++(ep.first))
    {
        vc.push_back( target( *ep.first, m_tree ) );
    }
    return vc;
}
#define FOR_ALL_CHILDREN( v ) vector<int> vc=getVertexChildren(v); BOOST_FOR_EACH( int child, vc )

底线是:继续使用BGL。它可以简化为做简单的事情,但是一旦你已经学会使用它,所有的巨大的灵活性将可当你需要它。

The bottom line is: go ahead and use BGL. It can be simplified to do simple things, but once you have learned to use it, all the immense flexibility will be available whenever you do need it.

这篇关于使用图形库/节点网络库或写我自己?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆