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

Mic*_*elM 5 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...
}
Run Code Online (Sandbox Code Playgroud)

有人知道怎么做吗?

谢谢

小智 9

您可以在此页面中找到所需的功能(在"非成员函数"部分中).你需要的是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);
}
Run Code Online (Sandbox Code Playgroud)