#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入门的更多相关文章

  1. Boost库学习之旅入门篇

    学习及使用Boost库已经有一段时间了,Boost为我的日常开发中带来了极大的方便,也使得我越来越依赖于boost库了.但boost功能太多,每次使用还是得翻看以前的 资料,所以为了以后可以更方便的使 ...

  2. boost库在windows下的编译和使用

    因为跨平台的原因,现在要使用到boost库,boost库非常大,现在处于摸索阶段. 首先来说boost库在window下的安装和使用. 一.下载 首先从boost官方主页http://www.boos ...

  3. Win7下Boost库的安装

    Boost库是C++领域公认的经过千锤百炼的知名C++类库,涉及编程中的方方面面,简单记录一下使用时的安装过程 1.boost库的下载 boost库官网主页:www.boost.org 2.安装 将下 ...

  4. Boost库

    2014-08-31 Boost库是一个经过千锤百炼.可移植.提供源代码的C++库,作为标准库的后备,是C++标准化进程的发动机之一.Boost库由C++标准委员会库工作组成员发起,其中有些内容有望成 ...

  5. boost库的安装,使用,介绍,库分类

    1)首先去官网下载boost源码安装包:http://www.boost.org/ 选择下载对应的boost源码包.本次下载使用的是 boost_1_60_0.tar.gz (2)解压文件:tar - ...

  6. VS2008编译boost库

    一.下载首先从boost官方主页http://www.boost.org/下载最新版boost安装包,我用的版本是boost.1.49.0二.新建文件夹 如果是使用下载的安装包,那么请将boost安装 ...

  7. VS2008下直接安装使用Boost库1.46.1版本号

    Boost库是一个可移植.提供源码的C++库,作为标准库的后备,是C++标准化进程的发动机之中的一个. Boost库由C++标准委员会库工作组成员发起,当中有些内容有望成为下一代C++标准库内容.在C ...

  8. VS2008下直接安装使用Boost库1.46.1版本

    Boost库是一个可移植.提供源代码的C++库,作为标准库的后备,是C++标准化进程的发动机之一. Boost库由C++标准委员会库工作组成员发起,其中有些内容有望成为下一代C++标准库内容.在C++ ...

  9. VS2008下直接安装Boost库1.46.1版本号

    Boost图书馆是一个移植.提供源代码C++库.作为一个备份标准库,这是C++发动机之间的一种标准化的过程. Boost图书馆由C++图书馆标准委员会工作组成员发起,一些内容有望成为下一代C++标准库 ...

随机推荐

  1. Django中的权限系统

    Django中已经为我们设置好了基本的权限系统,在定义好model同步数据库后,在每个库下面都会有一张 'auth_permission' 表.该表里面记录了每条权限的描述(name字段,can do ...

  2. Python & virtualenv使用说明

    virtualenv是virtual environment的缩写,可以创建独立的Python环境,用起来比较干净:   安装(已安装pip 或者 easy_install): 如果使用pip: pi ...

  3. Vultr优惠码20美元享受20GB SSD和2T流量

    美国vps主机商vultr最新优惠码:20FOR30,只限新注册用户,点击注册链接,进入后台Billing,找到Gift code,输入20FOR30,点击apply,就能免费获得20美元的账户余额. ...

  4. MBProgressHUD详解

    1,MBProgressHUD常用属性和用法Demo - (void)testMBProgressHUD { NSLog(@"test MBProgressHUD "); /* 要 ...

  5. KeyTweak(笔记本键盘设置工具) V2.20 中文版

    软件名称: KeyTweak(笔记本键盘设置工具)软件语言: 简体中文授权方式: 免费软件运行环境: Win 32位/64位软件大小: 50KB图片预览: 软件简介:KeyTweak 通过设置系统的注 ...

  6. 执行 npm run update-webdriver 提示文件不能获取错误

    按照angularjs官网的入门教程中输入 npm run update-webdriver  总是提示 https://chromedriver.storage.googleapis.com/2.1 ...

  7. opencv轮廓处理函数详细

    ApproxChains 用多边形曲线逼近 Freeman 链 CvSeq* cvApproxChains( CvSeq* src_seq, CvMemStorage* storage, int me ...

  8. split分割函数

    java.lang.string.split split 方法 将一个字符串分割为子字符串,然后将结果作为字符串数组返回. stringObj.split([separator,[limit]]) 参 ...

  9. 腾讯微博OAuthV2认证实现第三方登录

    1)添加相关jar包: httpmime.jar 以下信息是必须的 //!!!请根据您的实际情况修改!!! 认证成功后浏览器会被重定向到这个url中 必须与注册时填写的一致 private Strin ...

  10. 入门级(python)

    1.素数,求1-100之间的素数(想在代码中写中文注释,加一句#coding=utf-8,注意等号左右没空格) def isPrime(n): if(n == 1): return False els ...