27 #ifndef INCLUDE_ASTAR_PGR_ASTAR_HPP_
28 #define INCLUDE_ASTAR_PGR_ASTAR_HPP_
31 #include <boost/config.hpp>
32 #include <boost/graph/graph_traits.hpp>
33 #include <boost/graph/adjacency_list.hpp>
34 #include <boost/graph/astar_search.hpp>
51 namespace algorithms {
57 typedef typename G::B_G
B_G;
82 if (!graph.has_vertex(start_vertex)
83 || !graph.has_vertex(end_vertex)) {
84 return Path(start_vertex, end_vertex);
87 auto v_source(graph.get_V(start_vertex));
88 auto v_target(graph.get_V(end_vertex));
91 astar_1_to_1(graph, v_source, v_target, heuristic, factor, epsilon);
93 auto solution =
Path(graph,
Path(graph,
104 int64_t start_vertex,
105 std::vector<int64_t> end_vertex,
115 if (!graph.has_vertex(start_vertex))
return std::deque<Path>();
116 auto v_source(graph.get_V(start_vertex));
118 std::vector<V> v_targets;
119 for (
const auto &vertex : end_vertex) {
120 if (graph.has_vertex(vertex)) {
121 v_targets.push_back(graph.get_V(vertex));
132 auto paths =
get_paths(graph, v_source, v_targets, only_cost);
134 std::stable_sort(paths.begin(), paths.end(),
135 [](
const Path &e1,
const Path &e2)->bool {
136 return e1.end_id() < e2.end_id();
145 std::vector<int64_t> start_vertex,
146 std::vector<int64_t> end_vertex,
151 std::deque<Path> paths;
152 for (
const auto &start : start_vertex) {
153 auto r_paths =
astar(graph, start, end_vertex,
154 heuristic, factor, epsilon, only_cost);
155 paths.insert(paths.begin(), r_paths.begin(), r_paths.end());
158 std::sort(paths.begin(), paths.end(),
159 [](
const Path &e1,
const Path &e2)->bool {
160 return e1.end_id() < e2.end_id();
162 std::stable_sort(paths.begin(), paths.end(),
163 [](
const Path &e1,
const Path &e2)->bool {
164 return e1.start_id() < e2.start_id();
172 const std::vector<pgr_combination_t> &combinations,
178 std::deque<Path> paths;
181 std::map< int64_t, std::vector<int64_t> > vertex_map;
183 std::map< int64_t, std::vector<int64_t> >::iterator it = vertex_map.find(comb.source);
184 if (it != vertex_map.end()) {
185 it->second.push_back(comb.target);
187 std::vector<int64_t > targets{comb.target};
188 vertex_map[comb.source] = targets;
192 for (
const auto &start_ends : vertex_map) {
193 auto r_paths =
astar(
195 start_ends.first, start_ends.second,
196 heuristic, factor, epsilon, only_cost);
197 paths.insert(paths.end(), r_paths.begin(), r_paths.end());
226 const std::vector< V > &goals,
230 m_goals(goals.begin(), goals.end()),
237 double best_h((std::numeric_limits<double>::max)());
239 double current((std::numeric_limits<double>::max)());
240 double dx =
m_g[goal].x() -
m_g[u].x();
241 double dy =
m_g[goal].y() -
m_g[u].y();
247 current = std::fabs((std::max)(dx, dy)) *
m_factor;
250 current = std::fabs((std::min)(dx, dy)) *
m_factor;
256 current = std::sqrt(dx * dx + dy * dy) *
m_factor;
259 current = (std::fabs(dx) + std::fabs(dy)) *
m_factor;
264 if (current < best_h) {
270 if (!(s_it ==
m_goals.end())) {
305 :
m_goals(goals.begin(), goals.end()) {}
309 if (s_it ==
m_goals.end())
return;
333 CHECK_FOR_INTERRUPTS();
339 heuristic, factor * epsilon),
356 const std::vector< V > &targets,
362 CHECK_FOR_INTERRUPTS();
367 graph.graph, targets,
368 heuristic, factor * epsilon),
389 const std::vector<V> &targets,
390 bool only_cost)
const {
391 std::deque<Path> paths;
392 for (
const auto &target : targets) {
397 paths.push_back(
Path(graph, p, only_cost));
407 #endif // INCLUDE_ASTAR_PGR_ASTAR_HPP_