【问题标题】:Using custom and built-in properties in Boost::Graph在 Boost::Graph 中使用自定义和内置属性
【发布时间】:2011-01-25 13:03:15
【问题描述】:

我正在根据以下建议构建一个图形类: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(我的图表)。 然后我认为这可能是由于缺少内置属性,所以我尝试了:

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。 这种行为正常吗?使用自定义属性时是否还必须设置内置属性?

【问题讨论】:

    标签: c++ boost properties graph


    【解决方案1】:

    我已经很久没有使用 Boost.Graph,但谷歌搜索“vertex_index_t”,in hit #5 Andrew Sutton says

    只需将顶点索引声明为属性(捆绑或内部,如 在这里)不会为您购买任何新功能。它只是提供了一个地方 您可以为每个顶点或边分配一个索引。这个问题 半解决是发行版中的几乎每个算法都需要一个顶点 索引图(或边缘索引图,很少见),并且提供这将允许 自动提取属性映射的默认参数 顶点/边。

    它不会——或者不应该???自动分配索引。此外,如果您删除 顶点或边,您可能需要重新编号顶点。

    看来这个想法是在想要读取数字的算法之间标准化概念,但您仍然必须自己进行写入

    【讨论】:

    猜你喜欢
    • 2015-05-12
    • 1970-01-01
    • 2012-05-01
    • 2016-03-11
    • 1970-01-01
    • 1970-01-01
    • 2017-08-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多