在文档中:http://www.boost.org/doc/libs/1_46_1/libs/graph/doc/random.html#randomize_property如何在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;
};
原来的编译错误过帐为依据here,我无法理解。希望有人告诉我这是如何工作的。
似乎是提升用户的重复问题:http://lists.boost.org/boost-users/ 2005/09/14033.php和http://lists.boost.org/boost-users/2009/08/50755.php - 看起来不像是时间解决了。 – Cubbi 2011-04-19 18:34:36
@Cubbi是的,我也找到了。他放弃了使用捆绑的属性来做这件事。 – 2011-04-21 22:45:27
这与您的问题无关,但我试图弄清楚如何禁止平行边缘,并且您的代码示例给了我答案。多谢! – 2012-06-04 23:02:06