从boost :: adjacency_list获取边缘属性(包括相关顶点)

时间:2012-08-17 06:46:43

标签: c++ boost graph boost-graph

所以,我今天必须通过Boost文档一小时。我必须失明。我希望,我有一个简单的问题:

如何使用boost :: adjacency_list获得边缘的相应顶点?

我有以下代码,我想弄清楚:

typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS> Graph;
typedef boost::graph_traits<Graph>::edge_iterator EdgeIterator;
typedef std::pair<EdgeIterator, EdgeIterator> EdgePair;

EdgePair ep;
for (ep = edges(g); ep.first != ep.second; ++ep.first)
{
    // Get the two vertices that are joined by this edge...
}

任何人都知道怎么做?

由于

1 个答案:

答案 0 :(得分:9)

您可以在this page中找到所需的功能(在“非会员功能”部分中)。您需要的是sourcetarget

typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS> Graph;
typedef boost::graph_traits<Graph>::edge_iterator EdgeIterator;
typedef std::pair<EdgeIterator, EdgeIterator> EdgePair;
typedef boost::graph_traits<Graph>::vertex_descriptor VertexDescriptor;

EdgePair ep;
VertexDescriptor u,v;
for (ep = edges(g); ep.first != ep.second; ++ep.first)
{
    // Get the two vertices that are joined by this edge...
    u=source(*ep.first,g);
    v=target(*ep.first,g);
}