我正在尝试使用Boost的adjacency_list类型,但我无法理解文档

假设我定义了一个名为State的类,并为美国的每个州实例化一个实例:

class State { ... };
State california, oregon, nevada, arizona, hawaii, ...

我想将这些输入到boost :: adjacency_list中,顶点是状态,边是边界。对于我上面列出的状态,我认为该图表将包含以下数据:

california : oregon, nevada, arizona
hawaii :
oregon : california, nevada
nevada : oregon, california, arizona
arizona : california, nevada

我理解如何将图形放入图形中,我考虑只创建一个状态数组并将其数组索引插入图形中,但似乎我应该只能说:

add_edge(california, oregon, graph);

但当然不起作用。请帮忙!

修改结果 这里的几乎就是我的一个例子需要。

有帮助吗?

解决方案

读取boost :: adjacency_list,看起来你应该使用顶点的属性而不是像类这样的东西:

struct VertexProperties {
    std::string stateName;
};

typedef adjacency_list<listS, listS, bidirectionalS, VertexProperties> Graph;
Graph adjacentStates(50);

property_map<Graph, std::string VertexProperties::*>::type
    stateName = get(&VertexProperties::stateName, adjacentStates);

add_edge(vertex("california", adjacentStates), vertex("oregon", adjacentStates), adjacentStates);

(很差)改编自提升中的一个例子

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top