@@ -21,28 +21,27 @@ along with this program; if not, write to the Free Software
2121Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
2222********************************************************************PGR-GNU*/
2323
24- #ifndef INCLUDE_MST_PGR_BINARYBREADTHFIRSTSEARCH_HPP_
25- #define INCLUDE_MST_PGR_BINARYBREADTHFIRSTSEARCH_HPP_
24+ #ifndef INCLUDE_BREADTHFIRSTSEARCH_PGR_BINARYBREADTHFIRSTSEARCH_HPP_
25+ #define INCLUDE_BREADTHFIRSTSEARCH_PGR_BINARYBREADTHFIRSTSEARCH_HPP_
2626#pragma once
2727
2828#include < deque>
2929#include < algorithm>
3030#include < cmath>
31+ #include < limits>
32+ #include < vector>
3133
3234#include " cpp_common/basePath_SSEC.hpp"
3335#include " cpp_common/pgr_base_graph.hpp"
3436#include " cpp_common/pgr_assert.h"
3537// ******************************************
3638
37- namespace pgrouting
38- {
39- namespace functions
40- {
39+ namespace pgrouting {
40+ namespace functions {
4141
4242template <class G >
43- class Pgr_binaryBreadthFirstSearch
44- {
45- public:
43+ class Pgr_binaryBreadthFirstSearch {
44+ public:
4645 typedef typename G::V V;
4746 typedef typename G::E E;
4847 typedef typename G::B_G B_G;
@@ -53,18 +52,15 @@ class Pgr_binaryBreadthFirstSearch
5352 G &graph,
5453 std::vector<int64_t > start_vertex,
5554 std::vector<int64_t > end_vertex) {
56-
5755 std::deque<Path> paths;
5856
59- for (auto source : start_vertex) {
57+ for (auto source : start_vertex) {
6058 std::deque<Path> result_paths = one_to_many_binaryBreadthFirstSearch (
6159 graph,
6260 source,
63- end_vertex
64- );
65-
61+ end_vertex);
6662 paths.insert (
67- paths.begin (),
63+ paths.begin (),
6864 std::make_move_iterator (result_paths.begin ()),
6965 std::make_move_iterator (result_paths.end ()));
7066 }
@@ -81,20 +77,16 @@ class Pgr_binaryBreadthFirstSearch
8177 return paths;
8278 }
8379
84- private:
85-
80+ private:
8681 E DEFAULT_EDGE;
8782
8883 std::deque<Path> one_to_many_binaryBreadthFirstSearch (
8984 G &graph,
9085 int64_t start_vertex,
91- std::vector<int64_t > end_vertex)
92- {
93-
86+ std::vector<int64_t > end_vertex) {
9487 std::deque<Path> paths;
9588
96- if (graph.has_vertex (start_vertex) == false )
97- {
89+ if (graph.has_vertex (start_vertex) == false ) {
9890 return paths;
9991 }
10092
@@ -108,26 +100,22 @@ class Pgr_binaryBreadthFirstSearch
108100 current_cost[bgl_start_vertex] = 0 ;
109101 dq.push_front (bgl_start_vertex);
110102
111- while (dq.empty () == false )
112- {
103+ while (dq.empty () == false ) {
113104 int64_t head_vertex = dq.front ();
114105
115106 dq.pop_front ();
116107
117108 updateVertexCosts (graph, current_cost, from_edge, dq, head_vertex);
118109 }
119110
120- for (auto target_vertex : end_vertex)
121- {
122- if (graph.has_vertex (target_vertex) == false )
123- {
111+ for (auto target_vertex : end_vertex) {
112+ if (graph.has_vertex (target_vertex) == false ) {
124113 continue ;
125114 }
126115
127116 int64_t bgl_target_vertex = graph.get_V (target_vertex);
128117
129- if (from_edge[bgl_target_vertex] == DEFAULT_EDGE)
130- {
118+ if (from_edge[bgl_target_vertex] == DEFAULT_EDGE) {
131119 continue ;
132120 }
133121
@@ -144,16 +132,14 @@ class Pgr_binaryBreadthFirstSearch
144132 int64_t target,
145133 int64_t bgl_target_vertex,
146134 std::vector<E> &from_edge,
147- std::vector<double > ¤t_cost)
148- {
135+ std::vector<double > ¤t_cost) {
149136 int64_t current_node = bgl_target_vertex;
150137
151138 Path path = Path (graph[bgl_start_vertex].id , graph[current_node].id );
152139
153140 path.push_back ({target, -1 , 0 , current_cost[current_node]});
154141
155- do
156- {
142+ do {
157143 E e = from_edge[current_node];
158144 auto from = graph.source (e);
159145
@@ -171,43 +157,35 @@ class Pgr_binaryBreadthFirstSearch
171157 std::vector<double > ¤t_cost,
172158 std::vector<E> &from_edge,
173159 std::deque<int64_t > &dq,
174- int64_t &head_vertex)
175- {
160+ int64_t &head_vertex) {
176161 auto out_edges = boost::out_edges (head_vertex, graph.graph );
177162 E e;
178163 EO_i out_i;
179164 EO_i out_end;
180165 V v_source, v_target;
181166
182167 for (boost::tie (out_i, out_end) = out_edges;
183- out_i != out_end; ++out_i)
184- {
185-
168+ out_i != out_end; ++out_i) {
186169 e = *out_i;
187170 v_target = graph.target (e);
188171 v_source = graph.source (e);
189172 double edge_cost = graph[e].cost ;
190173
191- if (std::isinf (current_cost[v_target]) or current_cost[v_source] + edge_cost < current_cost[v_target])
192- {
193-
174+ if (std::isinf (current_cost[v_target]) || current_cost[v_source] + edge_cost < current_cost[v_target]) {
194175 current_cost[v_target] = current_cost[v_source] + edge_cost;
195176
196177 from_edge[v_target] = e;
197178
198- if (edge_cost != 0 )
199- {
179+ if (edge_cost != 0 ) {
200180 dq.push_back (v_target);
201- }
202- else
203- {
181+ } else {
204182 dq.push_front (v_target);
205183 }
206184 }
207185 }
208186 }
209187};
210- } // namespace functions
211- } // namespace pgrouting
188+ } // namespace functions
189+ } // namespace pgrouting
212190
213- #endif // INCLUDE_MST_PGR_BINARYBREADTHFIRSTSEARCH_HPP_
191+ #endif // INCLUDE_BREADTHFIRSTSEARCH_PGR_BINARYBREADTHFIRSTSEARCH_HPP_
0 commit comments