How to get port IDs for an edge using the Boost Graph library?

Using the Boost Graph library, is it possible to get port IDs for an edge?

Example: by calling read_graphviz , I can read_graphviz over the edges of this graph and print them with node_id - 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
source share
1 answer

From read_graphviz_new.hpp source:

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

Where node_and_port as follows:

 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 did not check) 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 the boost::read_graphviz_detail . It may also be available in dynamic_property_map if you use read_graphviz directly; it internally refers to read_graphviz_new .


Note: In graphviz.hpp , one of two graphviz parsers based on #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 

If I read this correctly, then a parser without a spirit is the one you want; based on the spirit, it looks like it is ignoring ports.

In any case, this is simply based on a quick look at the source of boost v. 1.44; for me, the interest code lives in /usr/include/boost/graph/detail/read_graphviz_new.hpp . I have not tested this, but it looks like all the plumbing is there.

+3
source

Source: https://habr.com/ru/post/1342483/


All Articles