【问题标题】:Getting edge properties (including related vertices) from boost::adjacency_list从 boost::adjacency_list 获取边属性(包括相关顶点)
【发布时间】:2012-08-13 14:50:42
【问题描述】:

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

有人知道怎么做吗?

谢谢

【问题讨论】:

    标签: c++ boost graph boost-graph


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-11
      • 2023-03-16
      • 1970-01-01
      • 2015-05-03
      • 1970-01-01
      • 2021-07-13
      相关资源
      最近更新 更多