#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;
}
}
}

最新文章

  1. 周末惊魂:因struts2 016 017 019漏洞被入侵,修复。
  2. Magicodes.WeiChat——自定义knockoutjs template、component实现微信自定义菜单
  3. IE6 IE7 IE8 的函数声明和函数表达式的实现与其他浏览器有差异
  4. AVG()和to_date()函数的使用
  5. [设计模式] 22 模板方法模式 template
  6. jquery.tochart.js
  7. 漫谈并发编程(六):java中一些经常使用的并发构件的介绍
  8. VS2010 下编译 cocos2d-x-2.1.4
  9. LFCP
  10. CSS 中的 initial、inherit、unset、revert
  11. 【leetcode81】Product of Array Except Self
  12. async/Await使用和原理
  13. js对象跟数组多层嵌套,检测没有此数据就添加有则不添加以及超过限制条件删除操作
  14. cordov vue项目中调用手机原生api
  15. Spring+Struts+Mybatis+Shiro整合配置
  16. C++STL 迭代器
  17. ilspy反编译
  18. 2.3.2 EditText(输入框)详解
  19. Weex入门与进阶指南
  20. Nginx入门篇(六)之反向代理和负载均衡

热门文章

  1. Python学习笔记_Chapter 6定制数据对象
  2. 解决VM安装VMTools后错误提示,实现文件共享
  3. 【转载】将python脚本打包成exe文件
  4. onmousedown活用之碰撞效果
  5. padding当高度用时出现的问题
  6. HTTPS科普扫盲帖【转】
  7. 在cmd模式下对mysql的操作语句
  8. pgadmin3 新建服务器出现错误 Peer authentication failed for user &quot;postgres&quot; 的解决办法
  9. composer安装自己的包
  10. sort 排序详解