У меня проблемы с Floyd Warshall (все пары кратчайших путей) в графе Boost. Есть ли способ напрямую предоставить ориентированный взвешенный график до floyd_warshall_all_pairs_shortest_paths
? Кажется, что все его функции перегрузок требуют дополнительных параметров, которые я не совсем понимаю. Ниже приводится тестовый код, который я пишу (не компилируется, потому что мой призыв к floyd_warshall_all_pairs_shortest_paths
неполно)Floyd Warshall (все парные кратчайшие пути) на взвешенном неориентированном графике - Boost Graph
#include <iostream>
#include <map>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/floyd_warshall_shortest.hpp>
typedef boost::property<boost::edge_weight_t, double> EdgeWeightProperty;
typedef boost::adjacency_list<boost::vecS, boost::vecS,
boost::undirectedS, boost::no_property,
EdgeWeightProperty> Graph;
typedef unsigned long t_indx;
int main()
{
typedef boost::graph_traits<Graph>::vertex_descriptor vertex_des;
std::map<vertex_des, std::map<vertex_des, int> > matrix;
Graph sp_graph;
int edgelet_sp[] = { 1, 2,
1, 3,
1, 4,
2, 5,
3, 4,
3, 6,
4, 5,
4, 6,
4, 7,
5, 7,
6, 7 };
double edgelet_vals[] = { 4,
10,
3,
1,
12,
20,
6,
3,
0,
3,
9};
int num_edges = 11;
/* make the superpixel graph */
for (t_indx i = 0; i < num_edges; ++i) {
add_edge(edgelet_sp[i]-1, edgelet_sp[i+num_edges]-1, edgelet_vals[i], sp_graph);
}
std::cout << num_vertices(sp_graph) << std::endl;
bool floyd2 =
boost::floyd_warshall_all_pairs_shortest_paths
(sp_graph, matrix);
return 0;
}
Я новичок в BGL, так что любая помощь будет оценена. Например, есть ли более элегантные способы написания этого кода (без объявления edgelet_sps
и edgelet_vals
, оба из которых будут заменены)? Благодарю.