Reputation: 195
I am learning boost::graph and trying to add name property to Vertex. However, after doing that, write_graphviz does not save anything (without this property, it works).
Header file:
struct VertexProps
{
std::string name;
};
struct EdgeProps
{
double weight;
};
using Graph = boost::adjacency_list<boost::setS, boost::vecS, boost::directedS, VertexProps, EdgeProps>;
using Vertex = boost::adjacency_list<>::vertex_descriptor;
using Edge = std::pair<boost::adjacency_list<>::edge_descriptor, bool>;
using EdgeList = std::pair<boost::adjacency_list<>::edge_iterator,
boost::adjacency_list<>::edge_iterator>;
Cpp file:
Vertex vertex = boost::add_vertex({std::move(vertexName)}, g);
std::filebuf fb;
fb.open("output.txt", std::ios::out);
std::ostream os(&fb);
write_graphviz(os, g, boost::make_label_writer(get(&VertexProps::name, g)), boost::make_label_writer(get(&EdgeProps::weight, g)));
fb.close();
The file should contain graph, however I can see only:
digraph G {
}
Upvotes: 1
Views: 150
Reputation: 393829
Unclear what you differently but here's a self-contained example based on the above:
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/graphviz.hpp>
struct VertexProps { std::string name; };
struct EdgeProps { double weight; };
using Graph = boost::adjacency_list<boost::setS, boost::vecS, boost::directedS, VertexProps, EdgeProps>;
int main(){
Graph g;
auto vertex = add_vertex({"MyVertexName"}, g);
write_graphviz(std::cout, g,
make_label_writer(get(&VertexProps::name, g)),
make_label_writer(get(&EdgeProps::weight, g)));
}
Which prints
digraph G {
0[label=MyVertexName];
}
Upvotes: 1