I would like to retrieve the label of a labeled node in BGL's labeled_graph but cannot find a method to do this.
The following MWE demonstrates what I am looking for:
//g++ -O3 question.cpp -o question.exe -I. --std=c++11 -lprotobuf-lite -lpthread -lz -losmpbf
#include <iostream>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/labeled_graph.hpp>
#include <boost/graph/iteration_macros.hpp>
typedef long long node_id_t;
typedef boost::adjacency_list<
boost::listS, // Store out-edges of each vertex in a std::list
boost::listS, // Store vertex set in a std::list
boost::bidirectionalS, // The file dependency graph is directed
boost::no_property, // vertex properties
boost::no_property // edge properties
> AdjGraph;
typedef boost::labeled_graph<
AdjGraph,
node_id_t // Node ID
> LabeledGraph;
int main(){
LabeledGraph g;
add_vertex( 10, g );
add_vertex( 20, g );
add_vertex( 30, g );
add_vertex( 40, g );
add_vertex( 50, g );
boost::add_edge_by_label(10,30,g);
boost::add_edge_by_label(10,50,g);
boost::add_edge_by_label(30,40,g);
boost::add_edge_by_label(50,20,g);
BGL_FORALL_EDGES(e, g, LabeledGraph){
auto source_n = boost::source(e,g);
//How do I do the following?
//std::cerr<<boost::get_label_of_vertex(source_n)<<std::endl;
}
}
The command boost::get_label_of_vertex(source_n)
does not seem to exist in my diggings.
Do you know if it does, or if there is another way to get this information?
Ah. I found your questions in the wrong order :)
I don't think
labeled_graph<>
adaptor has this feature. Instead, like in my other answer I suggest storing the label as a vertex property (bundled or vertex_index_t).Bundled
Live On Coliru
vertex_index_t
interior propertyLive On Coliru