简体   繁体   English

Boost-Graph访问边的标签

[英]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 [ ]. 要访问顶点的标签,似乎可以使用get(vertex_name,graph_),然后使用[]访问它。 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)] labelling_edge [(* ep.first)]

Sorry to have bothered you 抱歉打扰你了

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

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