boost :: compressed_sparse_row_graph用法

时间:2019-04-25 16:53:23

标签: c++ boost graph

我正在处理一个巨大的静态图,然后发现boost :: compressed_sparse_row_graph非常符合我的要求。我尝试使用下面的一些代码启动图形;

typedef uint32_t vertex_id;
typedef uint32_t edge_id;

struct MyVertex{
    vertex_id id;
// and other attributions
}

struct MyEdge{
    edge_id id;
//and other attributions
}

// graph define
typedef boost::compressed_sparse_row_graph<
        boost::bidirectionalS,
        MyVertex,
        MyEdge,
        boost::no_property,
        vertex_id,
        edge_id
> graph_t

std::vector<MyVertex> vertex_vector;
std::vector<MyEdge> edge_vector;

//this is the graph connection vertex_id->edge_id->vertex_id
std::unordered_map<vertex_id, std::unordered_map<vertex_id, edge_id>> out_adj; 

// init above from file ...

graph_t my_graph;

//add vertex
for (uint32_t i = 0; i < vertex_vector.size(); ++i) {
    vertex_id this_vertex_id = boost::add_vertex(my_graph, vertex_vector[i]);
    assert(i==this_vertex_id);
}

但是我对boost :: add_edges感到困惑,并且boost文档晦涩难懂。如何添加具有特定索引的边?任何人都可以给出有效的初始化代码吗?以及初始化后如何通过索引访问顶点/边缘。

0 个答案:

没有答案