Boost logo

Boost Users :

Subject: Re: [Boost-users] randomize_property question
From: Jeremiah Willcock (jewillco_at_[hidden])
Date: 2009-08-14 15:50:39


On Fri, 14 Aug 2009, mcorbion_at_[hidden] wrote:

> Ok so I still can't use the randomize property but I've done a workaround.
> I created an AbstractGraph class which has a m_Graph adjacency_list type
> of graph. And nodes uses the bundled property :
> struct City
> {
> int pos_X;
> int pos_Y;
> };
>
>
> My workaround test function uses the property map given to randomly set
> the values, but it's still too specific :
>
> template <typename Graph, typename BundProp,typename RandomGenerator>
> void AbstractGraph::test(bundle_property_map<Graph,unsigned
> int,BundProp,int> p_PMap, RandomGenerator& p_ewrg){
>
> AbstractGraph::N_iterator l_NodeStart;
> AbstractGraph::N_iterator l_NodeEnd;
> AbstractGraph::GetNodes(l_NodeStart,l_NodeEnd);
>
> for (; l_NodeStart != l_NodeEnd; ++l_NodeStart) {
> p_PMap[*l_NodeStart] = p_ewrg();
> }
> }
>
> called this way in the main :
>
> mt19937 l_Gen(1988);
> boost::uniform_int<> RandRange(1,10);
> boost::variate_generator<boost::mt19937&, boost::uniform_int<> >
> ew2rg(l_Gen, RandRange);
>
>
> typedef property_map<Graph, int(City::*)>::type t_PMapCity;
> t_PMapCity l_PMap=get(&City::pos_X,m_Graph);
> test<Graph,City>(l_PMap,ew2rg);
>
>
> I would like to include the two line that generates the property_map from
> the main to the test function. I've tried this :
>
> template <typename Graph, typename PropertyTagType,typename RandomGenerator>
> void AbstractGraph::test2( ??? p_PropertyTagName,RandomGenerator& p_ewrg){
>
> typedef property_map<Graph, PropertyTagType>::type t_PMap;
> t_PMap l_PMap=get(PropertyTagName,m_Graph);
> AbstractGraph::N_iterator l_NodeStart;
> AbstractGraph::N_iterator l_NodeEnd;
> AbstractGraph::GetNodes(l_NodeStart,l_NodeEnd);
>
> for (; l_NodeStart != l_NodeEnd; ++l_NodeStart) {
> p_PMap[*l_NodeStart] = p_ewrg();
> }
> }
>
> called this way :
>
> test2<Graph,int(City::*)>(l_Gen, &City::pos_X);
>
> But I can't figure any type for &City::pos_X in order to write the header
> for test2 allowing the function to work with float, char ...

The type of &City::pos_X should be "int City::*" (without the extra
parentheses); however, argument deduction should pick that up for you
automatically, both for this code and randomize_property. The ??? in
test2 should be PropertyTagType, I believe.

-- Jeremiah Willcock


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