Boost read_graphml示例 [英] Boost read_graphml example

查看:133
本文介绍了Boost read_graphml示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用BOOST库构建一个简单的GraphML加载器.我有一个GraphML文件,我想以增强邻接表结构加载它.该图是有向的,并且存储的唯一信息是节点的名称(0,1,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.

我得到的错误如下:

错误:类型‘loadHierarchy()::Graph’

/usr/include/boost/graph/graphml.hpp:194:错误:传递了‘void boost::read_graphml(std::istream&, boost::mutate_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.

推荐答案

经过更深入的研究后,我得出的结论是,它实际上很幸运地公开了boost :: read_graphml的2参数版本.这三个参数看起来像这样:

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:

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文件,例如,它具有类似

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

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

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

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

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

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

to handle the key with unspecified attr.type.

这篇关于Boost read_graphml示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆