大佬教程收集整理的这篇文章主要介绍了c – 如何在boost图库中使用带有捆绑属性图的`randomize_property`?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
只有一个函数原型,我找不到一个有效的例子.
我尝试了几件事,但它无法编译.
这是一个简单的源代码:
#include <ctime> #include <iostream> #include <boost/graph/random.hpp> #include <boost/graph/adjacency_list.hpp> #include <boost/random/linear_congruential.hpp> #include <boost/graph/erdos_renyi_generator.hpp> #include <boost/graph/graphviz.hpp> using namespace std; using namespace boost; struct EdgeProperty { int cost; }; typedef adjacency_list< setS,// disallow parallel edge vecS,undirectedS,no_property,EdgeProperty > Graph; typedef erdos_renyi_iterator<minstd_rand,Graph> ERGen; int main(int argc,const char *argv[]) { minstd_rand gen(time(0)); assert(argc >= 3); int n = atoi(argv[1]); double p = atof(argv[2]); Graph g(ERGen(gen,n,p),ERGen(),n); // randomize_property< [unkNown class] >(g,gen); return 0; }
更新:@phooji提供的代码有效.我为EdgeProperty添加了一个默认构造函数,我的代码也编译了:
struct EdgeProperty { EdgeProperty(int x = 0) : cost(X) { } int cost; };
#include <boost/graph/adjacency_list.hpp> #include <boost/graph/random.hpp> #include <boost/random/linear_congruential.hpp> struct myedge { myedge(int X) : testme(X) { } int testme; }; typedef boost::adjacency_list<boost::setS,// disallow parallel edge boost::vecS,boost::undirectedS,boost::no_property,myedge > mygraph; int main(int argc,char**argv) { mygraph g; // auto pmap = boost::get(&myedge::testme,g); boost::minstd_rand gen(0); boost::randomize_property<boost::edge_bundle_t>(g,gen); return EXIT_succesS; // :) }
希望有所帮助 – 我没有时间对它进行实际测试,所以如果这不是你想要的,那么道歉.
以上是大佬教程为你收集整理的c – 如何在boost图库中使用带有捆绑属性图的`randomize_property`?全部内容,希望文章能够帮你解决c – 如何在boost图库中使用带有捆绑属性图的`randomize_property`?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。