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

Getting edge properties (including related vertices) from boost::adjacency_list

本文关键字:包括相 顶点 属性 获取 adjacency boost list      更新时间:2023-10-16

所以,我今天一定已经浏览了一个小时的 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...
}

有人知道如何做到这一点吗?

谢谢

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