私の質問は以下に基づいています:単一のプロパティが表示されたグラフを印刷する方法
バンドルされたプロパティを使用しています:
typedef struct vert{
std::string name;
};
typedef struct edge{
int capacity;
int weight;
};
typedef adjacency_list<listS, vecS, undirectedS, vert, edge> Graph;
Graph g;
vector<int,int> ele;
エッジを作成する必要があるループで次の呼び出しを行います。
edge prop;
prop.weight = 5;
prop.capacity = 4;
add_edge(ele.first,ele.second, prop, g);
このセグメントは、グラフをドット形式で出力するものです。
ofstream dot("graph.dot");
write_graphviz(dot, g,
boost::make_label_writer(boost::get(&vert::name, g)),
boost::make_label_writer(boost::get(&edge::weight, g)),
boost::make_label_writer(boost::get(&edge::capacity, g)));
エラーは次のとおりです。
/usr/include/boost/graph/graphviz.hpp: In function ‘void boost::write_graphviz(std::ostream&, const Graph&, VertexPropertiesWriter, EdgePropertiesWriter, GraphPropertiesWriter, VertexID) [with Graph = boost::adjacency_list<boost::listS, boost::vecS, boost::undirectedS, vert, edge, boost::no_property, boost::listS>, VertexPropertiesWriter = boost::label_writer<boost::bundle_property_map<boost::adjacency_list<boost::listS, boost::vecS, boost::undirectedS, vert, edge, boost::no_property, boost::listS>, long unsigned int, vert, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, EdgePropertiesWriter = boost::label_writer<boost::bundle_property_map<boost::adjacency_list<boost::listS, boost::vecS, boost::undirectedS, vert, edge, boost::no_property, boost::listS>, boost::detail::edge_desc_impl<boost::undirected_tag, long unsigned int>, edge, int> >, GraphPropertiesWriter = boost::label_writer<boost::bundle_property_map<boost::adjacency_list<boost::listS, boost::vecS, boost::undirectedS, vert, edge, boost::no_property, boost::listS>, boost::detail::edge_desc_impl<boost::undirected_tag, long unsigned int>, edge, int> >, VertexID = boost::vec_adj_list_vertex_id_map<boost::property<boost::vertex_bundle_t, vert, boost::no_property>, long unsigned int>]’:
/usr/include/boost/graph/graphviz.hpp:260: instantiated from ‘void boost::write_graphviz(std::ostream&, const Graph&, VertexPropertiesWriter, EdgePropertiesWriter, GraphPropertiesWriter) [with Graph = Graph, VertexPropertiesWriter = boost::label_writer<boost::bundle_property_map<boost::adjacency_list<boost::listS, boost::vecS, boost::undirectedS, vert, edge, boost::no_property, boost::listS>, long unsigned int, vert, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, EdgePropertiesWriter = boost::label_writer<boost::bundle_property_map<boost::adjacency_list<boost::listS, boost::vecS, boost::undirectedS, vert, edge, boost::no_property, boost::listS>, boost::detail::edge_desc_impl<boost::undirected_tag, long unsigned int>, edge, int> >, GraphPropertiesWriter = boost::label_writer<boost::bundle_property_map<boost::adjacency_list<boost::listS, boost::vecS, boost::undirectedS, vert, edge, boost::no_property, boost::listS>, boost::detail::edge_desc_impl<boost::undirected_tag, long unsigned int>, edge, int> >]’
file_format.cc:194: instantiated from here
/usr/include/boost/graph/graphviz.hpp:236: error: no match for call to ‘(boost::label_writer<boost::bundle_property_map<boost::adjacency_list<boost::listS, boost::vecS, boost::undirectedS, vert, edge, boost::no_property, boost::listS>, boost::detail::edge_desc_impl<boost::undirected_tag, long unsigned int>, edge, int> >) (std::basic_ostream<char, std::char_traits<char> >&)’
これが機能するので、私には奇妙です:
write_graphviz(dot, g,
boost::make_label_writer(boost::get(&vert_info::name, g)));
そして、以下を出力します。
graph G {
0[label="0"];
1[label="1"];
2[label="2"];
3[label="3"];
4[label="4"];
5[label="5"];
6[label="6"];
7[label="7"];
8[label="8"];
9[label=""]; // this is another problem that I will have to fix but beside the point
0--9 ;
0--5 ;
0--2 ;
0--1 ;
...
...
}
私の目標は、各ノードにラベルを付け、各エッジにその容量と重みでラベルを付けることです。