|
Boost Users : |
From: Doug Gregor (dgregor_at_[hidden])
Date: 2005-06-22 11:33:36
Hi Andrea,
On Jun 13, 2005, at 7:07 AM, Andrea Olgiati wrote:
> I've encountered a problem whilst compiling the following program,
> and I can't quite figure out why it shouldn't work. Whilst compiling
> usign boost 1.32.0 and gcc 3.3.4, I get
> cannot convert
> `boost::detail::edge_desc_impl<boost::bidirectional_tag, size_t>' to
> `int'
> for argument `2' to `const T& get(const T*, int) [with T = int]'
>
>
> I believe this is saying that edge descriptors cannot be used as
> indices into a property map (that is, "wm"). Why is this different
> from vertex descriptors, which are accepted as indices into "p" and
> "dist"?
The problem here is that std::vectors really only work as property maps
when the descriptors are integers and, unfortunately, that only works
with vertex descriptors (in some limited cases). The easiest way to
solve the problem is to make "wm" an internal property map, by putting
the edge weight into the graph itself.
There's an updated version of your code below, where I've done three
things:
(1) I added an "edge_weight" property to each edge, by changing the
Graph typedef.
(2) I changed the definition of "wm" so that it is a property map
accessing the weights of each edge (that are stored inside the graph
itself).
(3) The call to bellman_ford_shortest_paths just passes the property
map "wm", instead of &wm[0].
Doug
#include <boost/graph/graph_traits.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/bellman_ford_shortest_paths.hpp>
int
main ()
{
typedef boost::adjacency_list<boost::vecS, boost::vecS,
boost::bidirectionalS,
boost::no_property,
boost::property<boost::edge_weight_t,
int> >
Graph;
Graph G;
boost::property_map<Graph, boost::edge_weight_t>::type wm =
boost::get(boost::edge_weight, G);
std::vector < boost::graph_traits < Graph >::vertex_descriptor > p;
std::vector < int > dist;
boost::bellman_ford_shortest_paths (G, boost::num_vertices(G),
wm, &p[0], &dist[0],
boost::closed_plus < int >(),
std::less < int >(),
boost::default_bellman_visitor
());
return 0;
}
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