简体   繁体   English

Boost BGL:Edge属性映射?

[英]Boost BGL: Edge property maps?

I'm trying to make a graph given a list of connected edges, but my edges have both a score (a weight) and a trans (an user-defined data type which is basically a transformation matrix from one point to the other). 我试图给出一个连接边列表的图形,但我的边有一个得分(一个权重)和一个转换(用户定义的数据类型,它基本上是从一个点到另一个点的转换矩阵)。 I've tried a whole bunch of ways to do this, but every website I checked (including stackoverflow) has a different way of doing this which doesn't 100% fit my problem. 我已经尝试了很多方法来做到这一点,但我检查过的每个网站(包括stackoverflow)都有不同的方式来做这件事,这并不是100%适合我的问题。 I've tried all of them, but for now I've settled for the following: 我已经尝试了所有这些,但是现在我已经解决了以下问题:

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

But from what I can tell from most of the sites, declaring just one struct isn't enough... 但是从我从大多数网站上可以看出来的情况来看,只宣称一个结构是不够的......

Indeed, now when I try to print out my graph: 的确,现在当我尝试打印我的图表时:

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)] << ") ";

When I try to get the EdgeInfoProperty prop so that I can eventually print out prop.score , I get 当我试图获得EdgeInfoProperty道具以便最终打印出prop.score ,我得到了

error C2275: 'ConnGraph::MakeKinectGraph::EdgeInfoProperty' : illegal use of this type as an expression

Help. 救命。 This is for a research project and if I can't surpass this I won't be able to get to the more interesting part... 这是一个研究项目,如果我不能超越这个,我将无法进入更有趣的部分......

Use this: 用这个:

G[*ei].score
G[*ei].trans

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM