BGL的另一个中介中心性问题
Yet another BGL's Betweenness centrality issue
根据这个回复,我尝试实现Betweenness中心性,如下所示:
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]
编辑
#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
编译,返回的错误为:
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
我该怎么解决这个问题?提前感谢
Jackb,这个BGL算法和BGL中的许多其他算法一样,需要一个"顶点索引属性映射"——图顶点集和区间[0,num_vertices(g))
内整数之间的一对一映射。
现在,您的结构EProp和VProp不能用作vertex_index属性映射的替代品,这就是导致编译错误的原因。
如果可以使用boost::adjacency_list<boost::vecS, ...>
作为图类型,则vertex_index映射将免费提供(作为图的内部属性)。然后,您将能够以引用线程centrality_map(num_vertices(g), get(boost::vertex_index, g));
中的调用方式调用中心性算法。
如果由于某些原因无法使用boost::vecS,则必须自己组织映射。对于setS和listS,这里讨论了如何使用boost::将listS、setS作为顶点/边容器的图算法?及其参考文献。
请参阅此处属性地图的相关讨论BOOST中的属性地图是什么?特别是在vertex_index映射上:Dijkstra最短路径,其中VertexList=提升图中的ListS
相关文章:
- 存储另一个函数返回的布尔数组时遇到问题
- c++问题:给一个变量赋值后,另一个变量发生了变化
- 在另一个类中创建类实例时出现问题
- 使用另一个函数调用一个函数(都在类中)时出现问题.没有错误代码C++
- 缺少类型说明符和另一个问题
- 将四元数旋转的游戏对象旋转另一个四元数时出现问题
- 编译问题 C++ 同时,尝试通过调用另一个对象中的成员函数来创建 std:: 线程
- 从另一个应用启动我的应用时出现相对路径更改问题
- 提升线程问题,当一个线程与另一个线程没有相同的副本时如何共享变量?
- C BITSHIFT导致另一个变量引起问题
- C++中嵌套在另一个 LinkedList 中的 LinkedList 整数上的回调函数问题
- 问题:字符串在另一个字符串上写入
- 专用纯虚拟模板函数(未定义引用)的另一个问题
- 将一个STL向量有效地分配给另一个STL矢量(WSL问题)
- "{"令牌 c++ 继承问题之前的另一个预期类名
- 宣布时的另一个'not declared in this scope'问题
- C++初始化包含另一个对象设计问题的对象
- 在Qt和C++中从另一个应用程序启动一个应用软件会产生问题
- 另一个模板循环依赖问题
- 我在从另一个类调用主函数时遇到问题