How to print a graph in graphviz with multiple properties displayed

空扰寡人 提交于 2019-11-29 04:52:35

You can find here the list of all the overloads for write_graphviz. The reason for your first error is that the overload you tried to use expects a graph property writer in its fifth argument.

The helper function make_label_writer simply creates a property writer that assigns a single property from either a vertex or an edge of your graph to a graphviz vertex or edge attribute named label.

In order to achieve what you want you need to create a custom property writer in which you assign each of your edge properties to the graphviz attributes you need. I would personally use weight->label and capacity->taillabel or headlabel.

template <class WeightMap,class CapacityMap>
class edge_writer {
public:
  edge_writer(WeightMap w, CapacityMap c) : wm(w),cm(c) {}
  template <class Edge>
  void operator()(ostream &out, const Edge& e) const {
    out << "[label=\"" << wm[e] << "\", taillabel=\"" << cm[e] << "\"]";
  }
private:
  WeightMap wm;
  CapacityMap cm;
};

template <class WeightMap, class CapacityMap>
inline edge_writer<WeightMap,CapacityMap> 
make_edge_writer(WeightMap w,CapacityMap c) {
  return edge_writer<WeightMap,CapacityMap>(w,c);
}

And finally your write_graphviz invocation would simply be:

ofstream dot("graph.dot");
write_graphviz(dot, g, 
  boost::make_label_writer(boost::get(&vert::name, g)),
  make_edge_writer(boost::get(&edge::weight,g),boost::get(&edge::capacity,g)));
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!