gpt4 book ai didi

c++ - boost 和图形化

转载 作者:行者123 更新时间:2023-11-30 02:31:30 24 4
gpt4 key购买 nike

我正在尝试通过 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com