另一个BGL的中间中心问题 [英] Yet another BGL's Betweenness centrality issue

查看:399
本文介绍了另一个BGL的中间中心问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

借助回复, ve尝试实现Betweenness中心性如下:

Drawing on this reply, I've tried to implement the Betweenness centrality as follows:

typedef struct vpr_
{ 
    int id;         
} VProp;
typedef boost::adjacency_list<boost::listS, boost::listS, boost::undirectedS, VProp, EProp> graph_t;
boost::shared_array_property_map<double, boost::property_map<graph_t, int>::const_type> centrality_map(num_vertices(g), get(VProp::id, g));

但返回了以下错误。

In file included from /usr/local/include/boost/graph/adjacency_list.hpp:246:0,
             from /usr/local/include/boost/graph/random.hpp:23,
             from ../../src/graph/Graph.h:25,
             from Graph.cpp:23:
/usr/local/include/boost/graph/detail/adjacency_list.hpp: In instantiation of ‘struct boost::adj_list_any_vertex_pa::bind_<int, boost::adjacency_list<boost::listS, boost::listS, boost::undirectedS, vpr_, epr_>, vpr_>’:
/usr/local/include/boost/graph/detail/adjacency_list.hpp:2568:12:   required from ‘struct boost::detail::adj_list_choose_vertex_pa<int, boost::adjacency_list<boost::listS, boost::listS, boost::undirectedS, vpr_, epr_>, vpr_>’
/usr/local/include/boost/graph/detail/adjacency_list.hpp:2705:12:   required from ‘struct boost::adj_list_vertex_property_selector::bind_<boost::adjacency_list<boost::listS, boost::listS, boost::undirectedS, vpr_, epr_>, vpr_, int>’
/usr/local/include/boost/graph/properties.hpp:217:12:   required from ‘struct boost::detail::vertex_property_map<boost::adjacency_list<boost::listS, boost::listS, boost::undirectedS, vpr_, epr_>, int>’
/usr/local/include/boost/graph/properties.hpp:228:10:   required from ‘struct boost::property_map<boost::adjacency_list<boost::listS, boost::listS, boost::undirectedS, vpr_, epr_>, int>’
Graph.cpp:374:76:   required from here
/usr/local/include/boost/graph/detail/adjacency_list.hpp:2498:29: error: forming reference to void
/usr/local/include/boost/graph/detail/adjacency_list.hpp:2499:35: error: forming reference to void
/usr/local/include/boost/graph/detail/adjacency_list.hpp:2502:47: error: forming reference to void
/usr/local/include/boost/graph/detail/adjacency_list.hpp:2504:53: error: forming reference to void
Graph.cpp: In member function ‘void Graph::getBetweennes()’:
Graph.cpp:374:88: error: template argument 2 is invalid
Graph.cpp:375:17: error: invalid type in declaration before ‘(’ token
In file included from ../../src/graph/graph_t.h:33:0,
             from ../../src/graph/Graph.h:26,
             from Graph.cpp:23:
../../src/graph/VProp.h:38:6: error: invalid use of non-static data member ‘vpr_::id’
Graph.cpp:375:46: error: from this location
Graph.cpp:375:52: error: expression list treated as compound expression in initializer [-fpermissive]

>

EDIT

#include <boost/graph/iteration_macros.hpp>
#include <boost/random/mersenne_twister.hpp>
#include <boost/graph/random.hpp> 

typedef struct vpr_
{ 
    int id;         
} VProp;
typedef struct epr_
{ 
    int id;         
} EProp;
typedef boost::adjacency_list<boost::listS, boost::listS, boost::undirectedS, VProp, EProp> graph_t;


int main(void) {
    graph_t g;
    boost::shared_array_property_map<double, boost::property_map<graph_t,  VProp::*>::const_type> centrality_map(num_vertices(g), get(&VProp::id, g));
}

代码已编译为 g ++ -L / usr / local / lib -lboost_graph gtest.cpp ,返回的错误是:

The code has been compiled with g++ -L/usr/local/lib -lboost_graph gtest.cpp, and the returned error is:

 gtest.cpp: In function ‘int main()’:
 gtest.cpp:18:81: error: template argument 2 is invalid
 gtest.cpp:18:94: error: template argument 2 is invalid
 gtest.cpp:18:110: error: invalid type in declaration before ‘(’ token
 gtest.cpp:18:146: error: expression list treated as compound expression in initializer [-fpermissive]
 gtest.cpp:18:146: error: cannot convert ‘boost::adj_list_any_vertex_pa::bind_<int vpr_::*, boost::adjacency_list<boost::listS, boost::listS, boost::undirectedS, vpr_, epr_>, vpr_>::type {aka boost::adj_list_vertex_property_map<boost::adjacency_list<boost::listS, boost::listS, boost::undirectedS, vpr_, epr_>, int, int&, int vpr_::*>}’ to ‘int’ in initialization

如何解决这个问题? / p>

How could I fix this? Thanks in advance

推荐答案

Jackb,这个BGL算法像许多其他在BGL中需要一个顶点索引属性映射 - 一对一在 [0,num_vertices(g))中的图顶点集和整数之间的映射。

Jackb, this BGL algorithm like many others in BGL requires a "vertex index property map" -- a one-to-one mapping between set of graph vertices and integer numbers within interval [0,num_vertices(g)).

现在,您的结构EProp和VProp不能用作vertex_index属性映射的替代,而是导致编译错误的原因。

Now, your structures EProp and VProp cannot be used as substitutes for vertex_index property maps, and it is what causes the compilation errors.

如果你可以使用 boost :: adjacency_list< boost :: vecS,...> 作为图表类型,那么vertex_index映射将会免费(作为图表的内部属性)。然后,你将能够调用中心性算法在你的引用线程中调用的方式: centrality_map(num_vertices(g),get(boost :: vertex_index,g));

If you can use boost::adjacency_list<boost::vecS, ...> as your graph type, then vertex_index mapping will come for free (as internal property of the graph). Then you will be able to call centrality algorithms the way it is called in your referenced thread: centrality_map(num_vertices(g), get(boost::vertex_index, g));.

如果由于某些原因你不能使用boost :: vecS,你必须自己组织映射。对于setS和listS,此处进行讨论如何使用带有listS的boost :: graph算法,setS作为顶点/边缘容器?及其引用。

If for some reasons you cannot use boost::vecS, you have to organize the mapping yourself. For setS and listS it is discussed here How to use boost::graph algorithms with listS, setS as vertex/edge containers? and references thereof.

查看有关地图的相关讨论什么是BOOST中的属性映射?,特别是在vertex_index映射上: Dijkstra最短路径与顶点列表=在升压图中的列表

See related discussions on Property Map here What is a property map in BOOST? and specifically on vertex_index map here: Dijkstra Shortest Path with VertexList = ListS in boost graph

这篇关于另一个BGL的中间中心问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆