boost库之graph入门
来源:互联网 发布:apache 隐藏index.php 编辑:程序博客网 时间:2024/04/27 20:27
#include <boost/graph/undirected_graph.hpp>#include <boost/graph/adjacency_list.hpp>using namespace std;int _tmain(int argc, _TCHAR* argv[]){// 创建简单无向图//typedef boost::adjacency_list<boost::lists boost::undirecteds="" boost::vecs=""> Graph;/*Graph g;// 添加边 boost::add_edge(0, 1, g);boost::add_edge(0, 3, g);boost::add_edge(1, 2, g);boost::add_edge(2, 3, g);cout << "Number of edges: " << boost::num_edges(g) << endl;// 边的数量cout << "Number of vertices: " << boost::num_vertices(g) << endl;// 顶点的数量Graph::vertex_iterator vertexIt,vertexEnd;// 顶点Graph::adjacency_iterator neighbourIt, neighbourEnd;// 邻接边boost::tie(vertexIt, vertexEnd) = boost::vertices(g);for (; vertexIt != vertexEnd; ++vertexIt) {std::cout << "edge vertex " << *vertexIt << std::endl;// 输出顶点的入边Graph::in_edge_iterator inedgeIt, inedgeEnd;boost::tie(inedgeIt, inedgeEnd) = boost::in_edges(*vertexIt, g);std::cout << "in edge: ";for (; inedgeIt != inedgeEnd; ++inedgeIt) {std::cout << *inedgeIt << " ";}std::cout << std::endl;// 输出顶点的出边Graph::out_edge_iterator outedgeIt, outedgeEnd;boost::tie(outedgeIt, outedgeEnd) = boost::out_edges(*vertexIt, g);std::cout << "out edge: ";for (; outedgeIt != outedgeEnd; ++outedgeIt) {std::cout << *outedgeIt << " ";}std::cout << std::endl;}*/// 创建无向图,并使用顶点和边的属性// 顶点属性typedef boost::property<boost::vertex_name_t std::string=""> VertexNameProp;// 边属性typedef boost::property<boost::edge_weight_t int=""> EdgeWeightProp;// 图typedef boost::adjacency_list<boost::lists boost::vecs="" boost::undirecteds="" vertexnameprop="" edgeweightprop=""> Graph;Graph g;std::string citys[4] = {"北京", "上海", "武汉", "西安"};Graph::vertex_descriptor v[4];// 添加顶点v[0] = boost::add_vertex(citys[0], g);v[1] = boost::add_vertex(citys[1], g);v[2] = boost::add_vertex(citys[2], g);v[3] = boost::add_vertex(citys[3], g);// 添加边boost::add_edge(v[0], v[1], 10, g);boost::add_edge(v[0], v[2], 40, g);boost::add_edge(v[0], v[3], 50, g);Graph::vertex_iterator vertexIt, vertexEnd;// 顶点的属性boost::property_map<graph boost::vertex_name_t="">::type vertexprop = boost::get(boost::vertex_name, g);// 边的属性boost::property_map<graph boost::edge_weight_t="">::type edgeprop = boost::get(boost::edge_weight, g);boost::tie(vertexIt, vertexEnd) = boost::vertices(g);for (; vertexIt != vertexEnd; ++vertexIt) {// 获取顶点属性std::string vprop = vertexprop[*vertexIt];// 设置顶点的属性 //vertexprop[*vertexIt] = "";Graph::out_edge_iterator outedgeIt, outedgeEnd;// 设置边属性boost::tie(outedgeIt, outedgeEnd) = boost::out_edges(*vertexIt, g);for (; outedgeIt != outedgeEnd; ++outedgeIt) {edgeprop[*outedgeIt] = 100;}}}
0 0
- boost库之graph入门
- Boost Graph Library 快速入门
- Boost Graph Library 快速入门
- Boost Graph Library 快速入门
- Boost Graph Library 快速入门
- Boost Graph Library 快速入门
- Boost Graph Library 快速入门
- (转)Boost Graph Library 快速入门
- [翻译]Boost Graph库简介
- Boost Graph
- Boost--Graph
- Boost库学习之旅入门篇
- 使用C++ Boost Graph Library 进行社交网络分析入门篇
- 一步一步学习 Boost 之 入门
- Boost 入门之3 - 格式化
- DirectShow入门之模拟构建Graph
- DirectShow入门之模拟构建Graph
- DirectShow入门之模拟构建Graph
- 关于 ubuntu 12.04 无法使用QQ的问题
- 四川大学线下编程比赛第一题:数字填充
- 打印华氏温度与摄氏温度的对应关系
- 关于利用js实现css切换布局视图的方法
- 二元查找树转化成排序的双向链表——要求不创建新的节点
- boost库之graph入门
- 语音信号的预处理
- 作为大型网站架构必须考虑的十大问题
- 我的第一篇CSDN博客
- fatal error LNK1168如何避免
- 结构体优先队列
- 自己动手编写嵌入式Bootloader之(1)
- Bootstrap3学习笔记
- 1加到N