Modifying vertex properties in a Boost::Graph

前端 未结 5 1887
执念已碎
执念已碎 2020-12-04 09:40

I am trying to figure out how to use boost::graph to store some information. However, there is information I want tied to each vertex. Staring at the documentation for the l

5条回答
  •  甜味超标
    2020-12-04 10:00

    Bundled properties are straightforward to use:

    using namespace boost;
    
    struct vertex_info { 
        std::string whatever; 
        int othervalue; 
        std::vector some_values; 
    };
    
    typedef adjacency_list graph_t;
    
    graph_t g(n);
    
    g[0].whatever = "Vertex 0";
    
    [...]
    

    and so on.

    Please also refer to the docs.

    The other type of vertex property that are very useful are external properties. You can declare std::vectors of the appropriate size and use them as properties.

提交回复
热议问题