我正在基于以下建议构建图类:Modifying vertex properties in a Boost::Graph

不幸的是,我意识到了意外的行为。当使用我自己的顶点属性(为简单起见,请忽略边缘属性)时,似乎不使用内置属性。
例如,当我有:

typedef adjacency_list<
        setS, // disallow parallel edges
        listS, // vertex container
        undirectedS, // undirected graph
        property<vertex_properties_t, VERTEXPROPERTIES>,
        property<edge_properties_t, EDGEPROPERTIES>
> GraphContainer;

我可以毫无问题地检索自定义属性,但是当我要检索vertex_index-property时,我总是为每个顶点获得相同的值,即值为0。节点是不同的,这由num_vertices(MyGraph)确认。
然后我认为这可能是由于缺少内置属性造成的,所以我尝试了:
typedef adjacency_list<
        setS, // disallow parallel edges
        listS, // vertex container
        undirectedS, // undirected graph
        property<vertex_index_t, unsigned int , property< vertex_properties_t, VERTEXPROPERTIES> >,
        property<edge_properties_t, EDGEPROPERTIES>
> GraphContainer;

同样,当想要检索任何顶点的索引时,我得到的值为0。
这是正常现象吗?使用自定义属性时,是否还必须设置内置属性?

最佳答案

自从我使用Boost.Graph已经很长时间了,但是使用Google搜索“vertex_index_t”,in hit #5 Andrew Sutton says:



因此,似乎是要在希望读取数字的算法之间对概念进行标准化,但是您仍然必须自己编写。

关于c++ - 在Boost::Graph中使用自定义和内置属性,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/2411017/

10-11 22:38
查看更多