Kumar Roshan Mehta
Kumar Roshan Mehta

Reputation: 3286

Boost and graphviz

I'm trying to learn graphviz with boost. I have installed boost library on Ubuntu with apt-get and tried to run multiple sample boost graph program but none gets compiled. Tell me what am I missing ?

#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;
}

Trying to compile it with as follows: g++ --std=c++11 sample.cpp -lboost_system

Error :

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

Upvotes: 1

Views: 596

Answers (1)

Simon Larsen
Simon Larsen

Reputation: 742

You need to use write_graphviz_dp instead of write_graphviz when using a dynamic properties object. The signature was changed in Boost 1.44.

Upvotes: 3

Related Questions