因此,我今天一定已经阅读了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...
}

有人知道怎么做吗?

谢谢

最佳答案

您可以在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);
}

关于c++ - 从boost::adjacency_list获取边缘属性(包括相关顶点),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12000987/

10-11 15:51