How to print a boost graph in graphviz with one of the properties displayed?

后端 未结 2 407
后悔当初
后悔当初 2020-12-09 22:27

I see examples of this when using property maps, but not when using structs to handle the vertices and edges (I think this is called \'bundles\').

I have vertices an

相关标签:
2条回答
  • 2020-12-09 22:52

    I gave bad info the first time. Here is the correct answer.

    #include <boost/graph/graphviz.hpp>
    
    using namespace boost;
    
    // Graph type
    typedef adjacency_list<vecS, vecS, directedS, VertexProperties, EdgeProperty> Graph;
    Graph g;
    std::vector<std::string> NameVec; // for dot file names
    
    
    // write the dot file
    std::ofstream dotfile (strDotFile.c_str ());
    write_graphviz (dotfile, g, make_label_writer(&NameVec[0]));
    
    0 讨论(0)
  • 2020-12-09 22:57

    I just stumbled upon this question. Although it has an accepted answer, I thought I'll add my version too.

    You are using bundled property in your graph. The correct way to get property map from your bundled properties is to use boost::get. So you can do something like:

    boost::write_graphviz(std::cout, your_graph,
        boost::make_label_writer(boost::get(&Vertex::name, your_graph)),
        boost::make_label_writer(boost::get(&Edge::weight, your_graph)),
        );
    

    Where your_graph is the graph object you have created.

    0 讨论(0)
提交回复
热议问题