简体   繁体   中英

BGL: how can I get from a bundled object to a vertex descriptor?

The question is about the Boost Graph Library (there is no such label unfortunately).

Suppose that I have associated a Widget instance with each vertex of a graph by using the bundled property feature of the Boost Graph Library . The class Widget implements operator== and all widgets associated with vertices are distinct (ie, for any pair of vertices, widget1 != widget2 holds for the widgets associated with these vertices).

Does the graph maintain a reverse mapping, ie can I easily retrieve a vertex descriptor that corresponds to a given object? In particular, suppose that I have objects widget1 and widget2 and the corresponding vertices have been added into the graph. How can I add an edge between the two objects (ie between the corresponding vertices)?

I suspect that BGL itself cannot provide a mapping from a vertex attribute to the corresponding vertex descriptor because the mapping is m:1 many to one, in general. Many vertices/descriptors can correspond to the same attribute. Even though in your case, you know that different vertices must have different attribute, BGL generally has no way of knowing that.

You can probably maintain this mapping (eg vd_map ) yourself when you create the graph eg using std:map . When you insert each vertex with its attribute ( Widget in this case), insert a corresponding entry:

vd_map[widget] = desc;

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