int main() { typedef b::adjacency_list<b::listS, b::vecS, b::undirectedS, vert, edge> Graph; Graph g; b::generate_random_graph(g, 10 /*100*/, 5 /*20*/, rng); write_graphviz(std::cout, g, boost::make_label_writer(boost::get(&vert::name, g)), make_edge_writer(boost::get(&edge::weight, g), boost::get(&edge::capacity, g))); }
void ribi::cmap::SaveToFile(const ConceptMap& g, const std::string& dot_filename) { //Cannot use: //save_custom_and_selectable_edges_and_vertices_graph_to_dot(g, dot_filename); //because we have a directed graph in which edegs have zero/one/two arrow heads std::ofstream f(dot_filename); boost::write_graphviz(f, g, make_custom_and_selectable_vertices_writer( get(boost::vertex_custom_type,g), get(boost::vertex_is_selected,g) ), make_edge_writer( get(boost::edge_custom_type,g), get(boost::edge_is_selected,g) ) ); }
int Graph::toGraphviz(string filename){ ofstream dotFile (filename.c_str()); if( !dotFile.is_open()){ return -1; } vector<string> ids; vector< pair< double, double> > locs; vector<nodeType> types; map< edge_d,string> edge_labels; // cout << "Num vertices " << num_vertices(*this) << endl; // property_map<MyGraphType, vertex_name_t>::type idmap = get(vertex_name_t(),*this); graph_traits<MyGraphType>::vertex_iterator vi, vi_end, next; tie(vi, vi_end) = vertices(*this); for (next = vi; next != vi_end; next++) { // printf("Vertex id [%d] = %s\n",*next,idmap[*next].c_str()); ids.push_back((*this)[*next].id); locs.push_back( make_pair( (*this)[*next].x, (*this)[*next].y)); types.push_back((*this)[*next].t); } graph_traits<MyGraphType>::edge_iterator ei,e_end,e_next; graph_traits<MyGraphType>::edge_descriptor e; tie(ei, e_end) = edges( (*this)); for(e_next = ei; e_next != e_end; e_next++) { edge_labels[*e_next] = (*this)[*e_next].label; } write_graphviz(dotFile, *this,make_position_writer(ids,locs,types),make_edge_writer(edge_labels),graph_writer()); return 0; }