简体   繁体   中英

Boost-Graph Accessing the label of an edge

I was using boost graph and it seems that I don't understand it very well.

To access the label of a vertex it seems to be all right to use get(vertex_name, graph_) and then access it with the [ ]. But how can I access the label of a edge.

I tried to apply the same methodology (and many other wrong stuffs) but I didn't successfully access its label.

Here is a snippet of my code:

typedef property<edge_name_t, int>   edge_property;
typedef property<vertex_name_t, int> vertex_property;
typedef adjacency_list<vecS, vecS, undirectedS, vertex_property, edge_property> MyGraph;

MyGraph graph_;
add_vertex(vertex_property(6), graph_);
add_vertex(vertex_property(1), graph_);
add_vertex(vertex_property(1), graph_);
add_edge(0, 1, edge_property(2), graph_); 
add_edge(1, 2, edge_property(3), graph_); 
add_edge(0, 2, edge_property(1), graph_); 

cout << "Graph 1 [graph_]" << endl;
typedef graph_traits<MyGraph>::edge_iterator edge_iter;
pair<edge_iter, edge_iter> ep;

property_map<MyGraph, vertex_name_t>::type labelling_vertex = get(vertex_name, graph_); 
property_map<MyGraph, edge_name_t>::type   labelling_edge   = get(edge_name,   graph_); 

int position = 0;
for (ep = edges(graph_); ep.first != ep.second; ++ep.first) {
    unsigned int source_ = source(*ep.first, graph_);
    unsigned int target_ = target(*ep.first, graph_);
    cout << source_ << "["<< labelling_vertex[source_] <<"]" << " ~~~~" << labelling_edge[position] << "~~~~ " << target_ <<"[" <<labelling_vertex[target_] <<"]" << endl;
    position++;
}

Ok, just found a way to do so.

labelling_edge[(*ep.first)]

Sorry to have bothered you

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