Boost logo

Boost Users :

Subject: [Boost-users] randomize_property question
From: mcorbion_at_[hidden]
Date: 2009-08-14 08:30:26


Hello I'm currently trying to create a randomly made graph and I'm having
problem populating the properties using the randomize_property. Just like
this man
http://lists.boost.org/boost-users/2005/09/14033.php
I'm wondering if it's even possible to use randomize_property with the
bundled properties? I hope so because the bundled properties are in my
opinion much more easy to use.

Here's the bundled property I would like to randomize (which is quite
basic):
struct City
{
  int pos_X;
  int pos_Y;
};

I've tried to get from it the property class needed using
vertex_bundle_type<Graph>::type this way :

randomize_property<vertex_bundle_type<Graph>::type>(m_Graph,l_Gen);

I then looked in the source code and it seems that the function merely
takes a property_map and randomly changes the values. So I tried this (I
was desperate^^) using the way "get" works with bundled property :

randomize_property<&City::pos_X>(m_Graph,l_Gen);

Here's the source code for randomize_property

boost/graph/random.hpp

169 template<class Property, class G, class RandomGenerator>
170 void randomize_property(G& g, RandomGenerator& rg,
171 Property, vertex_property_tag)
172 {
173 typename property_map<G, Property>::type pm = get(Property(),
g); 174 typename graph_traits<G>::vertex_iterator vi, ve;
175 for (tie(vi, ve) = vertices(g); vi != ve; ++vi) {
176 pm[*vi] = rg();
177 }
178 }

I know that for my short example and, by inspiring me from the source, I
could do it manually but I'd rather do it using genericity.

Hope there isn't too much broken english.
Thanks
M.Corbion


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net