简体   繁体   English

BGL:我如何从捆绑对象到顶点描述符?

[英]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). 问题是关于Boost Graph Library (不幸的是没有这样的标签)。

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 . 假设我已经通过使用Boost Graph Library捆绑属性功能将Widget实例与图形的每个顶点相关联。 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). Widget实现operator== ,并与顶点相关联的所有部件是不同的(即,对于任意一对顶点的widget1 != widget2保持用于与这些顶点相关联的窗口小部件)。

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. 特别是,假设我有对象widget1widget2 ,并且相应的顶点已添加到图中。 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. 我怀疑BGL本身无法提供从顶点属性到相应顶点描述符的映射,因为通常该映射是m:1多对一。 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. 即使在您的情况下,您知道不同的顶点必须具有不同的属性,但BGL通常无法得知。

You can probably maintain this mapping (eg vd_map ) yourself when you create the graph eg using std:map . 创建图形时,您可以自己维护此映射(例如vd_map ),例如使用std:map When you insert each vertex with its attribute ( Widget in this case), insert a corresponding entry: 在插入每个顶点及其属性(在这种情况下为Widget )时,请插入相应的条目:

vd_map[widget] = desc;

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

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