#include <boost/graph/graph_traits.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/dijkstra_shortest_paths_no_color_map.hpp>
+#include <boost/property_map/property_map.hpp>
using namespace boost;
typedef adjacency_list < listS, vecS, directedS,
no_property, property < edge_weight_t, int > > graph_t;
typedef graph_traits < graph_t >::vertex_descriptor vertex_descriptor;
- typedef graph_traits < graph_t >::edge_descriptor edge_descriptor;
typedef std::pair<int, int> Edge;
const int num_nodes = 5;
};
int weights[] = { 1, 2, 1, 2, 7, 3, 1, 1, 1 };
int num_arcs = sizeof(edge_array) / sizeof(Edge);
-#if defined(BOOST_MSVC) && BOOST_MSVC <= 1300
- graph_t g(num_nodes);
- property_map<graph_t, edge_weight_t>::type weightmap = get(edge_weight, g);
- for (std::size_t j = 0; j < num_arcs; ++j) {
- edge_descriptor e; bool inserted;
- boost::tie(e, inserted) = add_edge(edge_array[j].first, edge_array[j].second, g);
- weightmap[e] = weights[j];
- }
-#else
graph_t g(edge_array, edge_array + num_arcs, weights, num_nodes);
property_map<graph_t, edge_weight_t>::type weightmap = get(edge_weight, g);
-#endif
std::vector<vertex_descriptor> p(num_vertices(g));
std::vector<int> d(num_vertices(g));
vertex_descriptor s = vertex(A, g);
-#if defined(BOOST_MSVC) && BOOST_MSVC <= 1300
- // VC++ has trouble with the named parameters mechanism
- property_map<graph_t, vertex_index_t>::type indexmap = get(vertex_index, g);
- dijkstra_shortest_paths_no_color_map(g, s, &p[0], &d[0], weightmap,
- indexmap, std::less<int>(),
- closed_plus<int>(),
- (std::numeric_limits<int>::max)(), 0,
- default_dijkstra_visitor());
-#else
- dijkstra_shortest_paths_no_color_map(g, s, predecessor_map(&p[0]).distance_map(&d[0]));
-#endif
+ dijkstra_shortest_paths_no_color_map(g, s,
+ predecessor_map(boost::make_iterator_property_map(p.begin(), get(boost::vertex_index, g))).
+ distance_map(boost::make_iterator_property_map(d.begin(), get(boost::vertex_index, g))));
std::cout << "distances and parents:" << std::endl;
graph_traits < graph_t >::vertex_iterator vi, vend;