由于传统卷积神经网络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】

  1. boost_graph_cookbook_1.pdf

图算法系列一 boost graph Algorithm基本使用相关推荐

  1. boost::graph模块实现二分图算法的测试程序

    boost::graph模块实现二分图算法的测试程序 实现功能 C++实现代码 实现功能 boost::graph模块实现二分图算法的测试程序 C++实现代码 #include <iostrea ...

  2. Boost Graph Library 快速入门

    Boost Graph Library 快速入门 图领域的数据结构和算法在某些方面比容器更为复杂,图算法在图中移动有着众多的路线,而STL使用的抽象迭代器接口不能有效的支持这些.作为替换,我们为图提供 ...

  3. boost::graph模块演示 GGCL Vertex 接口

    boost::graph模块演示 GGCL Vertex 接口 实现功能 C++实现代码 实现功能 boost::graph模块演示 GGCL Vertex 接口 C++实现代码 #include & ...

  4. boost::graph模块实现内部属性图的测试程序

    boost::graph模块实现内部属性图的测试程序 实现功能 C++实现代码 实现功能 boost::graph模块实现内部属性图的测试程序 C++实现代码 #include <boost/c ...

  5. boost::graph模块实现内部pmap捆绑的测试程序

    boost::graph模块实现内部pmap捆绑的测试程序 实现功能 C++实现代码 实现功能 boost::graph模块实现内部pmap捆绑的测试程序 C++实现代码 #include <b ...

  6. boost::graph模块使用breadth_first_search()实现GGCL算法的测试程序

    boost::graph模块使用breadth_first_search实现GGCL算法的测试程序 实现功能 C++实现代码 实现功能 boost::graph模块使用breadth_first_se ...

  7. boost::graph模块演示 GGCL Edge 接口

    boost::graph模块演示 GGCL Edge 接口 实现功能 C++实现代码 实现功能 boost::graph模块演示 GGCL Edge 接口 C++实现代码 #include <b ...

  8. Boost Graph

    图论是一种数学抽象,它对于解决多种计算机科学问题是非常有用的,Boost.Graph提供了一个基于图论的通用编程接口. Boost.Graph是一个图的封装,在<数据结构>的教科书里,一般 ...

  9. 【转】使用Boost Graph library(二)

    原文转自:http://shanzhizi.blog.51cto.com/5066308/942972 让我们从一个新的图的开始,定义一些属性,然后加入一些带属性的顶点和边.我们将给出所有的代码,这样 ...

最新文章

  1. python【蓝桥杯vip练习题库】ADV-105 不同单词个数统计(集合)
  2. EasyGui的用法简介
  3. 无法定位程序输入点 在.exe上_win7提示explorer.exe应用程序错误的解决方法
  4. python3.5 连接mysql_python3.5 連接mysql本地數據庫
  5. 《『若水新闻』客户端开发教程》——06.设计新闻内容UI
  6. 88.http反向代理proxy处理请求的流程
  7. 如何禁用Web表单字段/输入标签上的浏览器自动完成功能?
  8. mockito 静态方法_Mockito模拟静态方法– PowerMock
  9. 【笔记】生成函数与大背包问题
  10. vant toast 指定挂载到指定位置_文档如何只允许编辑指定位置?2步限制编辑,保护文档不被修改...
  11. css3径向渐变详解-遁地龙卷风
  12. 计算机无法打开文档,电脑txt文件打不开怎么办-修复电脑中无法打开txt文档的方法 - 河东软件园...
  13. 计算机开机时10声响,电脑开机报警的声音有什么含义?详细教您认识报警声音
  14. 【java】使用Stanford CoreNLP处理英文(词性标注/词形还原/解析等)
  15. fabs linux头文件,C/C++ algorithm头文件的max()、min()、abs()和math头文件的fabs(
  16. android 外边距,外边距(padding)重叠的及解决办法
  17. 手绘vs码绘 动态对比
  18. 痛心,拼多多一程序员在家跳楼自杀!发生了什么?
  19. ARM结构体系和接口技术
  20. html中怎么制作选择头像,网页中的个人头像选择框(转)

热门文章

  1. 【firefox】最新浏览器无法添加组件firebug和firepath的方法
  2. R语言绘制布林带通道
  3. 无痛刷新token续接401请求
  4. 赶快收藏,关于PostgreSQL培训认证的问题都在这里。
  5. 是时候展现真正的技术了!Python二维码表白神器一秒生成!
  6. WKWebView1 加载带图文富文本
  7. 信息系统项目管理师2021年下半年下午案例分析题及答案
  8. PDM系统的产生及相关技术理论
  9. 松下A6伺服调试笔记
  10. 那些挂羊头卖狗肉的公司