从特定的起始顶点提升 prim_minimum_spanning_tree
Posted
技术标签:
【中文标题】从特定的起始顶点提升 prim_minimum_spanning_tree【英文标题】:Boost prim_minimum_spanning_tree from a particular start vertex 【发布时间】:2016-11-09 13:09:38 【问题描述】:对于一个简单的图,直接调用 prim_minimum_spanning_tree 得到从顶点 0 开始的结果:
#include <iostream>
#include <boost/graph/graph_traits.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/prim_minimum_spanning_tree.hpp>
typedef boost::property<boost::edge_weight_t, double> EdgeWeightProperty;
typedef boost::adjacency_list<boost::setS, boost::vecS, boost::undirectedS, boost::no_property, EdgeWeightProperty> Graph;
int main(int,char*[])
// Create a graph object
Graph g(3);
EdgeWeightProperty e1 = 5;
add_edge(0, 1, e1, g);
EdgeWeightProperty e2 = 3;
add_edge(1, 2, e2, g);
std::vector < boost::graph_traits < Graph >::vertex_descriptor > parents(num_vertices(g));
prim_minimum_spanning_tree(g, &parents[0]);
for (std::size_t i = 0; i != parents.size(); ++i)
if (parents[i] != i)
std::cout << "parent[" << i << "] = " << parents[i] << std::endl;
else
std::cout << "parent[" << i << "] = no parent" << std::endl;
return 0;
但我似乎无法解密指定不同起始顶点的签名?看起来这个是唯一一个需要vertex_descriptor
(我假设它是开始顶点?):
prim_minimum_spanning_tree
(const VertexListGraph& g,
typename graph_traits<VertexListGraph>::vertex_descriptor s,
PredecessorMap predecessor, DistanceMap distance, WeightMap weight,
IndexMap index_map,
DijkstraVisitor vis)
关于如何调用它的任何建议?
【问题讨论】:
【参考方案1】:这需要“命名参数”签名:
prim_minimum_spanning_tree(g, &parents[0], boost::root_vertex(1));
您可以在文档页面的“命名参数”下找到可用的命名参数:http://www.boost.org/doc/libs/1_61_0/libs/graph/doc/prim_minimum_spanning_tree.html
【讨论】:
以上是关于从特定的起始顶点提升 prim_minimum_spanning_tree的主要内容,如果未能解决你的问题,请参考以下文章