Boost logo

Boost Users :

From: Doug Gregor (dgregor_at_[hidden])
Date: 2004-08-01 09:41:05


On Jul 31, 2004, at 4:58 PM, Ralph Wessel wrote:

> I would like to use the BGL for a project I'm working on, but I
> haven't been able to find a particular piece of information. The
> system I'm modeling can be easily represented by a directed graph, but
> it seems that an essential vertex property can only be calculated on
> the fly based on the current in-edge and out-edge as the graph is
> traversed. Can this be supported in the BGL in a way which can feed
> this vertex property to the supplied algorithms?

You can do this by creating your own external property map type, e.g.,

template<typename Graph>
   struct my_property_map
   {
     typedef typename graph_traits<Graph>::vertex_descriptor key_type;
     typedef int value_type; // change me
     typedef value_type reference;
     typedef boost::readable_property_map_tag category;

     explicit my_property_map(const Graph& g) : g(g) {}

     const Graph& g;
   };

template<typename Graph>
   typename my_property_map<Graph>::reference
   get(my_property_map<Graph> pm, typename
my_property_map<Graph>::key_type k)
   {
     // compute whatever you want...
     return in_degree(k, g) + out_degree(k, g);
   }

        Doug


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