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++标准库 ...
随机推荐
- informix建临时表索引
对于特殊字段,比如外键,主键,在不知道外键主键名的情况下,需要如下操作select constrname from sysconstraints where constrtype='R' and ta ...
- LeetCode OJ 85. Maximal Rectangle
Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and ...
- WebService 调用三种方法
//来源:http://www.cnblogs.com/eagle1986/archive/2012/09/03/2669699.html 最近做一个项目,由于是在别人框架里开发app,导致了很多限制 ...
- 【卷一】正则一 之re.split
有时候,用re.split()匹配字符串会比findall,search, match等 正则表达式对象方法方便简洁很多! 参考: <Python核心编程(3rd)>—p23 如果给定分隔 ...
- 关于oracle数据库(5)增删改查
添加.修改.删除.查询都叫SQL语言(结构化查询语言) 添加数据(注意事项:列的顺序和值的顺序要相同.数量也要相同:字符串要加单引号,数字可以加或不加) insert into 表名(列名,列名,列名 ...
- 通过实例来理解ajax
点击一个按钮,然后将信息显示到指定的div内. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"& ...
- Python字符串连接方式
python中有很多字符串连接方式,总结一下: 1 最原始的字符串连接方式:str1 + str22 python 新字符串连接语法:str1, str23 奇怪的字符串方式:str1 str24 % ...
- 管理MySQL的命令
USE 数据库名 :选择要操作的Mysql数据库,使用该命令后所有Mysql命令都只针对该数据库. SHOW DATABASES: 列出 MySQL 数据库管理系统的数据库列表. SHOW TABLE ...
- sql语句判断两个时间段是否有交集
场景: 数据库有有两个字段.开始时间<startTime>,和结束时间<endTime>,指定一个时间段(a,b),a表示开始时间,b表示结束时间.看数据库中有没有与(a,b ...
- sql身份证号查人数
select a.*,b.item_name from (select sum(buy_num) num,nqh from (select substr(a.embed_dis_province,1, ...