Boost logo

Boost Users :

Subject: Re: [Boost-users] BGL: write_graphviz_dp taking in count values of dynamic_properties
From: Jeremiah Willcock (jewillco_at_[hidden])
Date: 2013-09-30 12:14:25


On Mon, 30 Sep 2013, Pablo Madoery wrote:

> Hi,
> I have the following code that print a graph taking in count values of dynamic_properties:
>
> #include<iostream>
> #include <boost/graph/adjacency_list.hpp>
> #include <boost/graph/graphviz.hpp>
>
> using namespace std;
> using namespace boost;
>
> struct VertexInfo
> {
>     int id;
> };
>
> struct EdgeInfo
> {
>     double weight;
>     bool enable;
> };
>
> typedef adjacency_list<listS, vecS, bidirectionalS, VertexInfo, EdgeInfo> Graph;
>
> int main()
> {
>     ////////////////////////////////////////////////////////////////////////////////////////////
>     Graph graph;
>     Graph::vertex_descriptor a = add_vertex(graph);
>     Graph::vertex_descriptor b = add_vertex(graph);
>     Graph::vertex_descriptor c = add_vertex(graph);
>     Graph::vertex_descriptor d = add_vertex(graph);
>     Graph::edge_descriptor e1 = (add_edge(a, b, graph)).first;
>     Graph::edge_descriptor e2 = (add_edge(a, b, graph)).first;
>     Graph::edge_descriptor e3 = (add_edge(b, c, graph)).first;
>     Graph::edge_descriptor e4 = (add_edge(c, a, graph)).first;
>     Graph::edge_descriptor e5 = (add_edge(c, a, graph)).first;
>     Graph::edge_descriptor e6 = (add_edge(c, d, graph)).first;
>
>     graph[e1].weight = 5;
>     graph[e2].weight = 10;
>     graph[e3].weight = 6;
>     graph[e4].weight = 14;
>     graph[e5].weight = 2;
>     graph[e6].weight = 3;
>
>     graph[e1].enable = true;
>     graph[e2].enable = false;
>     graph[e3].enable = true;
>     graph[e4].enable = false;
>     graph[e5].enable = true;
>     graph[e6].enable = false;
>
>     ofstream ofs("graph.dot");
>     dynamic_properties dp;
>     dp.property("node_id", get(vertex_index, graph));
>     dp.property("label", get(&EdgeInfo::weight, graph));
>     dp.property("taillabel", get(&EdgeInfo::enable, graph));
>     write_graphviz_dp(ofs, graph, dp);
>
>     cout << "fin" << endl;
>
>     return 0;
> }
>
> ///////////////////////////////////////////////////////////////////////////////////
>
> there is a property called "enable" in the edges that I print in the tails of the arrows.
> But what i really want is that when enable = false the style of the arrow be different ("invis" for example). How can i do that?

Try something like this (not tested); be sure to include
<boost/property_map/transform_value_property_map.hpp>:

dp.property(
   "style",
   boost::make_transform_value_property_map(
     enable_to_style(),
     get(&EdgeInfo::enable, graph)));

where enable_to_style is something like:

struct enable_to_style {
   std::string operator()(bool b) const {
     return b ? "solid" : "invis";
   }
};

-- Jeremiah Willcock


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net