用基本类型标记的 Boost Graph 边缘的简单点输出

Simple dot output for Boost Graph edges labelled with basic types

使用 Boost 图形库的捆绑属性意味着创建代码以输出与 graphviz 兼容的点文件非常简单:

#include <boost/graph/graphviz.hpp>

struct Edge { int i; };

int main()
{
  using namespace boost;
  typedef adjacency_list<vecS, vecS, directedS, no_property, Edge> Graph;
  Graph g;
  add_edge(0, 1, {123}, g);
  write_graphviz(std::cout, g, default_writer(),
                   make_label_writer(boost::get(&Edge::i,g)));
  return 0;
}

在上面的代码中,边 属性 是使用名为 Edge 的结构定义的。这个结构只包含一个 int; boost::get 然后为 make_label_writer 提供必要的 PropertyWriter.

如果我想对边缘 属性 使用基本类型,例如 intdouble,我现在需要传递给哪些参数make_label_writer?代码能否与上面的代码保持可比性。例如,adjacency_list 可以声明为:

typedef adjacency_list<vecS, vecS, directedS, no_property, int> Graph;

您可以直接解决边缘束。

With bundled properties, the pointer-to-member property tag is implicitly applied to the value of the edge_bundle_t property (or vertex_bundle_t or graph_bundle_t as the case may be; Therefore you wouldn't want to use the same user-defined type for edge/vertex/graph bundles).

Live On Coliru

#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/graphviz.hpp>

int main()
{
    using namespace boost;
    typedef adjacency_list<vecS, vecS, directedS, no_property, int> Graph;
    Graph g;
    add_edge(0, 1, 123, g);
    write_graphviz(std::cout, g, default_writer(), 
            make_label_writer(boost::get(edge_bundle,g)));
}

输出:

digraph G {
0;
1;
0->1 [label=123];
}