【问题标题】:boost::graph : implementation independent way of getting edge from a pair of verticesboost::graph :从一对顶点获取边缘的实现独立方式
【发布时间】:2013-07-18 21:37:13
【问题描述】:

我查看了 Boost 图的概念,但它没有提供从顶点对中获取任何边的任何接口。 我试过了:

boost::graph_traits<G>::edge_descriptor edge(u, v); // does not work

但它需要一个额外的指向属性类型的指针。我怎样才能得到它?

【问题讨论】:

    标签: c++ boost-graph


    【解决方案1】:

    boost::edge() 的第三个参数是你的图表。

    还请注意,该函数不直接返回边描述符,而是包含边描述符和布尔值的对,具体取决于边的存在

    类似这样的:

    G myGraph;   // construct the graph
    ....         // populate it
    ....         // select a pair of vertices u, v
    
    // get the edge between the vertices, if it exists
    typedef boost::graph_traits<G>::edge_descriptor edge_t;
    edge_t found_edge;
    std::pair < edge_t, bool > p = boost::edge( u, v, myGraph ); 
    if( ! p.second) {
       // edge does not exist
       ...
    } else {
       found_edge = p.first;
       ...
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多