How to use `randomize_property` with the property graph enabled in the accelerator library?

In the documentation: http://www.boost.org/doc/libs/1_46_1/libs/graph/doc/random.html#randomize_property

There is only a function prototype; I cannot find a working example. I tried a few things, but it just doesn't compile. Here is a simple source code:

#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; } 

Update: The code provided by @phooji is working. I added a default constructor for EdgeProperty , and my compilation too:

 struct EdgeProperty { EdgeProperty(int x = 0) : cost(x) { } int cost; }; 

The original compilation error is published as a gist here , which I cannot understand. Hope someone tells me how this works.

+4
source share
3 answers

This compiles for me:

 #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; // :) } 

Hope this helps - I don’t have time to actually test it, so apologize if this is not what you need.

+2
source

There is at least one problem that I see that is an invalid definition of the edge property. To determine graph properties, use the property<> . There are several predefined properties, such as index, weight, color, etc. The property type edge_weight_t used to determine the cost of an edge. Therefore, the definition of the type of graph should be as follows:

 typedef adjacency_list< setS, // disallow parallel edge vecS, undirectedS, no_property, property<edge_weight_t, int> > Graph; 

To access the property type, use property_map<> : property_map<Graph, edge_weight_t>::type .

Change My mistake is related to related properties, but it’s still difficult to specify the correct type for the randomize_property<Property> template parameter, which should be a property type. If you define a graph, as in my example, the use will be randomize_property<edge_weight_t>(g, gen);

0
source

You can use the following workaround until it is properly sorted using boost:

 boost::detail::randomize_property<int EdgeProperty::*> (g, gen, &EdgeProperty::cost, boost::edge_bundle_t); 
0
source

All Articles