我是BGL的新手,我在创建自己的属性贴图时出现问题,其关键是edge_property
你可以告诉我,我做错了以下代码不打印: (0,1)==(0,1)? 1 但 (0,1)==(0,1)? 0
这是代码
#include <boost/graph/adjacency_list.hpp>
#include <iostream>
#include <map>
using namespace std;
class A {};
class B {};
typedef boost::adjacency_list<boost::listS, boost::vecS, boost::bidirectionalS,
A, B > Graph;
typedef boost::graph_traits<Graph>::vertex_descriptor vertex_descriptor;
typedef boost::graph_traits<Graph>::edge_descriptor edge_descriptor;
typedef boost::graph_traits<Graph>::edge_iterator edge_iterator;
typedef boost::graph_traits<Graph>::in_edge_iterator in_edge_iterator;
typedef boost::graph_traits<Graph>::out_edge_iterator out_edge_iterator;
map<edge_descriptor, int> fun(Graph g){
map<edge_descriptor, int> m;
m[*(edges(g).first)] = 5;
return m;
}
int main(){
Graph g;
vertex_descriptor a = add_vertex(g);
vertex_descriptor b = add_vertex(g);
add_edge(a, b, g);
map<edge_descriptor, int> m = fun(g);
edge_iterator ei, ei_end;
for(tie(ei, ei_end) = edges(g) ; ei !=ei_end ; ++ei){
cout << m.begin()->first << " == " << *ei << " ? " << (m.begin()->first == *ei) << endl;
}
}
非常感谢你!
编辑: 也许有更好的方法来映射edge而不是edge_property值?
答案 0 :(得分:1)
您的边缘描述符有3个成员:源节点,目标节点和指向B属性的指针。在fun
中,您复制了图表,并且新图表中复制的边缘指向不同的B.如果您将fun
声明为map<edge_descriptor, int> fun(const Graph& g)
(并且您可能应该一个更大的图表的副本可能是昂贵的)你获得了你期望的结果。