Boost read_graphml 示例
我正在尝试使用 BOOST 库构建一个简单的 GraphML 加载器。我有一个 GraphML 文件,我想将其加载到 boost 邻接列表结构中。该图是有向的,它存储的唯一信息是节点的名称(0,1,2,...)以及从一个节点到另一个节点的边。我所做的是:
void loadHierarchy(){
// ...
std::ifstream inFile;
inFile.open("ext.gml", std::ifstream::in);
typedef boost::adjacency_list<> Graph;
Graph g;
boost::read_graphml(inFile, g);
// ...
}
我不需要使用任何属性,只需将整个图信息保留在邻接列表中即可。
我得到的错误如下:
错误:从
'loadHierarchy()::Graph' 类型的表达式对
'boost::mutate_graph&'
类型的引用进行无效初始化/usr/include/boost/graph/graphml.hpp:194: 错误:传递
'void boost::read_graphml(std::istream&, boost::mutate_graph&)' 的参数 2
应该就这么简单,但显然事实并非如此。
I'm trying to build a simple GraphML loader using BOOST libraries. I have a GraphML file and I want to load it in a boost adjacency list structure. The graph is directed and the only information that it is stored are the name of the nodes (0,1,2,...) and the edges from one node to another. What I did is:
void loadHierarchy(){
// ...
std::ifstream inFile;
inFile.open("ext.gml", std::ifstream::in);
typedef boost::adjacency_list<> Graph;
Graph g;
boost::read_graphml(inFile, g);
// ...
}
I don't need to use any properties, just to keep the whole graph information in the adjacency list.
The errors that I get are the following:
error: invalid initialization of reference of type
‘boost::mutate_graph&’
from expression of type‘loadHierarchy()::Graph’
/usr/include/boost/graph/graphml.hpp:194: error: in passing argument 2 of
‘void boost::read_graphml(std::istream&, boost::mutate_graph&)’
It should be as simple as that, but apparently it isn't.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
经过更彻底的调查后,我得出的结论是,boost::read_graphml 的 2 参数版本被暴露实际上是幸运的。第 3 个参数看起来像这样:
有一个特别好的 GraphML 编辑器,即 yEd,它输出一种格式错误的 GraphML 文件,例如它具有类似的标签
。上面的键中应该有一个 attr.type="string",但它没有。相反,它有一个 yfiles.type,这似乎是 yEd 正在使用的扩展(不幸的是)。默认的 mutate_graph_impl 无法处理这个问题。 mutate_graph_impl 需要由您继承,并且您需要直接调用第 2 版 read_graphml,并将您自己的 mutate_graph_impl 实现传递给它。
在您自己的实现中,您需要重写 mutate_graph_impl
来处理具有未指定 attr.type 的密钥。
after a more thorough investigation, i've come to the conclusion it is actually fortunate the 2 param version of boost::read_graphml is exposed. The 3 param one looks like this:
There is a particularly good GraphML editor out there, namely yEd that output a kind of malformed GraphML file, for example it has tags like
in it. The above key should have a attr.type="string" in it, yet it does not. It instead has a yfiles.type, which seems to be an extension yEd is using (unfortunately). The default mutate_graph_impl can't handle this. mutate_graph_impl will need to be inherited by you, and you will need to directly call the 2 version read_graphml with your own implementation of mutate_graph_impl passed to it.
In your own implementation, you will need to override mutate_graph_impl's
to handle the key with unspecified attr.type.
我认为您应该使用 read_graphml() 的 3 参数版本,即使您不需要设置任何属性。您想要使用的两个参数版本是库的(不幸的是暴露的)内部细节。
所以,我建议你尝试这样的事情:
我希望它有所帮助。
I think you should use the 3 parameter version of read_graphml(), even if you do not need any properties to be set. The two parameter version that you want to use is an (unfortunately exposed) internal detail of the library.
So, I suggest you to try something like this:
I hope it helped.