edge_index zero for all edges?

瘦欲@ 提交于 2019-12-20 03:06:13

问题


Defining my boost::graph like the following, I get edge indices zero for all edges. Why? What am I doing wrong?

#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;
}

As far as I can tell from documentation and examples, this should work.


回答1:


An adjacency_list doesn't have an edge index associated with it, only a vertex index. Which is quite logical once you think about how the graph is stored.

To have an edge index, you need to manually add it to the graph description, and then manually handle it.



来源:https://stackoverflow.com/questions/7283128/edge-index-zero-for-all-edges

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!