简体   繁体   English

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

[英]How to get port identifiers for an edge using Boost Graph Library?

Using the Boost Graph Library, is it possible to get the port identifiers for an edge? 使用Boost Graph Library,是否可以获取边缘的端口标识符?

Example: After calling read_graphviz , I can iterate through the edges of this graph and print their node_id s -- I get "A -> B, A -> B". 示例:在调用read_graphviz ,我可以遍历此图的边缘并打印它们的node_id s - 我得到“A - > B,A - > B”。 How can I print something like "A:p0 -> B:p1, A:p0 -> B:p2"? 如何打印“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;
}

渲染的有向图G.

From the read_graphviz_new.hpp source: 来自read_graphviz_new.hpp来源:

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

Where node_and_port looks like this: 其中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
  // ...
}

I think (but have not verified) that these results are available if you call the parser directly using: 我认为(但尚未验证)如果您直接使用以下方法调用解析器,则可以使用这些结果:

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

in namespace boost::read_graphviz_detail . 在命名空间boost::read_graphviz_detail It may also be available in the dynamic_property_map if you use read_graphviz directly; 如果直接使用read_graphviz它也可能在dynamic_property_map可用; it internally refers to read_graphviz_new . 它在内部指的是read_graphviz_new


Note: In graphviz.hpp , one of two graphviz parsers is selected, based on an #ifdef : 注意: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

If I am reading this correctly, then the non-spirit parser is the one you want; 如果我正确地阅读这个,那么非精神解析器就是你想要的; the spirit-based one looks like it disregards ports. 基于精神的一个看起来像是无视港口。

Anyway, this is just based on a quick look at the source for boost v. 1.44; 无论如何,这只是基于快速查看boost v.1.44的来源; for me code of interest lives in /usr/include/boost/graph/detail/read_graphviz_new.hpp . 对我来说,感兴趣的代码存在于/usr/include/boost/graph/detail/read_graphviz_new.hpp I have not tested this, but it looks like all the plumbing is there. 我没有测试过这个,但看起来所有的管道都在那里。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM