å æ¥ã®ã°ã©ããGraphvizã®*.dotå½¢å¼ã§åºåãã¦ã¿ããã
#include <fstream> #include <vector> #include <string> #include <boost/graph/adjacency_list.hpp> #include <boost/graph/graphviz.hpp> typedef boost::adjacency_list<boost::listS, boost::vecS, boost::directedS, boost::no_property, boost::property<boost::edge_weight_t, int>> Graph; typedef std::pair<int, int> Edge; enum { A, B, C, D, E, N }; const std::string name = "ABCDE"; int main() { const std::vector<Edge> edges = { {A, B}, {A, C}, {A, D}, {B, E}, {C, E}, {D, E} }; const std::vector<int> weights = { 3, 1, 4, 5, 2, 6 }; const Graph g(edges.begin(), edges.end(), weights.begin(), N); // graphvizã®å½¢å¼(*.dot)ã§åºå std::ofstream file("test.dot"); boost::write_graphviz(file, g, boost::make_label_writer(name.c_str())); }
åºåãããtest.dot
digraph G { 0[label="A"]; 1[label="B"]; 2[label="C"]; 3[label="D"]; 4[label="E"]; 0->1 ; 0->2 ; 0->3 ; 1->4 ; 2->4 ; 3->4 ; }
test.dotãpngã«å¤æã
dot -Tpng test.dot -o test.png
ãããªæãã«ãªãã¾ããã
weightã¯ã©ããã£ã¦åºåãããã ããããã¨ã§èª¿ã¹ãã