首页 文章

需要提升adjacency_list帮助

提问于
浏览
2

我'm trying to use Boost' s adjacency_list类型,我无法理解documentation .

假设我定义了一个名为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);

但当然这不起作用 . 请帮忙!

Edit:
Here's几乎正是我需要的一个例子 .

1 回答

  • 3

    读取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);
    

    (很差)改编自an example in boost .

相关问题