Boost的图库如何链接顶点和外边列表容器?

时间:2014-07-29 22:30:34

标签: boost graph containers

根据Boost's documentation,顶点有两种主要的容器类型及其对应的外边缘,默认为两者的向量。

两者之间是否存在任何链接,就像地图一样,键是顶点,值是传出边的矢量?或者你知道每个顶点指向的是什么,因为顶点在顶点列表中存储为唯一的int,其中每个顶点就像是某种向量向量的索引,其中每个向量都包含该向量的传出边缘顶点?

基本上,如何将顶点链接到Boost邻接列表中相应的传出边列表?

1 个答案:

答案 0 :(得分:1)

邻接列表中的每个顶点项(称为stored_vertex)都有一个出边的容器,如果是双向的,则在边上。以下是stored_vertex的各种风格的定义:

    // stored_vertex and StoredVertexList
    typedef typename container_gen<VertexListS, vertex_ptr>::type
      SeqStoredVertexList;
    struct seq_stored_vertex {
      seq_stored_vertex() { }
      seq_stored_vertex(const VertexProperty& p) : m_property(p) { }
      OutEdgeList m_out_edges;
      VertexProperty m_property;
      typename SeqStoredVertexList::iterator m_position;
    };
    struct bidir_seq_stored_vertex {
      bidir_seq_stored_vertex() { }
      bidir_seq_stored_vertex(const VertexProperty& p) : m_property(p) { }
      OutEdgeList m_out_edges;
      InEdgeList m_in_edges;
      VertexProperty m_property;
      typename SeqStoredVertexList::iterator m_position;
    };
    struct rand_stored_vertex {
      rand_stored_vertex() { }
      rand_stored_vertex(const VertexProperty& p) : m_property(p) { }
      OutEdgeList m_out_edges;
      VertexProperty m_property;
    };
    struct bidir_rand_stored_vertex {
      bidir_rand_stored_vertex() { }
      bidir_rand_stored_vertex(const VertexProperty& p) : m_property(p) { }
      OutEdgeList m_out_edges;
      InEdgeList m_in_edges;
      VertexProperty m_property;
    };

    //! This generates the actual stored_vertex type based on 
    //! the container type.
    typedef typename mpl::if_<is_rand_access,
      typename mpl::if_<BidirectionalT,
        bidir_rand_stored_vertex, rand_stored_vertex>::type,
      typename mpl::if_<BidirectionalT,
        bidir_seq_stored_vertex, seq_stored_vertex>::type
    >::type StoredVertex;
    struct stored_vertex : public StoredVertex {
      stored_vertex() { }
      stored_vertex(const VertexProperty& p) : StoredVertex(p) { }
    };

如果顶点的列表类型是随机访问,则vertex_descriptor类型是std :: size_t,并表示stored_vertex个实例的向量中顶点的索引。如果列表类型是基于节点的序列(如列表),则vertex_descriptor是stored_vertex的内存地址(强制转换为void *)。这两种情况都提供从vertex_descriptor到底层O(n)的{​​{1}}映射,从而提供到关联的边缘列表。

相关问题