27 #ifndef INCLUDE_BELLMAN_FORD_PGR_BELLMAN_FORD_HPP_
28 #define INCLUDE_BELLMAN_FORD_PGR_BELLMAN_FORD_HPP_
31 #include <boost/config.hpp>
32 #include <boost/graph/adjacency_list.hpp>
33 #include <boost/graph/bellman_ford_shortest_paths.hpp>
66 bool only_cost =
false) {
68 log << std::string(__FUNCTION__) <<
"\n";
75 if (!graph.has_vertex(start_vertex)
76 || !graph.has_vertex(end_vertex)) {
77 return Path(start_vertex, end_vertex);
81 auto v_source(graph.get_V(start_vertex));
82 auto v_target(graph.get_V(end_vertex));
100 const std::vector< int64_t > &end_vertex,
101 bool only_cost =
false) {
104 log << std::string(__FUNCTION__) <<
"\n";
109 if (!graph.has_vertex(start_vertex))
110 return std::deque<Path>();
111 auto v_source(graph.get_V(start_vertex));
113 std::set< V > s_v_targets;
114 for (
const auto &vertex : end_vertex) {
115 if (graph.has_vertex(vertex)) {
116 s_v_targets.insert(graph.get_V(vertex));
120 std::vector< V > v_targets(s_v_targets.begin(), s_v_targets.end());
124 std::deque< Path > paths;
126 paths =
get_paths(graph, v_source, v_targets, only_cost);
128 std::stable_sort(paths.begin(), paths.end(),
129 [](
const Path &e1,
const Path &e2)->bool {
130 return e1.end_id() < e2.end_id();
139 const std::vector < int64_t > &start_vertex,
141 bool only_cost =
false) {
142 std::deque<Path> paths;
143 log << std::string(__FUNCTION__) <<
"\n";
144 for (
const auto &start : start_vertex) {
149 std::stable_sort(paths.begin(), paths.end(),
150 [](
const Path &e1,
const Path &e2)->bool {
151 return e1.start_id() < e2.start_id();
160 const std::vector< int64_t > &start_vertex,
161 const std::vector< int64_t > &end_vertex,
162 bool only_cost =
false) {
164 std::deque<Path> paths;
165 log << std::string(__FUNCTION__) <<
"\n";
167 for (
const auto &start : start_vertex) {
168 auto r_paths =
bellman_ford(graph, start, end_vertex, only_cost);
169 paths.insert(paths.begin(), r_paths.begin(), r_paths.end());
173 std::sort(paths.begin(), paths.end(),
174 [](
const Path &e1,
const Path &e2)->bool {
175 return e1.end_id() < e2.end_id();
177 std::stable_sort(paths.begin(), paths.end(),
178 [](
const Path &e1,
const Path &e2)->bool {
179 return e1.start_id() < e2.start_id();
187 const std::vector<pgr_combination_t> &combinations,
188 bool only_cost =
false) {
190 std::deque<Path> paths;
191 log << std::string(__FUNCTION__) <<
"\n";
194 std::map< int64_t, std::vector<int64_t> > vertex_map;
196 std::map< int64_t, std::vector<int64_t> >::iterator it = vertex_map.find(comb.source);
197 if (it != vertex_map.end()) {
198 it->second.push_back(comb.target);
200 std::vector<int64_t > targets{comb.target};
201 vertex_map[comb.source] = targets;
205 for (
const auto &start_ends : vertex_map) {
213 std::make_move_iterator(result_paths.begin()),
214 std::make_move_iterator(result_paths.end()));
228 log << std::string(__FUNCTION__) <<
"\n";
230 CHECK_FOR_INTERRUPTS();
232 boost::bellman_ford_shortest_paths(
234 static_cast<int>(graph.num_vertices()),
236 .weight_map(get(&G::G_T_E::cost, graph.graph))
238 .root_vertex(source));
239 }
catch (boost::exception
const& ex) {
242 }
catch (std::exception &e) {
254 log << std::string(__FUNCTION__) <<
"\n";
256 CHECK_FOR_INTERRUPTS();
258 boost::bellman_ford_shortest_paths(
260 static_cast<int>(graph.num_vertices()),
262 .weight_map(get(&G::G_T_E::cost, graph.graph))
264 .root_vertex(source));
265 }
catch (boost::exception
const& ex) {
268 }
catch (std::exception &e) {
289 std::vector< V > &targets,
290 bool only_cost)
const {
291 log << std::string(__FUNCTION__) <<
"\n";
292 std::deque<Path> paths;
293 for (
const auto target : targets) {
294 paths.push_back(
Path(
313 #endif // INCLUDE_BELLMAN_FORD_PGR_BELLMAN_FORD_HPP_