【问题标题】:How to get port identifiers for an edge using Boost Graph Library?如何使用 Boost Graph Library 获取边缘的端口标识符?
【发布时间】:2011-03-06 05:00:08
【问题描述】:

使用 Boost Graph Library,是否可以获取边缘的端口标识符?

示例:调用read_graphviz 后,我可以遍历该图的边缘并打印它们的node_ids——我得到“A -> B,A -> B”。如何打印“A:p0 -> B:p1, A:p0 -> B:p2”之类的内容?

digraph G {
    A [label="A|<p0>p0"];
    B [label="B|<p1>p1|<p2>p2"];

    A:p0 -> B:p1;
    A:p0 -> B:p2;
}

【问题讨论】:

    标签: c++ boost graphviz boost-graph


    【解决方案1】:

    来自read_graphviz_new.hpp 来源:

    struct edge_info {
      node_and_port source;
      node_and_port target;
      properties props;
    };
    

    node_and_port 看起来像这样:

    struct node_and_port {
      node_name name;
      std::string angle; // Or empty if no angle
      std::vector<std::string> location; // Up to two identifiers
      // ...
    }
    

    我认为(但尚未验证)如果您直接使用以下方式调用解析器,这些结果是可用的:

     void parse_graphviz_from_string(const std::string& str, parser_result& result, bool want_directed);
    

    在命名空间boost::read_graphviz_detail。如果您直接使用read_graphviz,它也可能在dynamic_property_map 中可用;它在内部引用read_graphviz_new


    注意:graphviz.hpp 中,根据#ifdef 选择两个graphviz 解析器之一:

    #ifdef BOOST_GRAPH_USE_SPIRIT_PARSER
      return read_graphviz_spirit(data.begin(), data.end(), graph, dp, node_id);
    #else // Non-Spirit parser
      return read_graphviz_new(data,graph,dp,node_id);
    #endif
    

    如果我没看错,那么非精神解析器就是你想要的;以精神为基础的看起来像是无视端口。

    无论如何,这只是基于快速浏览 boost v. 1.44 的源代码;对我来说,感兴趣的代码位于/usr/include/boost/graph/detail/read_graphviz_new.hpp。我没有对此进行测试,但看起来所有的管道都在那里。

    【讨论】:

    • 谢谢——它成功了。为了澄清,您将parser_result 传递给parse_graphviz_from_string,对于edges 向量中的每个edge_info,您查看每个node_and_portlocation 字段。
    • 澄清一下,我们无法从read_graphviz 获取端口信息。在函数translate_results_to_graph 中,只有ei.source.nameei.target.name 被复制到返回的图形中。
    猜你喜欢
    • 1970-01-01
    • 2014-08-13
    • 2019-09-14
    • 2014-05-09
    • 2020-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-16
    相关资源
    最近更新 更多