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

rcollyer
  • 10,475
  • 4
  • 48
  • 75
jlstrecker
  • 4,953
  • 3
  • 46
  • 60

1 Answers1

4

From the read_graphviz_new.hpp source:

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

Where node_and_port looks like this:

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. It may also be available in the 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 is selected, based on an #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 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; for me code of interest 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.

phooji
  • 10,086
  • 2
  • 38
  • 45
  • Thanks-- it worked. To clarify, you pass a `parser_result` to `parse_graphviz_from_string`, and for each `edge_info` in its `edges` vector, you look at each `node_and_port`'s `location` field. – jlstrecker Mar 06 '11 at 23:30
  • To clarify, we could not get port info from `read_graphviz`. In function `translate_results_to_graph`, only `ei.source.name` and `ei.target.name` are copied to the returned graph. – chain ro May 19 '18 at 09:58