2
4

2 回答 2

2

我认为您应该使用 read_graphml() 的 3 参数版本,即使您不需要设置任何属性。您要使用的两个参数版本是库的(不幸的是公开的)内部细节。

所以,我建议你尝试这样的事情:

boost::dynamic_properties dp;
boost::read_graphml(inFile, g, dp);

我希望它有所帮助。

于 2011-12-12T16:40:53.577 回答
2

经过更彻底的调查,我得出结论,实际上很幸运的是 boost::read_graphml 的 2 参数版本被暴露。3 参数一个看起来像这样:

template<typename MutableGraph>
void
read_graphml(std::istream& in, MutableGraph& g, dynamic_properties& dp)
{
    mutate_graph_impl<MutableGraph> mg(g,dp);
    read_graphml(in, mg);
}

那里有一个特别好的 GraphML 编辑器,即 yEd,它输出一种格式错误的 GraphML 文件,例如它有如下标签

<key for="node" id="d6" yfiles.type="nodegraphics"/>

在里面。上面的键应该有一个attr.type="string",但它没有。相反,它有一个 yfiles.type,这似乎是 yEd 正在使用的扩展名(不幸的是)。默认的 mutate_graph_impl 无法处理这个问题。mutate_graph_impl 将需要由您继承,并且您需要直接调用 2 版本 read_graphml 并将您自己的 mutate_graph_impl 实现传递给它。在您自己的实现中,您将需要覆盖 mutate_graph_impl 的

virtual void
    set_vertex_property(const std::string& name, any vertex, const std::string& value, const std::string& value_type)

处理未指定 attr.type 的密钥。

于 2012-06-15T04:31:19.750 回答