Boost logo

Boost Users :

Subject: [Boost-users] Graph: writing graph properties to graphml file
From: Juerg Tschirren (juerg.tschirren_at_[hidden])
Date: 2012-02-28 20:47:22


I wrote the code below to construct a directed graph with internal
properties (for vertices, edges, and the graph itself) and write everything
to a graphml file. The code compiles and works as it is, but my two
questions are:

1. What dynamic property do I have to add to write the graph properties out
to the graphml file as well? So far I could only figure out how to write
vertex and edge properties.

2. Does everything else look good? Specifically, is it O.K. to define the
properties the way I did in the first typedef line (without using
boost::property<>), and is it O.K. to access the properties the way I do
it?

Juerg

//--- start of example code
typedef boost::adjacency_list<boost::listS, boost::vecS,
boost::directedS, std::string, std::string, std::string> Graph;
typedef boost::graph_traits<Graph>::vertex_descriptor vertex_t;
typedef boost::graph_traits<Graph>::edge_descriptor edge_t;

Graph g;

vertex_t u = boost::add_vertex(g);
vertex_t v = boost::add_vertex(g);
edge_t e; bool b;
boost::tie(e,b) = boost::add_edge(u,v,g);

g[u] = "a_vertex_name";
g[v] = "an_other_vertex_name";
g[e] = "an_edge_name";
boost::get_property(g) = "the_graph";

boost::dynamic_properties dp;
dp.property("vertex_data", boost::get(boost::vertex_bundle, g));
dp.property("edge_data", boost::get(boost::edge_bundle, g));

std::ofstream graphmlOutFile("graph.xml");
boost::write_graphml(graphmlOutFile, g, dp, true);
graphmlOutFile.close();



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