edge_index为所有边的零? [英] edge_index zero for all edges?

查看:122
本文介绍了edge_index为所有边的零?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

像下面这样定义我的 boost :: graph ,我得到所有边缘的边缘索引为零。为什么?我做错了什么?

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

从文档和示例中可以看出, / p>

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

推荐答案

adjacency_list没有与之相关联的边缘索引,只有 索引。

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.

这篇关于edge_index为所有边的零?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆