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

Modifying vertex properties in a Boost::Graph(在 Boost::Graph 中修改顶点属性)

本文介绍了在 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.

这篇关于在 Boost::Graph 中修改顶点属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:在 Boost::Graph 中修改顶点属性

基础教程推荐