tags:

views:

662

answers:

1

Hi,

using boost::graph with bundled properties. I want to be able to run searches using a variety of different possible edge weighting schemes. I'd like to not create an additional class for the bundled properties if possible, and pass in different weight maps depending on the type of search without creating a new graph or modifying all of the existing properties in the graph.

Can I manually build a property_map for edge_weight_t? Here's what I've got so far:

typedef boost::property_map<SSPSGraph_t, boost::edge_weight_t>::type WeightMap;
typedef boost::property<boost::edge_weight_t, float> DistanceProperty;

And I'd like to just be able to do

WeightMap distances;
edge_descriptor_t e = some_edge_or_another;
float d=some_derived_distance_value;

And assign distances[e] to the appropriate values--

distances[e]= ?

Or do I just need to break down and make up a new structure for the bundled properties-- something I've been trying to avoid-- and create the weight map from that? New to boost::graph; not assuming I'm not doing something entirely stupid here.

+1  A: 

I am not sure i understand your question. Here are a few tips that may help you :

boost::property_map, which you have used to define WeightMap requires that you add corresponding property inside your graph (you only did half of what's needed by defining DistanceProperty):

typedef boost::property<boost::edge_weight_t, float> DistanceProperty;

typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::undirS, DistanceProperty> MyGraph;

If this hasn't been done, boost::property_map won't help you in anyway.

If you don't want to add a different weight property for every different scheme you want to try, the alternative is to define such properties outside graph definition. This can either be done - using std::map and boost::associative_property (which is pretty simple but has the efficiency of a map) - using boost::vector_property_map, which is more efficient (thanks underlying std::vector), but requires a identifier property_map ie a property_map which can extract a numerical identifier (ideally between 0 and num_edges() - 1) from provided edge. This property_map is typically defined within the graph.

If my answer does not help you (or not enough), please be a bit more precise in your question so i can update my answer !

Benoît