Boost logo

Boost Users :

Subject: Re: [Boost-users] Retrieving edge weights
From: Jeremiah Willcock (jewillco_at_[hidden])
Date: 2011-06-11 17:12:33

On Sat, 11 Jun 2011, David Doria wrote:

> I found one way to get edge weights:
> typedef boost::property_map<Graph, boost::edge_weight_t>::type EdgeWeightMap;
> EdgeWeightMap edgeWeightMap = get(boost::edge_weight, g);
> std::pair<Graph::edge_descriptor, bool> edgePair = boost::edge(v0, v1, g);
> Graph::edge_descriptor edge = edgePair.first;
> That seems like a lot of work though. It looks like there is a
> operator[](edge_descriptor), but I don't understand how to use it:
> I tried:
> g[edge]->edge_weight

That syntax only works for bundled properties. If you had used a struct
with an edge_weight member as your vertex property type, you could use the
[] syntax. With the old-style property syntax, however, you will need to
use the version you posted at the top. You can use a three-parameter
version of get (get(boost::edge_weight, g, v) is the order, I think) if
you are not getting a lot of weights.

-- Jeremiah Willcock

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at