在 Boost::Graph 中修改顶点属性

2021-12-24 00:00:00 graph properties c++ boost boost-graph

我想弄清楚如何使用 boost::graph 来存储一些信息.但是,我想将信息与每个顶点相关联.盯着库的文档揭示了(a)写得很糟糕的文档,或者(b),我显然没有我想象的那么擅长 C++.选择两个.

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 library reveals either(a)badly written documentation, or (b), I'm obviously not as good at C++ as I thought. Pick two.

我正在寻找一个简单的使用示例.

I am looking for a simple example use.

推荐答案

捆绑的属性使用起来很简单:

Bundled properties are straightforward to use:

using namespace boost;

struct vertex_info { 
    std::string whatever; 
    int othervalue; 
    std::vector<int> some_values; 
};

typedef adjacency_list<vecS, vecS, undirectedS, vertex_info> graph_t;

graph_t g(n);

g[0].whatever = "Vertex 0";

[...]

等等.

另请参阅文档.

另一种非常有用的顶点属性是外部属性.您可以声明适当大小的 std::vectors 并将它们用作属性.

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.

相关文章