write_graphviz 在顶点具有 属性 时不起作用
write_graphviz does not work when vertex has property
我正在学习 boost::graph 并尝试将名称 属性 添加到 Vertex。但是,这样做之后,write_graphviz 不会保存任何东西(没有这个 属性,它会起作用)。
头文件:
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 文件:
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();
文件应该包含图表,但我只能看到:
digraph G {
}
不清楚你有什么不同,但这是一个基于上述内容的独立示例:
#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)));
}
打印
digraph G {
0[label=MyVertexName];
}
我正在学习 boost::graph 并尝试将名称 属性 添加到 Vertex。但是,这样做之后,write_graphviz 不会保存任何东西(没有这个 属性,它会起作用)。
头文件:
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 文件:
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();
文件应该包含图表,但我只能看到:
digraph G {
}
不清楚你有什么不同,但这是一个基于上述内容的独立示例:
#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)));
}
打印
digraph G {
0[label=MyVertexName];
}