15.boost最小生成树 prim_minimum_spanning_tree
#include <iostream>
#include <boost/config.hpp>
//图(矩阵实现)
#include <boost/graph/adjacency_matrix.hpp>
#include <boost\graph\graph_utility.hpp>
#include <boost/graph/graph_traits.hpp>
//图(链表实现)
#include <boost/graph/adjacency_list.hpp>
//求最小生成树
#include <boost/graph/kruskal_min_spanning_tree.hpp>
//prim算法求最小生成树
#include <boost/graph/prim_minimum_spanning_tree.hpp>
using namespace std;
using namespace boost; //顶点名称
enum { A, B, C, D, E, F };
//顶点个数
#define N 6
const char *name = "ABCDEF"; //无向图
void main()
{
//图,每个结点是vec来实现,无向图,有边长与权重的属性
adjacency_list<vecS, vecS, undirectedS, no_property, property<edge_weight_t, int>> myg;
add_edge(A, B,, myg);
add_edge(B, C, ,myg);
add_edge(A, C,, myg);
add_edge(A, D,, myg);
add_edge(C, D,, myg);
add_edge(B, D,, myg); //定义图的类型
typedef adjacency_list<vecS, vecS, undirectedS, property<edge_weight_t, int>> mygraph; //创建边与权重的映射(weight是函数指针)
auto weight= get(edge_weight,myg);
//property_map<mygraph, edge_weight_t>::type weight = get(edge_weight, myg); //vector数组,存放四个顶点
vector<graph_traits<mygraph>::vertex_descriptor> pv(); //将最小生成树的结果插到vector中
prim_minimum_spanning_tree(myg, &pv[]); //输出
for (int i = ; i < pv.size(); i++)
{
if (pv[i] != i)
{
graph_traits<mygraph>::edge_descriptor ed;
bool isok;
//生成绑定
tie(ed, isok) = edge(i, pv[i], myg);
cout << "tree" << i << "<--->" << pv[i] << " " << weight[ed] << endl;
}
} cin.get();
}
15.boost最小生成树 prim_minimum_spanning_tree的更多相关文章
- 14.boost最小生成树 kruskal_min_spainning_tree
#include <iostream> #include <boost/config.hpp> //图(矩阵实现) #include <boost/graph/adjac ...
- 16.boost图深度优先遍历DFS
#include <iostream> #include <boost/config.hpp> //图(矩阵实现) #include <boost/graph/adjac ...
- (转)boost::bind介绍
转自:http://www.cnblogs.com/sld666666/archive/2010/12/14/1905980.html 这篇文章介绍boost::bind()的用法, 文章的主要内容是 ...
- Boost Thread学习笔记四
barrierbarrier类的接口定义如下: 1 class barrier : private boost::noncopyable // Exposition only 2 { 3 pub ...
- Boost Thread学习笔记
thread自然是boost::thread库的主 角,但thread类的实现总体上是比较简单的,前面已经说过,thread只是一个跨平台的线程封装库,其中按照所使用的编译选项的不同,分别决定使用 W ...
- boost::bind 介绍
boost::bind 介绍 这篇文章介绍boost::bind()的用法, 文章的主要内容是参考boost的文档. 1. 目的 boost::bind 是std::bindlist 和 std: ...
- [Fundamental of Power Electronics]-PART I-5.不连续导电模式-5.3 Boost变换器实例
5.3 Boost变换器实例 作为第二个示例,考虑图5.12的Boost变换器.让我们来确定不同模式的边界并且求解DCM下的电压变换比.此前在2.3节中分析了在CCM工作的Boost变换器的特性,并确 ...
- 17.广度优先遍历bfs
#include <iostream> #include <boost/config.hpp> //图(矩阵实现) #include <boost/graph/adjac ...
- C++内存管理学习笔记(5)
/****************************************************************/ /* 学习是合作和分享式的! /* Auth ...
随机推荐
- iOS~判断应用是否有定位权限
在特定场景下我们需要判断用户是否允许应用获取定位权限 1.导入类库: #import <CoreLocation/CLLocationManager.h> 2.判断用户手机是否开启了定位服 ...
- shell脚本创建和执行
shell脚本并不能作为正式的编程语言,因为它是在Linux的shell中运行的,所以称他为shell脚本. 事实上,shell脚本就是一些命令的集合. 我们不妨吧所有的操作都记录到一个文档中,然后去 ...
- 15.Linux的文件结构
linux的文件结构和windows不同,没有分区,是树形的结构: /etc:存放配置文件 /lib:编译程序需要的函数库 /usr:包含所有其他内容,比如内核在/usr/src中,/usr/bin存 ...
- POJ 3260 DP
只需要对John的付款数做一次多重背包,对shopkeeper的找零钱数做一次完全背包即可. 最重要的是上界的处理.可以注意到,John的付款数最多为maxv*maxv+m,也就是24400元.同理, ...
- js input 只能输入数字
HTML网页上这么写 <input type="text" style="ime-mode:disabled;" onpaste="return ...
- idea报错:Please, configure Web Facet first!
https://blog.csdn.net/handsomepig123_/article/details/87257689 转载
- CDR 2017版本LiveSketch工具是什么,怎么用?
LiveSketch 工具在提供手绘草图的简便性和速度的同时,结合了智能笔触调整和向量绘图.在您绘制草图时,CorelDRAW 2017会分析您输入笔触的属性.时序和空间接近度,对其进行调整并将其转换 ...
- 使用RestTemplate上传文件给远程接口
MultiValueMap request = new LinkedMultiValueMap(1); ByteArrayResource is = new ByteArrayResource(mul ...
- Android 7.0 Gallery图库源码分析2 - 分析启动流程
前面一讲解了Gallery启动Activity以及界面如何绘制,现在开始讲解启动流程的代码逻辑. GalleryActivity的onCreate方法中调用initializeByIntent()方法 ...
- [CodeForces]1006F Xor Path
双向搜索. 水div3的时候最后一道题由于C题死活看不懂题 来不及做F了Orz.. 因为n,m是20,双向搜索一下,求个到中间的Xor值的方案,统计一下即可. 时间复杂度\(O(2^{21})\) 好 ...