所有边的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;
}
据我从文档和示例中可以看出,这应该可行。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
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.