24 #ifndef INCLUDE_BREADTHFIRSTSEARCH_PGR_BINARYBREADTHFIRSTSEARCH_HPP_
25 #define INCLUDE_BREADTHFIRSTSEARCH_PGR_BINARYBREADTHFIRSTSEARCH_HPP_
48 typedef typename G::B_G
B_G;
49 typedef typename G::EO_i
EO_i;
50 typedef typename G::E_i
E_i;
54 std::vector<int64_t> start_vertex,
55 std::vector<int64_t> end_vertex) {
56 std::deque<Path> paths;
58 for (
auto source : start_vertex) {
65 std::make_move_iterator(result_paths.begin()),
66 std::make_move_iterator(result_paths.end()));
69 std::sort(paths.begin(), paths.end(),
70 [](
const Path &e1,
const Path &e2) ->
bool {
71 return e1.end_id() < e2.end_id();
73 std::stable_sort(paths.begin(), paths.end(),
74 [](
const Path &e1,
const Path &e2) ->
bool {
75 return e1.start_id() < e2.start_id();
84 const std::vector<pgr_combination_t> &combinations) {
85 std::deque<Path> paths;
88 std::map< int64_t, std::vector<int64_t> > vertex_map;
90 std::map< int64_t, std::vector<int64_t> >::iterator it = vertex_map.find(comb.source);
91 if (it != vertex_map.end()) {
92 it->second.push_back(comb.target);
94 std::vector<int64_t > targets{comb.target};
95 vertex_map[comb.source] = targets;
99 for (
const auto &start_ends : vertex_map) {
106 std::make_move_iterator(result_paths.begin()),
107 std::make_move_iterator(result_paths.end()));
110 std::sort(paths.begin(), paths.end(),
111 [](
const Path &e1,
const Path &e2) ->
bool {
112 return e1.end_id() < e2.end_id();
114 std::stable_sort(paths.begin(), paths.end(),
115 [](
const Path &e1,
const Path &e2) ->
bool {
116 return e1.start_id() < e2.start_id();
127 int64_t start_vertex,
128 std::vector<int64_t> end_vertex) {
129 std::deque<Path> paths;
131 if (graph.has_vertex(start_vertex) ==
false) {
135 std::vector<double> current_cost(graph.num_vertices(), std::numeric_limits<double>::infinity());
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 dq.push_front(bgl_start_vertex);
145 while (dq.empty() ==
false) {
146 auto head_vertex = dq.front();
153 for (
auto target_vertex : end_vertex) {
154 if (graph.has_vertex(target_vertex) ==
false) {
158 auto bgl_target_vertex = graph.get_V(target_vertex);
165 getPath(graph, bgl_start_vertex, target_vertex, bgl_target_vertex, from_edge, current_cost));
176 std::vector<E> &from_edge,
177 std::vector<double> ¤t_cost) {
178 auto current_node = bgl_target_vertex;
180 Path path =
Path(graph[bgl_start_vertex].
id, graph[current_node].
id);
182 path.
push_back({target, -1, 0, current_cost[current_node]});
185 E e = from_edge[current_node];
186 auto from = graph.source(e);
188 path.
push_back({graph[from].id, graph[e].id, graph[e].cost, current_cost[from]});
193 std::reverse(path.
begin(), path.
end());
200 std::vector<double> ¤t_cost,
201 std::vector<E> &from_edge,
204 auto out_edges = boost::out_edges(head_vertex, graph.graph);
208 V v_source, v_target;
210 for (boost::tie(out_i, out_end) = out_edges;
211 out_i != out_end; ++out_i) {
213 v_target = graph.target(e);
214 v_source = graph.source(e);
215 double edge_cost = graph[e].cost;
217 if (std::isinf(current_cost[v_target]) || current_cost[v_source] + edge_cost < current_cost[v_target]) {
218 current_cost[v_target] = current_cost[v_source] + edge_cost;
220 from_edge[v_target] = e;
222 if (edge_cost != 0) {
223 dq.push_back(v_target);
225 dq.push_front(v_target);
234 #endif // INCLUDE_BREADTHFIRSTSEARCH_PGR_BINARYBREADTHFIRSTSEARCH_HPP_