|
Boost Users : |
Subject: Re: [Boost-users] edges
From: Jeremiah Willcock (jewillco_at_[hidden])
Date: 2010-03-31 10:11:41
On Wed, 31 Mar 2010, Figa Pelosa wrote:
> hello.
> My graph is an:
>
> typedef adjacency_list < mapS, vecS, undirectedS, my_vertexProperty,
> property < edge_weight_t, float > > Graph;
>
> I have 100 edges, and I also have an array with 100 weights.
>
> How do I assign weight[i] to edge[i], and how do I create a
> weightmap to use in dijkstra_shortest_paths()?
The easiest way would probably be the "obvious" one -- iterate through
edges(g) and the weight array in parallel, and assign corresponding
elements. I.e., (using <boost/graph/iteration_macros.hpp>):
size_t i = 0;
BGL_FORALL_EDGES(e, g, Graph) {
put(edge_weight, g, e, weight[i]);
++i;
}
You could also use your weight array directly by creating an
iterator_property_map to use as the weight map, but this would require
filling in an edge_index property map that corresponds to the edge order
in your weight array.
Since you have an internal edge_weight property in your graph, you can
leave off the weight_map parameter to dijkstra_shortest_paths; your
internal property will be found automatically.
-- 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