Reputation: 1608
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...
Upvotes: 1
Views: 818