其他分享
首页 > 其他分享> > c-edge_index为零的所有边缘?

c-edge_index为零的所有边缘?

作者:互联网

如下定义我的boost :: graph,我得到所有边缘的边缘索引为零.为什么?我究竟做错了什么?

#include <iostream>
#include <boost/graph/adjacency_list.hpp>

int main() {
    typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, boost::no_property, boost::property<boost::edge_index_t, std::size_t> > Graph;
    typedef boost::graph_traits<Graph>::edge_descriptor Edge;

    Graph g(3);
    Edge e1 = boost::add_edge(0, 1, g).first;
    Edge e2 = boost::add_edge(1, 2, g).first;
    Edge e3 = boost::add_edge(2, 0, g).first;

    boost::property_map<Graph, boost::edge_index_t>::type eim = boost::get(boost::edge_index, g);
    size_t e1n = eim[e1],
           e2n = eim[e2],
           e3n = eim[e3];

    return 0;
}

据我从文档和示例中可以看出,这应该有效.

解决方法:

adjacency_list没有与之关联的边索引,只有一个顶点索引.一旦考虑图形的存储方式,这是很合逻辑的.

要具有边缘索引,您需要将其手动添加到图形描述中,然后手动进行处理.

标签:c,boost-graph
来源: https://codeday.me/bug/20191011/1893606.html