21 #ifndef INCLUDE_BELLMAN_FORD_PGR_EDWARDMOORE_HPP_
22 #define INCLUDE_BELLMAN_FORD_PGR_EDWARDMOORE_HPP_
45 typedef typename G::B_G
B_G;
46 typedef typename G::EO_i
EO_i;
47 typedef typename G::E_i
E_i;
51 std::vector<int64_t> start_vertex,
52 std::vector<int64_t> end_vertex) {
53 std::deque<Path> paths;
55 for (
auto source : start_vertex) {
63 std::make_move_iterator(result_paths.begin()),
64 std::make_move_iterator(result_paths.end()));
67 std::sort(paths.begin(), paths.end(),
68 [](
const Path &e1,
const Path &e2) ->
bool {
69 return e1.end_id() < e2.end_id();
71 std::stable_sort(paths.begin(), paths.end(),
72 [](
const Path &e1,
const Path &e2) ->
bool {
73 return e1.start_id() < e2.start_id();
82 const std::vector<pgr_combination_t> &combinations) {
83 std::deque<Path> paths;
86 std::map< int64_t, std::vector<int64_t> > vertex_map;
88 std::map< int64_t, std::vector<int64_t> >::iterator it = vertex_map.find(comb.source);
89 if (it != vertex_map.end()) {
90 it->second.push_back(comb.target);
92 std::vector<int64_t > targets{comb.target};
93 vertex_map[comb.source] = targets;
97 for (
const auto &start_ends : vertex_map) {
105 std::make_move_iterator(result_paths.begin()),
106 std::make_move_iterator(result_paths.end()));
109 std::sort(paths.begin(), paths.end(),
110 [](
const Path &e1,
const Path &e2) ->
bool {
111 return e1.end_id() < e2.end_id();
113 std::stable_sort(paths.begin(), paths.end(),
114 [](
const Path &e1,
const Path &e2) ->
bool {
115 return e1.start_id() < e2.start_id();
126 int64_t start_vertex,
127 std::vector<int64_t> end_vertex) {
128 std::deque<Path> paths;
130 if (graph.has_vertex(start_vertex) ==
false) {
134 std::vector<double> current_cost(graph.num_vertices(), std::numeric_limits<double>::infinity());
135 std::vector<bool> isInQ(graph.num_vertices(),
false);
136 std::vector<E> from_edge(graph.num_vertices());
140 auto bgl_start_vertex = graph.get_V(start_vertex);
142 current_cost[bgl_start_vertex] = 0;
143 isInQ[bgl_start_vertex] =
true;
144 dq.push_front(bgl_start_vertex);
146 while (dq.empty() ==
false) {
147 auto head_vertex = dq.front();
150 isInQ[head_vertex] =
false;
155 for (
auto target_vertex : end_vertex) {
156 if (graph.has_vertex(target_vertex) ==
false) {
160 auto bgl_target_vertex = graph.get_V(target_vertex);
167 getPath(graph, bgl_start_vertex, target_vertex, bgl_target_vertex, from_edge, current_cost));
178 std::vector<E> &from_edge,
179 std::vector<double> ¤t_cost) {
180 auto current_node = bgl_target_vertex;
182 Path path =
Path(graph[bgl_start_vertex].
id, graph[current_node].
id);
184 path.
push_back({target, -1, 0, current_cost[current_node]});
187 E e = from_edge[current_node];
188 auto from = graph.source(e);
190 path.
push_back({graph[from].id, graph[e].id, graph[e].cost, current_cost[from]});
195 std::reverse(path.
begin(), path.
end());
201 std::vector<double> ¤t_cost,
202 std::vector<bool> &isInQ,
203 std::vector<E> &from_edge,
207 CHECK_FOR_INTERRUPTS();
209 auto out_edges = boost::out_edges(head_vertex, graph.graph);
213 V v_source, v_target;
215 for (boost::tie(out_i, out_end) = out_edges;
216 out_i != out_end; ++out_i) {
218 v_target = graph.target(e);
219 v_source = graph.source(e);
220 double edge_cost = graph[e].cost;
222 if (std::isinf(current_cost[v_target]) || current_cost[v_source] + edge_cost < current_cost[v_target]) {
223 current_cost[v_target] = current_cost[v_source] + edge_cost;
225 from_edge[v_target] = e;
227 if (isInQ[v_target] ==
false) {
228 dq.push_back(v_target);
229 isInQ[v_target] =
true;
238 #endif // INCLUDE_BELLMAN_FORD_PGR_EDWARDMOORE_HPP_