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

7

今天我必须花了一个小时阅读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个回答

12

您可以在此页面中找到所需的函数(位于“非成员函数”部分)。您需要的是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);
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接