简体   繁体   中英

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. 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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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