4

Using the Boost Graph Library, is it possible to get the port identifiers for an edge?

Example: After calling read_graphviz, I can iterate through the edges of this graph and print their node_ids -- I get "A -> B, A -> B". How can I print something like "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

4

1 回答 1

4

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_detaildynamic_property_map如果您直接使用,它也可能在 中可用read_graphviz;它在内部是指read_graphviz_new.


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

#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. 我没有对此进行测试,但看起来所有的管道都在那里。

于 2011-03-06T05:36:59.037 回答