图算法系列一 boost graph Algorithm基本使用
由于传统卷积神经网络CNN一般处理
欧式空间的
数据,但是有些非欧式空间的数据如社交网络,实体关系等都是拓扑空间,具备拓扑结构
,其基础理论是图,因此本文详细介绍图算法以及boost graph algorithm的应用
1.1 计算顶点数目
// Counting the number of vertices#include <cassert>
#include <boost/graph/adjacency_list .hpp>
template <typename graph>
int get_n_vertices(const graph& g) {const int n{static_cast<int>(boost :: num_vertices(g))};
assert (static_cast<unsigned == boost :: num_vertices(g) );
return n;
}
注:boost :: num_vertices 即可以针对有向图也可以计算无向图的顶点个数
1.2 计算边的条数
// Counting the number of edges
#include <cassert>
#include <boost/graph/adjacency_list .hpp>
template <typename graph>
int get_n_edges(const graph& g) noexcept {const int n{static_cast<int>(boost ::num_edges(g))};
assert (static_cast<unsigned == boost :: num_edges(g) );
return n;}
注:boost :: num_edges 即可以针对有向图也可以计算无向图的边个数
1.3 添加顶点
#include <type_traits>
#include <boost/graph/adjacency_list .hpp>
template <typename graph>
typename boost::graph_traits<graph >::vertex_descriptor
add_vertex(graph& g)
{static_assert( !std::is_const<graph>::value , "graph cannot be const");const auto vd = boost::add_vertex(g); return vd ;
}
static_assert 用来检查是否是const 图,const无法添加节点,这个会在编译期报错,防止问题发生在run time。
1.4 添加边
#include <cassert>
#include <type_traits>
#include <boost/graph/adjacency_list .hpp>
template <typename graph>
typename boost::graph_traits<graph >:: edge_descriptor
add_edge(graph& g) {static_assert( !std::is_const <graph>::value , "graph cannot be const"
);
const auto vd_a = boost::add_vertex(g);
const auto vd_b = boost::add_vertex(g);
const auto aer = boost::add_edge(vd_a , vd_b , g );
assert ( aer.second ) ;
return aer.first ;
}
【Reference】
- boost_graph_cookbook_1.pdf
图算法系列一 boost graph Algorithm基本使用相关推荐
- boost::graph模块实现二分图算法的测试程序
boost::graph模块实现二分图算法的测试程序 实现功能 C++实现代码 实现功能 boost::graph模块实现二分图算法的测试程序 C++实现代码 #include <iostrea ...
- Boost Graph Library 快速入门
Boost Graph Library 快速入门 图领域的数据结构和算法在某些方面比容器更为复杂,图算法在图中移动有着众多的路线,而STL使用的抽象迭代器接口不能有效的支持这些.作为替换,我们为图提供 ...
- boost::graph模块演示 GGCL Vertex 接口
boost::graph模块演示 GGCL Vertex 接口 实现功能 C++实现代码 实现功能 boost::graph模块演示 GGCL Vertex 接口 C++实现代码 #include & ...
- boost::graph模块实现内部属性图的测试程序
boost::graph模块实现内部属性图的测试程序 实现功能 C++实现代码 实现功能 boost::graph模块实现内部属性图的测试程序 C++实现代码 #include <boost/c ...
- boost::graph模块实现内部pmap捆绑的测试程序
boost::graph模块实现内部pmap捆绑的测试程序 实现功能 C++实现代码 实现功能 boost::graph模块实现内部pmap捆绑的测试程序 C++实现代码 #include <b ...
- boost::graph模块使用breadth_first_search()实现GGCL算法的测试程序
boost::graph模块使用breadth_first_search实现GGCL算法的测试程序 实现功能 C++实现代码 实现功能 boost::graph模块使用breadth_first_se ...
- boost::graph模块演示 GGCL Edge 接口
boost::graph模块演示 GGCL Edge 接口 实现功能 C++实现代码 实现功能 boost::graph模块演示 GGCL Edge 接口 C++实现代码 #include <b ...
- Boost Graph
图论是一种数学抽象,它对于解决多种计算机科学问题是非常有用的,Boost.Graph提供了一个基于图论的通用编程接口. Boost.Graph是一个图的封装,在<数据结构>的教科书里,一般 ...
- 【转】使用Boost Graph library(二)
原文转自:http://shanzhizi.blog.51cto.com/5066308/942972 让我们从一个新的图的开始,定义一些属性,然后加入一些带属性的顶点和边.我们将给出所有的代码,这样 ...
最新文章
- python【蓝桥杯vip练习题库】ADV-105 不同单词个数统计(集合)
- EasyGui的用法简介
- 无法定位程序输入点 在.exe上_win7提示explorer.exe应用程序错误的解决方法
- python3.5 连接mysql_python3.5 連接mysql本地數據庫
- 《『若水新闻』客户端开发教程》——06.设计新闻内容UI
- 88.http反向代理proxy处理请求的流程
- 如何禁用Web表单字段/输入标签上的浏览器自动完成功能?
- mockito 静态方法_Mockito模拟静态方法– PowerMock
- 【笔记】生成函数与大背包问题
- vant toast 指定挂载到指定位置_文档如何只允许编辑指定位置?2步限制编辑,保护文档不被修改...
- css3径向渐变详解-遁地龙卷风
- 计算机无法打开文档,电脑txt文件打不开怎么办-修复电脑中无法打开txt文档的方法 - 河东软件园...
- 计算机开机时10声响,电脑开机报警的声音有什么含义?详细教您认识报警声音
- 【java】使用Stanford CoreNLP处理英文(词性标注/词形还原/解析等)
- fabs linux头文件,C/C++ algorithm头文件的max()、min()、abs()和math头文件的fabs(
- android 外边距,外边距(padding)重叠的及解决办法
- 手绘vs码绘 动态对比
- 痛心,拼多多一程序员在家跳楼自杀!发生了什么?
- ARM结构体系和接口技术
- html中怎么制作选择头像,网页中的个人头像选择框(转)