27 #ifndef INCLUDE_ALLPAIRS_PGR_ALLPAIRS_HPP_
28 #define INCLUDE_ALLPAIRS_PGR_ALLPAIRS_HPP_
32 #include <boost/config.hpp>
33 #include <boost/graph/adjacency_list.hpp>
34 #include <boost/property_map/property_map.hpp>
35 #include <boost/graph/johnson_all_pairs_shortest.hpp>
36 #include <boost/graph/floyd_warshall_shortest.hpp>
59 fn_johnson.
johnson(graph, rows);
74 size_t &result_tuple_count,
77 fn_johnson.
johnson(graph, result_tuple_count, postgres_rows);
85 size_t &result_tuple_count,
88 fn_floydWarshall.
floydWarshall(graph, result_tuple_count, postgres_rows);
98 size_t &result_tuple_count,
100 std::vector< std::vector<double>> matrix;
105 CHECK_FOR_INTERRUPTS();
107 boost::floyd_warshall_all_pairs_shortest_paths(
111 distance_combine(combine).
112 distance_inf((std::numeric_limits<double>::max)()).
115 make_result(graph, matrix, result_tuple_count, postgres_rows);
120 std::vector< Matrix_cell_t> &rows) {
121 std::vector< std::vector<double>> matrix;
126 CHECK_FOR_INTERRUPTS();
128 boost::floyd_warshall_all_pairs_shortest_paths(
132 distance_combine(combine).
133 distance_inf((std::numeric_limits<double>::max)()).
141 size_t &result_tuple_count,
143 std::vector< std::vector<double>> matrix;
148 CHECK_FOR_INTERRUPTS();
150 boost::johnson_all_pairs_shortest_paths(
154 distance_combine(combine).
155 distance_inf((std::numeric_limits<double>::max)()).
158 make_result(graph, matrix, result_tuple_count, postgres_rows);
164 std::vector< Matrix_cell_t> &rows) {
165 std::vector< std::vector<double>> matrix;
170 CHECK_FOR_INTERRUPTS();
172 boost::johnson_all_pairs_shortest_paths(
176 distance_combine(combine).
177 distance_inf((std::numeric_limits<double>::max)()).
186 std::vector< std::vector<double>> &matrix)
const {
188 matrix.resize(v_size);
189 for (
size_t i=0; i < v_size; i++)
190 matrix[i].resize(v_size);
195 const std::vector< std::vector<double> > &matrix,
196 size_t &result_tuple_count,
198 result_tuple_count =
count_rows(graph, matrix);
199 *postgres_rows =
pgr_alloc(result_tuple_count, (*postgres_rows));
203 for (
typename G::V v_i = 0; v_i < graph.num_vertices(); v_i++) {
204 for (
typename G::V v_j = 0; v_j < graph.num_vertices(); v_j++) {
205 if (v_i == v_j)
continue;
206 if (matrix[v_i][v_j] != (std::numeric_limits<double>::max)()) {
207 (*postgres_rows)[seq].from_vid = graph[v_i].id;
208 (*postgres_rows)[seq].to_vid = graph[v_j].id;
209 (*postgres_rows)[seq].cost = matrix[v_i][v_j];
219 const std::vector< std::vector<double> > &matrix)
const {
220 size_t result_tuple_count = 0;
221 for (
size_t i = 0; i < graph.num_vertices(); i++) {
222 for (
size_t j = 0; j < graph.num_vertices(); j++) {
223 if (i == j)
continue;
224 if (matrix[i][j] != (std::numeric_limits<double>::max)()) {
225 result_tuple_count++;
229 return result_tuple_count;
234 std::vector< std::vector<double> > &matrix,
235 std::vector< Matrix_cell_t> &rows) {
240 for (
typename G::V v_i = 0; v_i < graph.num_vertices(); v_i++) {
241 for (
typename G::V v_j = 0; v_j < graph.num_vertices(); v_j++) {
242 if (matrix[v_i][v_j] != (std::numeric_limits<double>::max)()) {
244 {graph[v_i].id, graph[v_j].id, matrix[v_i][v_j]};
251 template <
typename T>
254 T inf = (std::numeric_limits<T>::max)();
255 if (a == inf || b == inf)
263 #endif // INCLUDE_ALLPAIRS_PGR_ALLPAIRS_HPP_