【问题标题】:Boost Graph Library C++/ Power LawBoost 图形库 C++/幂律
【发布时间】:2014-04-08 05:53:13
【问题描述】:

我有一个带有 id、x 和 y 坐标的顶点向量,我想为我的顶点生成一个幂律图。 Boost 库图提供了幂律 plod_iterator() 但我怎样才能用我的顶点生成它。有人可以帮忙吗?

【问题讨论】:

    标签: c++ boost boost-graph power-law


    【解决方案1】:

    Boost 文档指出这些是生成器。

    “此类模板使用幂律输出度 (PLOD) 算法实现了无标度图生成器”(http://www.boost.org/doc/libs/1_55_0/libs/graph/doc/plod_generator.html)

    它说迭代器有点令人困惑。

    我会用您的数据创建一个结构向量,然后生成一个具有相同数量节点的幂律图。

    根据 boost 文档修改:

    #include <boost/graph/adjacency_list.hpp>
    #include <boost/graph/plod_generator.hpp>
    #include <boost/random/linear_congruential.hpp>
    
    struct VertData{
      size_t id;
      size_t x;
      size_t y;
    };
    
    typedef boost::adjacency_list<> Graph;
    typedef boost::plod_iterator<boost::minstd_rand, Graph> SFGen;
    
    int main()
    {
    
      vector<VertData> vertData;
      //... Initialize with data ...
    
    
      boost::minstd_rand gen;
      // Create graph with 100 nodes 
      Graph g(SFGen(gen, 100, 2.5, 1000), SFGen(), 100);
    
    
      typedef property_map<Graph, vertex_index_t >::type VertexIndexMap;
      VertexIndexMap iMap = get(vertex_index,g);
      // ... get some vertex v
      size_t vertexIndex = iMap[v];
      //...
      vertexData.at(vertexIndex).x = 4;//or what ever
    
    
    
      return 0;
    }
    

    这里将使用 2.5 的幂律指数设置一个包含 100 个节点的无标度图。

    然后,当您想要访问节点的数据时,只需访问其索引并在您的结构向量中进行查找。你可以这样获取索引:

    typedef property_map<Graph, vertex_index_t >::type VertexIndexMap;
    VertexIndexMap iMap = get(vertex_index,g);
    size_t vertexIndex = iMap[v];
    ...
    vertexData.at(vertexIndex).x = 4;//or what ever
    

    这可能不是绝对最好的方法,但它使我能够完成我的工作。

    【讨论】:

      猜你喜欢
      • 2011-01-07
      • 2012-02-07
      • 2011-03-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多