boost库之graph入门
#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;
}
}
}
boost库之graph入门的更多相关文章
- Boost库学习之旅入门篇
学习及使用Boost库已经有一段时间了,Boost为我的日常开发中带来了极大的方便,也使得我越来越依赖于boost库了.但boost功能太多,每次使用还是得翻看以前的 资料,所以为了以后可以更方便的使 ...
- boost库在windows下的编译和使用
因为跨平台的原因,现在要使用到boost库,boost库非常大,现在处于摸索阶段. 首先来说boost库在window下的安装和使用. 一.下载 首先从boost官方主页http://www.boos ...
- Win7下Boost库的安装
Boost库是C++领域公认的经过千锤百炼的知名C++类库,涉及编程中的方方面面,简单记录一下使用时的安装过程 1.boost库的下载 boost库官网主页:www.boost.org 2.安装 将下 ...
- Boost库
2014-08-31 Boost库是一个经过千锤百炼.可移植.提供源代码的C++库,作为标准库的后备,是C++标准化进程的发动机之一.Boost库由C++标准委员会库工作组成员发起,其中有些内容有望成 ...
- boost库的安装,使用,介绍,库分类
1)首先去官网下载boost源码安装包:http://www.boost.org/ 选择下载对应的boost源码包.本次下载使用的是 boost_1_60_0.tar.gz (2)解压文件:tar - ...
- VS2008编译boost库
一.下载首先从boost官方主页http://www.boost.org/下载最新版boost安装包,我用的版本是boost.1.49.0二.新建文件夹 如果是使用下载的安装包,那么请将boost安装 ...
- VS2008下直接安装使用Boost库1.46.1版本号
Boost库是一个可移植.提供源码的C++库,作为标准库的后备,是C++标准化进程的发动机之中的一个. Boost库由C++标准委员会库工作组成员发起,当中有些内容有望成为下一代C++标准库内容.在C ...
- VS2008下直接安装使用Boost库1.46.1版本
Boost库是一个可移植.提供源代码的C++库,作为标准库的后备,是C++标准化进程的发动机之一. Boost库由C++标准委员会库工作组成员发起,其中有些内容有望成为下一代C++标准库内容.在C++ ...
- VS2008下直接安装Boost库1.46.1版本号
Boost图书馆是一个移植.提供源代码C++库.作为一个备份标准库,这是C++发动机之间的一种标准化的过程. Boost图书馆由C++图书馆标准委员会工作组成员发起,一些内容有望成为下一代C++标准库 ...
随机推荐
- Excel教程(13) - 统计函数
AVEDEV 用途:返回一组数据与其平均值的绝对偏差的平均值,该 函数可以评测数据(例如学生的某科考试成绩)的离散度. 语法:AVEDEV(number1,number2,...) 参数:Number ...
- KeyTweak(笔记本键盘设置工具) V2.20 中文版
软件名称: KeyTweak(笔记本键盘设置工具)软件语言: 简体中文授权方式: 免费软件运行环境: Win 32位/64位软件大小: 50KB图片预览: 软件简介:KeyTweak 通过设置系统的注 ...
- submit提交表单后,不刷新当前页面
<form method="get" target="test" action="a.html"> <input type ...
- Laravel框架开发规范-修订前期版
1.追加App/Models目录,App/User.php迁移至App/Models目录中 ①配置内容属于架构信息.服务器信息.有必要隐藏无法提交git的信息,请使用.env文件配合env()方法进行 ...
- MVC view视图获取Html.RenderAction方式带来的参数
通过Html.RenderAction这种方式传递的参数,在view视图中获取要使用viewContext上下文来获取:Html.ViewContext.RouteData.Values[" ...
- 委托的BeginInvoke和EndInvoke方法
.NET Framework 允许异步调用任何方法,为了实现异步调用目标,需要定义与被调用方法具有相同签名的委托.公共语言运行时会自动使用适当的签名为该委托定义 BeginInvoke 和 EndIn ...
- 学习multiprocessing
1. multiprocessing.Pool from multiprocessing.pool import Pool def gen_row(): ...return rows def main ...
- Eclipse/MyEclipse中常用快捷键总结
1.格式化代码: Ctrl+Shift+F; 2.自动生成get/set方法:Shifi+Alt+S+R(按下空格是选中). 3.自动生成toString方法:Shifi+Alt+S+S(按下空格是选 ...
- ios文本框基本使用,以及所有代理方法的作用
/* UITextField文本输入框 */ UITextField * textField = [[UITextField alloc]initWithFrame:CGRectMake(50, 50 ...
- Windows常用的监视数据指标