BGL: Write graphviz file with invisible edges

I found out that if you write a graph (.dot) file like this: graph G { 0; 1; 2; 0--1; 1--2 [style=invis]; } graphviz will layout the graph as if it has two edges (0--1, and 1--2), but not display the edge between vertices 1 and 2. This is useful when trying to keep the vertices stationary and show changes to the connectivity. How would I setup the graph in BGL so I could mark particular edges so they will be written with [style=invis]? Thanks, David

On Tue, 21 Jun 2011, David Doria wrote:
I found out that if you write a graph (.dot) file like this:
graph G { 0; 1; 2; 0--1; 1--2 [style=invis]; }
graphviz will layout the graph as if it has two edges (0--1, and 1--2), but not display the edge between vertices 1 and 2. This is useful when trying to keep the vertices stationary and show changes to the connectivity. How would I setup the graph in BGL so I could mark particular edges so they will be written with [style=invis]?
The strategy for doing that is to create a dynamic_properties object, add an entry to it for the "style" edge property and some property map, and then pass that to write_graphviz_dp. An example of what you want to do is in libs/graph/example/graphviz.cpp; see how the "weight" property is handled. In your case, the value type of the property would be std::string. -- Jeremiah Willcock

The strategy for doing that is to create a dynamic_properties object, add an entry to it for the "style" edge property and some property map, and then pass that to write_graphviz_dp. An example of what you want to do is in libs/graph/example/graphviz.cpp; see how the "weight" property is handled. In your case, the value type of the property would be std::string.
-- Jeremiah Willcock
Thanks Jeremiah, Here is what I tried: #include <iostream> #include <string> #include <boost/graph/undirected_graph.hpp> #include <boost/graph/graphviz.hpp> struct StyleProperty { std::string style; } typedef boost::undirected_graph<boost::no_property, StyleProperty> Graph; int main() { Graph g; Graph::vertex_descriptor v0 = g.add_vertex(); Graph::vertex_descriptor v1 = g.add_vertex(); Graph::vertex_descriptor v2 = g.add_vertex(); StyleProperty styleInvisible; styleInvisible.style = "invis"; StyleProperty styleNormal; styleNormal = "normal"; boost::add_edge(v0,v1,styleInvisible, g); boost::add_edge(v1,v2,styleNormal g); boost::dynamic_properties dp; dp.property("style", get(&StyleProperty::style, g)); boost::write_graphviz_dp(std::cout, g, dp, "style"); return 0; } However, I get an exception "dynamic property get cannot retrieve value for property: style." Can you see where I have gone wrong? Thanks, David

On Tue, 21 Jun 2011, David Doria wrote:
The strategy for doing that is to create a dynamic_properties object, add an entry to it for the "style" edge property and some property map, and then pass that to write_graphviz_dp. An example of what you want to do is in libs/graph/example/graphviz.cpp; see how the "weight" property is handled. In your case, the value type of the property would be std::string.
-- Jeremiah Willcock
Thanks Jeremiah,
Here is what I tried:
#include <iostream> #include <string>
#include <boost/graph/undirected_graph.hpp> #include <boost/graph/graphviz.hpp>
struct StyleProperty { std::string style; }
typedef boost::undirected_graph<boost::no_property, StyleProperty> Graph;
int main() { Graph g; Graph::vertex_descriptor v0 = g.add_vertex(); Graph::vertex_descriptor v1 = g.add_vertex(); Graph::vertex_descriptor v2 = g.add_vertex();
StyleProperty styleInvisible; styleInvisible.style = "invis";
StyleProperty styleNormal; styleNormal = "normal";
boost::add_edge(v0,v1,styleInvisible, g); boost::add_edge(v1,v2,styleNormal g);
boost::dynamic_properties dp; dp.property("style", get(&StyleProperty::style, g));
boost::write_graphviz_dp(std::cout, g, dp, "style");
The last argument here shouldn't be "style" -- it should be the default "node_id" or something else that can be used to identify vertices in the graph.
return 0; }
However, I get an exception "dynamic property get cannot retrieve value for property: style."
I'm not sure what the issue is for that -- try changing the call to write_graphviz_dp and see if it recurs. -- Jeremiah Willcock

boost::write_graphviz_dp(std::cout, g, dp, "style");
The last argument here shouldn't be "style" -- it should be the default "node_id" or something else that can be used to identify vertices in the graph.
return 0; }
However, I get an exception "dynamic property get cannot retrieve value for property: style."
I'm not sure what the issue is for that -- try changing the call to write_graphviz_dp and see if it recurs.
-- Jeremiah Willcock _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
I tried both: boost::write_graphviz_dp(std::cout, g, dp, "node_id"); and boost::write_graphviz_dp(std::cout, g, dp); and both produce the exception "dynamic property cannot retrieve value for property: "node_id". David

On Tue, 21 Jun 2011, David Doria wrote:
boost::write_graphviz_dp(std::cout, g, dp, "style");
The last argument here shouldn't be "style" -- it should be the default "node_id" or something else that can be used to identify vertices in the graph.
return 0; }
However, I get an exception "dynamic property get cannot retrieve value for property: style."
I'm not sure what the issue is for that -- try changing the call to write_graphviz_dp and see if it recurs.
-- Jeremiah Willcock _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
I tried both: boost::write_graphviz_dp(std::cout, g, dp, "node_id"); and boost::write_graphviz_dp(std::cout, g, dp);
and both produce the exception "dynamic property cannot retrieve value for property: "node_id".
You will also need dp.property("node_id", get(vertex_index, g)); before the write_graphviz_dp call. -- Jeremiah Willcock

On Tue, Jun 21, 2011 at 2:55 PM, David Doria <daviddoria@gmail.com> wrote:
You will also need dp.property("node_id", get(vertex_index, g)); before the write_graphviz_dp call.
Awesome, works like a charm. Thanks for your help!
David
Here is the full example for future readers: http://programmingexamples.net/index.php?title=CPP/Boost/BGL/InvisibleEdges David
participants (2)
-
David Doria
-
Jeremiah Willcock