C&C++   发布时间:2022-04-03  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了c – 如何在boost图库中使用带有捆绑属性图的`randomize_property`?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
在文档中: http://www.boost.org/doc/libs/1_46_1/libs/graph/doc/random.html#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;
};

原始编译错误发布为gist here,我无法理解.希望有人告诉我这是如何工作的.

解决方法

这为我编译:

#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,请注明来意。