[BGL][Graph][vertex_descriptor] how do I get my vertex_descriptor?

This is probably in the Graph doc / book somewhere, but after a few hours poking around didn't find it... I added a bunch of vertices, each with a "unique id" property that comes from our system. Then I want to add the edges. Given the "unique id" from our system for the From and To vertices of the edge, how do I convert those "unique ids" into vertex_descriptors that can be passed to add_edge? tx Andy

Andrew Schweitzer escribió:
This is probably in the Graph doc / book somewhere, but after a few hours poking around didn't find it...
I added a bunch of vertices, each with a "unique id" property that comes from our system.
Then I want to add the edges. Given the "unique id" from our system for the From and To vertices of the edge, how do I convert those "unique ids" into vertex_descriptors that can be passed to add_edge?
tx
Andy
A simple solution that instantly comes to my mind is to create a map e.g. std::map<"unique id", Vertex, Comp<"unique id">
id2v and use it to convert vertex id to vertex descriptor.
If you use adjacency_list<> with vecS selector for vettices list and "unique id" is an integer number within the interval [0, num_vertices ) you may directly write boost::add_edge(id(v1), id(v2)) Hope this will help, Dmiry
participants (2)
-
Andrew Schweitzer
-
Dmitry