我试图在给定连接边列表的情况下制作一个图,但我的边同时具有分数(权重)和反式(用户定义的数据类型,基本上是从一个点到另一个点的转换矩阵其他)。我已经尝试了很多方法来做到这一点,但我检查过的每个网站(包括 stackoverflow)都有不同的方法来做到这一点,这并不是 100% 适合我的问题。我已经尝试了所有这些,但现在我已经解决了以下问题:
struct EdgeInfoProperty{
int score;
Trans trans;
};
typedef boost::adjacency_list<boost::listS, boost::vecS, boost::directedS, boost::no_property, EdgeInfoProperty > mygraph;
typedef mygraph::edge_descriptor Edge;
mygraph G;
for (i..i++){//some is
for(j..j++){//some js
boost::graph_traits<mygraph>::vertex_descriptor u, v;
u = vertex(i, G);
v = vertex(j, G);
EdgeInfoProperty property_uv;
property_uv.score=s[i]+s[j];//some score
property_uv.trans = T[i]*T[j];
boost::add_edge(u,v,property_uv,G);
}
}
但是据我所知,从大多数网站上可以看出,仅声明一个结构是不够的...
确实,现在当我尝试打印我的图表时:
typedef boost::property_map<mygraph, boost::vertex_index_t>::type IndexMap;
IndexMap index = get(boost::vertex_index, G);
std::cout << "vertices(g) = ";
typedef boost::graph_traits<mygraph>::vertex_iterator vertex_iter;
std::pair<vertex_iter, vertex_iter> vp;
for (vp = boost::vertices(G); vp.first != vp.second; ++vp.first)
std::cout << index[*vp.first] << " ";
std::cout << std::endl;
std::cout << "edges(g) = ";
boost::graph_traits<mygraph>::edge_iterator ei, ei_end;
for (boost::tie(ei, ei_end) = edges(G); ei != ei_end; ++ei)
//----- how do I get the edge property?
//EdgeInfoProperty prop = boost::get(EdgeInfoProperty, *ei);
std::cout << "(" << index[source(*ei, G)]<< "," << index[target(*ei, G)] << ") ";
当我尝试获取 EdgeInfoProperty
Prop 以便最终打印出 prop.score
时,我得到了
error C2275: 'ConnGraph::MakeKinectGraph::EdgeInfoProperty' : illegal use of this type as an expression
帮助。这是一个研究项目,如果我不能超越这个,我将无法进入更有趣的部分......
最佳答案
使用这个:
G[*ei].score
G[*ei].trans
关于c++ - boost BGL : Edge property maps?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25111393/