【问题标题】:Boost read_graphml example提升 read_graphml 示例
【发布时间】:2011-07-29 19:07:51
【问题描述】:

我正在尝试使用 BOOST 库构建一个简单的 GraphML 加载器。我有一个 GraphML 文件,我想将它加载到提升邻接列表结构中。该图是有向的,它存储的唯一信息是节点的名称 (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&amp;’ 类型的引用的初始化无效

/usr/include/boost/graph/graphml.hpp:194:错误:传递‘void boost::read_graphml(std::istream&amp;, boost::mutate_graph&amp;)’的参数2

应该就这么简单,但显然不是。

【问题讨论】:

    标签: c++ boost adjacency-list graphml


    【解决方案1】:

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

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

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

    希望对你有所帮助。

    【讨论】:

      【解决方案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 处理密钥。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-12-31
        • 2011-10-19
        • 2016-01-14
        • 2018-08-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多