c++ - boost 和图形化

标签 c++ c++11 boost

我正在尝试通过 boost 学习 graphviz。我已经使用 apt-get 在 Ubuntu 上安装了 boost 库,并尝试运行多个示例 boost 图形程序,但没有一个被编译。告诉我我错过了什么?

#include <boost/graph/graphviz.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <string>
#include <fstream>
#include <boost/graph/iteration_macros.hpp>

int main(int,char*[])
{
  typedef std::pair<int,int> Edge;
  Edge used_by[] = {
    Edge(1, 5), Edge(1, 7), Edge(1, 2), Edge(2, 7), Edge(2, 12),
    Edge(3, 7), Edge(3, 10), Edge(3, 12),
    Edge(4, 5), Edge(5, 6),Edge(6, 9),Edge(7, 8),Edge(8, 9),Edge(9, 14),
    Edge(10, 11),Edge(11, 14),Edge(12, 13),Edge(13, 14),Edge(14, 15)
  };
  const int nedges = sizeof(used_by)/sizeof(Edge);
  double weights[nedges];
  std::fill(weights, weights + nedges, 1.0);
  weights[1] = 0.5;
  weights[2] = 1.5;
  weights[3] = 2.5;

  using namespace boost;

  typedef adjacency_list< vecS, vecS, directedS,
    property< vertex_color_t, default_color_type >,
    property< edge_weight_t, double >
    > Graph;
  Graph g_write(used_by, used_by + nedges, weights, 16);

  // write
  dynamic_properties dp;
  dp.property("weight", get(edge_weight, g_write));
  dp.property("node_id", get(vertex_index, g_write));
  std::ofstream ofs( "test.dot" );
  write_graphviz(ofs, g_write, dp);

  return 0;
}

尝试编译如下: g++ --std=c++11 示例.cpp -lboost_system

错误:

roshan@ubuntu:~/FixMe/Learn$ g++ --std=c++11 sample.cpp -lboost_system
In file included from sample.cpp:1:0:
/usr/include/boost/graph/graphviz.hpp: In instantiation of ‘void boost::write_graphviz(std::ostream&, const Graph&, VertexPropertiesWriter, EdgePropertiesWriter, GraphPropertiesWriter, VertexID, typename boost::enable_if_c<boost::is_base_and_derived<boost::vertex_list_graph_tag, typename boost::graph_traits<Graph>::traversal_category>::value, boost::graph::detail::no_parameter>::type) [with Graph = boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, boost::property<boost::vertex_color_t, boost::default_color_type>, boost::property<boost::edge_weight_t, double> >; VertexPropertiesWriter = boost::dynamic_properties; EdgePropertiesWriter = boost::default_writer; GraphPropertiesWriter = boost::default_writer; VertexID = boost::vec_adj_list_vertex_id_map<boost::property<boost::vertex_color_t, boost::default_color_type>, long unsigned int>; std::ostream = std::basic_ostream<char>; typename boost::enable_if_c<boost::is_base_and_derived<boost::vertex_list_graph_tag, typename boost::graph_traits<Graph>::traversal_category>::value, boost::graph::detail::no_parameter>::type = boost::graph::detail::no_parameter]’:
/usr/include/boost/graph/graphviz.hpp:290:63:   required from ‘void boost::write_graphviz(std::ostream&, const Graph&, VertexPropertiesWriter, EdgePropertiesWriter, GraphPropertiesWriter, typename boost::enable_if_c<boost::is_base_and_derived<boost::vertex_list_graph_tag, typename boost::graph_traits<Graph>::traversal_category>::value, boost::graph::detail::no_parameter>::type) [with Graph = boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, boost::property<boost::vertex_color_t, boost::default_color_type>, boost::property<boost::edge_weight_t, double> >; VertexPropertiesWriter = boost::dynamic_properties; EdgePropertiesWriter = boost::default_writer; GraphPropertiesWriter = boost::default_writer; std::ostream = std::basic_ostream<char>; typename boost::enable_if_c<boost::is_base_and_derived<boost::vertex_list_graph_tag, typename boost::graph_traits<Graph>::traversal_category>::value, boost::graph::detail::no_parameter>::type = boost::graph::detail::no_parameter]’
/usr/include/boost/graph/graphviz.hpp:312:38:   required from ‘void boost::write_graphviz(std::ostream&, const Graph&, VertexWriter, typename boost::enable_if_c<boost::is_base_and_derived<boost::vertex_list_graph_tag, typename boost::graph_traits<Graph>::traversal_category>::value, boost::graph::detail::no_parameter>::type) [with Graph = boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, boost::property<boost::vertex_color_t, boost::default_color_type>, boost::property<boost::edge_weight_t, double> >; VertexWriter = boost::dynamic_properties; std::ostream = std::basic_ostream<char>; typename boost::enable_if_c<boost::is_base_and_derived<boost::vertex_list_graph_tag, typename boost::graph_traits<Graph>::traversal_category>::value, boost::graph::detail::no_parameter>::type = boost::graph::detail::no_parameter]’
sample.cpp:36:34:   required from here
/usr/include/boost/graph/graphviz.hpp:270:18: error: no match for call to ‘(boost::dynamic_properties) (std::ostream&, boost::iterator_facade<boost::range_detail::integer_iterator<long unsigned int>, long unsigned int, boost::random_access_traversal_tag, long unsigned int, long int>::reference)’
       vpw(out, *i); //print vertex attributes

最佳答案

在使用动态属性对象时,您需要使用write_graphviz_dp 而不是write_graphviz。 Boost 1.44 中更改了签名。

关于c++ - boost 和图形化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37615083/

相关文章:

c++ - 在 fixed_sized<true> 的情况下 boost 无锁队列行为

c++ - 如何将 MPL 类型列表 fold 到可变参数容器中?

c++ - enable_shared_from_this 必须是第一个基类吗?

php - 为 PHP 构建 Saxon/C 时出错

c++ - CMake 无法使用相对文件路径找到静态库

c++ - 将移位的无符号数字用作数组的索引号是一个好习惯

c++ - 如何修复 "error: ‘_1’ 未在此范围内声明”?

c++ - 在两个 vector 中对 vector 进行空间高效解包的优雅方法

c++ - 在 C++ 中,在单态类/静态成员的析构函数中管理资源是个坏主意吗?

python - Boost:在窗口中包含路径