c++ - 如何使用 Boost Graph Library 获取边缘的端口标识符?

标签 c++ boost graphviz boost-graph

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

示例:调用 read_graphviz 后,我可以遍历该图的边并打印它们的 node_id——我得到“A -> B,A ->乙”。如何打印类似“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;
}

Rendering of digraph G

最佳答案

来自 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

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

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

关于c++ - 如何使用 Boost Graph Library 获取边缘的端口标识符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5208811/

相关文章:

python - 如何通过 boost::python 捕获 python 站点的自定义异常

graphviz - 定位具有 `{rank=same ...}` 副作用的节点

python - 将引擎从 dot 更改为 neato 时未找到 graphviz PATH 变量

c++ - 使用boost将gzip压缩/解压缩到内存中

c++ - 需要代码度量。最佳代码中 h 文件中的 LOC 与 cpp 文件中的 LOC 的比率

c++ - 是否有任何 c/c++ 编译器可以警告(或给出错误)或枚举转换为 int?

c++ - QT 在错误的类中寻找插槽

c++ - boost read()永远不会返回,即使在服务器(ssl)boost上执行了写入

graphviz - 如何让 DOT 显示节点的图像?

c++ - 如何在 C++ 中发出长哔声?