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++标准库 ...
随机推荐
- Understanding continuations
原文地址http://fsharpforfunandprofit.com/posts/computation-expressions-continuations/ 上一篇中我们看到复杂代码是如何通过使 ...
- storm.yaml 配置项
配置项 配置说明 storm.zookeeper.servers ZooKeeper服务器列表 storm.zookeeper.port ZooKeeper连接端口 storm.local.dir s ...
- 转载–移动互联网终端的touch事件,touchstart, touchend, touchmove
转载请注明: 转载自WEB前端开发(www.css119.com)-关注常见的WEB前端开发问题.最新的WEB前端开发技术(webApp开发.移动网站开发).最好的WEB前端开发工具和最全的WEB前端 ...
- PHP ajax 限制 API 来源限制
if(isset($_SERVER["HTTP_X_REQUESTED_WITH"]) && strtolower($_SERVER["HTTP_X_RE ...
- jvm工具的使用
打开Java VisualVm->工具->插件 如图: 关于要填写的URL地址到 http://visualvm.java.net/pluginscenters.html 找到jdk版本 ...
- Ubuntu14.04下安装redis
1.首先在官网上下载redis压缩包 redis-3.2.0.tar.gz 2.解压到到当前文件夹(这里可以解压到随意位置) tar zvxf redis-3.2.0.tar.gz 3.切换到redi ...
- 华硕笔记本怎么进入PE之前的BIOS设置
1.先要制作一个U盘的PE启动盘,建议使用WIN8 PE 2.将制作好的PE启动盘接上电脑,开机按F2键进入BIOS ,先将[Secure]菜单下[Secure Boot Control]选项设置为[ ...
- G - 小晴天老师系列——可恶的墨水瓶
G - 小晴天老师系列——可恶的墨水瓶 Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Othe ...
- websphere安装验证报错 忘记密码的配置
http://blog.csdn.net/yulimin/article/details/4048897 ADMU7704E: 在尝试启动与服务器相关联的 Windows 服务时失败:server1: ...
- POJ 2062 HDU 1528 ZOJ 2223 Card Game Cheater
水题,感觉和田忌赛马差不多 #include<cstdio> #include<cstring> #include<cmath> #include<algor ...