C++ boost::write_graphviz-如何水平生成图形

C++ boost::write_graphviz-如何水平生成图形,c++,boost,graph,graphviz,dot,C++,Boost,Graph,Graphviz,Dot,我正在尝试生成一个.dot,它用Boost图形库显示一个水平图形 创建图表时的代码如下所示: struct VertexP { std::string tag; }; struct EdgeP { std::string symbol; }; struct GraphP{ std::string orientation; }; typedef boost::adjacency_list<boost::vecS, boost::vecS, boo

我正在尝试生成一个.dot,它用Boost图形库显示一个水平图形

创建图表时的代码如下所示:

struct VertexP {
    std::string tag;
};

struct EdgeP {
    std::string symbol;
};

struct GraphP{
    std::string orientation;
};

typedef boost::adjacency_list<boost::vecS,
        boost::vecS, boost::directedS,
        VertexP, EdgeP, GraphP> Graph;

GraphP property;
property.orientation = "LR";
Graph graph(property);
// Then fill the graph
Graph g = creator.AutomatonToGraph(&automaton);
ofstream dot_file("automaton.dot");
dynamic_properties dp;
dp.property("node_id", get(&VertexP::tag, g));
dp.property("label", get(&VertexP::tag, g));
dp.property("label", get(&EdgeP::symbol, g));

write_graphviz_dp(dot_file, g, dp);
这可以完美地编写带有节点和边标签的.dot文件,但我的问题是我想将
rankdir=LR
graph属性添加到输出文件中。我试过:

Graph g = creator.AutomatonToGraph(&automaton);
ofstream dot_file("automaton.dot");
dynamic_properties dp;
dp.property("node_id", get(&VertexP::tag, g));
dp.property("label", get(&VertexP::tag, g));
dp.property("label", get(&EdgeP::symbol, g));
dp.property("rankdir", get(&GraphP::orientation, g));

write_graphviz_dp(dot_file, g, dp);
但我从以下几个方面得到了大量错误:

/src/lab2.cc:48:55:   required from here
/usr/include/boost/graph/detail/adjacency_list.hpp:2585:29: error: forming reference to void
         typedef value_type& reference;
                             ^~~~~~~~~

我对使用BGL真的很陌生,我做错了什么?

阅读
动态\u图形\u属性\u writer
的实现,我发现您应该这样做

    dp.property("rankdir", boost::make_constant_property<Graph*>(std::string("LR")));
#include <boost/property_map/function_property_map.hpp>

    dp.property("rankdir", boost::make_function_property_map<Graph*>([](Graph const* g) { return g->m_property->orientation; }));
#include <boost/graph/adj_list_serialize.hpp>
#include <boost/graph/graphviz.hpp>
#include <boost/property_map/function_property_map.hpp>
#include <fstream>
using namespace boost;

struct VertexP { std::string tag; };
struct EdgeP { std::string symbol; };
struct GraphP { std::string orientation; };

typedef adjacency_list<vecS, vecS, directedS, VertexP, EdgeP, GraphP> Graph;

int main() {
    Graph g(GraphP{"LR"});
    // Then fill the graph
    add_edge(
        add_vertex(VertexP{ "tag1" }, g),
        add_vertex(VertexP{ "tag2" }, g),
        EdgeP{ "symbol" }, g
    );

    {
        std::ofstream dot_file("automaton.dot");
        dynamic_properties dp;
        dp.property("node_id", get(&VertexP::tag, g));
        dp.property("label", get(&VertexP::tag, g));
        dp.property("label", get(&EdgeP::symbol, g));
        dp.property("rankdir", boost::make_constant_property<Graph*>(std::string("LR")));
        dp.property("dummy", boost::make_function_property_map<Graph*>([](Graph const* g) { return g->m_property->orientation; }));

        write_graphviz_dp(dot_file, g, dp);
    }
}
digraph G {
dummy=LR;
rankdir=LR;
tag2 [label=tag2];
tag1 [label=tag1];
tag1->tag2  [label=symbol];
}