boost graph libaray: my own note(1)

本文介绍了一个使用Boost库实现的图遍历示例,包括深度优先搜索、广度优先搜索及拓扑排序等算法,并展示了如何定义图结构以及访问顶点和边。

进来看就正常了。。小BS下CSDN博客。。。

#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/depth_first_search.hpp>
#include <boost/graph/graph_traits.hpp>
#include <boost/graph/topological_sort.hpp>
#include <boost/graph/breadth_first_search.hpp>
#include <string>
#include <utility>
#include <iostream>
#include <iterator>
#include <deque>

using namespace std;
using namespace boost;

typedef property<vertex_name_t, string> VertexNameProperty;
typedef adjacency_list<vecS, vecS, directedS, VertexNameProperty>  MyGraph;
typedef graph_traits<MyGraph>::vertex_iterator VertexIterator;
typedef pair<VertexIterator, VertexIterator> VerIterPair;
typedef graph_traits<MyGraph>::edge_descriptor Edge;
typedef graph_traits<MyGraph>::edge_iterator EdgeIter;
typedef property_map<MyGraph, vertex_index_t>::type MapIndex;
typedef property_map<MyGraph, vertex_name_t>::type NameArray;
typedef graph_traits<MyGraph>::vertex_descriptor Vertex;
typedef deque<Vertex> VertexArray;
typedef back_insert_iterator<VertexArray> BackIter;

template<class Name>
struct GetName
{
 const Name& name;
 GetName(const NameArray& name):name(name){}
 string operator()(int i) const
 {
  return name[i];
 }
};

template <typename OutputIterator>
class MyBFSVisitor : public default_bfs_visitor
{
public:
 MyBFSVisitor(OutputIterator iter) : iter(iter){}
 OutputIterator iter;
 template < typename Vertex, typename Graph >
  void discover_vertex(Vertex u, const Graph & g)
 {
  *iter++=u;
 }
};

template<class Graph, class Name>
void VisitAllVertex(const Graph& graph, const Name& name)
{
 cout<<"--------Visit all vertex--------"<<endl;
 MapIndex index = get(vertex_index, graph);
 for(VerIterPair vp=vertices(graph); vp.first!=vp.second; ++vp.first){
  cout<<"Vertex "<<index[*vp.first]<<":"<<name[*vp.first]<<endl;
 }
}

template<class Graph>
void VisitAllEdge(const Graph& graph)
{
 cout<<"--------Visit all edge--------"<<endl;
 EdgeIter first, last;
 for(tie(first, last)=edges(graph); first!=last; ++first){
  cout<<"Edge: "<<*first<<endl;
 }
}

template<class Graph, class Name>
void TopologicalSort(const Graph& graph, const Name& name)
{
 cout<<"--------Topological sort--------"<<endl;
 VertexArray vertexs;
 topological_sort(graph, front_insert_iterator<VertexArray>(vertexs) );
 transform(vertexs.begin(), vertexs.end(),
  ostream_iterator<string>(cout, "/n"),
  GetName<Name>(name) );
}

template<class Graph, class Vertex, class Name>
void BFS(const Graph& graph, const Vertex& v0, const Name& name)
{
 cout<<"--------BFS--------"<<endl;
 VertexArray vertexs;
 MyBFSVisitor<BackIter> vis=BackIter(vertexs);
 breadth_first_search(graph, v0, visitor(vis) );
 transform(vertexs.begin(), vertexs.end(),
  ostream_iterator<string>(cout, "/n"),
  GetName<Name>(name) );
}

int main(int argc,char* argv[])
{
 //Graph Construction
 MyGraph graph;
 NameArray name=get(vertex_name, graph);

 Vertex v0, v1, v2, v3, v4, v5;
 v0=add_vertex(graph);
 v1=add_vertex(graph);
 v2=add_vertex(graph);
 v3=add_vertex(graph);
 v4=add_vertex(graph);
 v5=add_vertex(graph);
 name[v0]="起床";
 name[v1]="看书";
 name[v2]="吃饭";
 name[v3]="午睡";
 name[v4]="游泳";
 name[v5]="上网";

 Edge e1=(add_edge(v0, v1, graph)).first;
 Edge e2=(add_edge(v0, v2, graph)).first;
 Edge e3=(add_edge(v0, v5, graph)).first;
 Edge e4=(add_edge(v1, v3, graph)).first;
 Edge e5=(add_edge(v2, v4, graph)).first;
 Edge e6=(add_edge(v3, v4, graph)).first;
 Edge e7=(add_edge(v4, v5, graph)).first;

 VisitAllVertex(graph, name);
 VisitAllEdge(graph);
 TopologicalSort(graph, name);
 BFS(graph, v0, name);

 system("pause");
 return 0;
}

源码链接: https://pan.quark.cn/s/dbe32f6bace6 在本指南中,我们将详细解析如何在银河麒麟v10操作系统平台上完成MySQL 5.7的安装过程。银河麒麟v10作为一个基于Linux内核的国产操作系统,特别适用于arm架构的aarch64计算平台。鉴于我们讨论的是免编译的安装方法,这意味着我们将借助预先编译好的二进制软件包来简化操作步骤,而非采用从源代码开始的编译方式。 ### 一、前期准备 1. **系统更新**: 在部署任何新软件之前,务必确保操作系统处于最新状态,此举旨在规避潜在的兼容性挑战和已知的安全隐患。 ``` sudo apt-get update sudo apt-get upgrade ``` 2. **依赖安装**: MySQL 5.7版本在运行时可能需要特定的库文件支持,比如libaio和jemalloc。在银河麒麟v10环境中,可以通过以下指令来安装这些必需的依赖项: ``` sudo apt-get install libaio1 libaio-dev jemalloc-dev ``` ### 二、获取MySQL 5.7二进制文件 由于银河麒麟v10运行在arm架构之上,因此需要寻找适配aarch64架构的MySQL 5.7二进制文件。这些文件可从MySQL的官方发布渠道或授权的第三方镜像站点获取。务必确认下载的文件名与压缩包内的内容一致。例如,文件名应为`mysql-5.7.37-linux-glibc2.17-arm64.tar.gz`。 ### 三、部署MySQL 5.7 1. **文件解压缩**: 将下载的MySQL压缩文件解压至一个指定目录,例如 `/usr/local/`。 ``` tar...
下载代码方式:https://pan.quark.cn/s/a4b39357ea24 Node.js 是一种开放源代码且能够在多种操作系统上运行的 JavaScript 执行环境,它使得开发人员能够在服务器端执行 JavaScript 代码。Node.js 采用了 V8 引擎,该引擎是由 Google 为 Chrome 浏览器开发的一个高性能的 JavaScript 解释器。Node.js 的 16.x 版本在其发展历程中占据着重要位置,其中包含了众多新功能以及性能上的改进。标题 "Nodejs16-x64 windows安装包" 指向的是专为 Windows 操作系统设计的 64 位版本的 Node.js 16 安装程序。在 Windows 平台上安装 Node.js 的 64 位版本对于处理大量数据或运行需要高性能的应用程序来说尤为关键,因为 64 位系统能够更有效地利用硬件资源。描述 "Nodejs-16 x64位windows 安装包" 明确了该安装程序是为 Windows 用户准备的,特别是对于那些需要运行 64 位应用程序的用户。x64 表明该版本兼容 64 位架构,意味着它能够充分利用 64 位计算机的内存和处理能力。标签 "Node Nodejs nodejs16" 提供了关于此安装包的核心信息,表明它与 Node.js 相关,并且具体指的是 v16 版本。这些标签有助于进行搜索和分类,从而方便用户找到他们所需要的特定版本。压缩包文件 "node-v16.18.0-x64.msi" 代表实际的安装文件,其中 "v16.18.0" 指示了 Node.js 的具体版本号,"x64" 再次强调了其适用于 64 位系统,而 ".msi" 后缀表明这是一...
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值