edge_list<EdgeIterator, ValueType, DiffType>
The edge_list class is an adaptor that turns a pair of edge iterators into a class that models EdgeListGraph. The value_type of the edge iterator must be a std::pair (or at least have first and second members). The first_type and second_type of the pair must be the same and they will be used for the graph's vertex_descriptor. The ValueType and DiffType template parameters are only needed if your compiler does not support partial specialization. Otherwise they default to the correct types.
Applying the Bellman-Ford shortest paths algorithm to an edge_list.
enum { u, v, x, y, z, N }; char name[] = { 'u', 'v', 'x', 'y', 'z' }; typedef std::pair<int,int> E; E edges[] = { E(u,y), E(u,x), E(u,v), E(v,u), E(x,y), E(x,v), E(y,v), E(y,z), E(z,u), E(z,x) }; int weight[] = { -4, 8, 5, -2, 9, -3, 7, 2, 6, 7 }; typedef boost::edge_list<E*> Graph; Graph g(edges, edges + sizeof(edges) / sizeof(E)); std::vector<int> distance(N, std::numeric_limits<short>::max()); std::vector<int> parent(N,-1); distance[z] = 0; parent[z] = z; bool r = boost::bellman_ford_shortest_paths(g, int(N), weight, distance.begin(), parent.begin()); if (r) for (int i = 0; i < N; ++i) std::cout << name[i] << ": " << distance[i] << " " << name[parent[i]] << std::endl; else std::cout << "negative cycle" << std::endl;The output is the distance from the root and the parent of each vertex in the shortest paths tree.
u: 2 v v: 4 x x: 7 z y: -2 u z: 0 z
Parameter | Description |
---|---|
EdgeIterator | Must be model of InputIterator who's value_type must be a pair of vertex descriptors. |
ValueType | The value_type of the EdgeIterator. Default: std::iterator_traits<EdgeIterator>::value_type |
DiffType | The difference_type of the EdgeIterator. Default: std::iterator_traits<EdgeIterator>::difference_type |
Copyright © 2000-2001 |
Jeremy Siek,
Indiana University ([email protected]) Lie-Quan Lee, Indiana University ([email protected]) Andrew Lumsdaine, Indiana University ([email protected]) |