23namespace shortest_path {
51 typename F1 = std::function<
typename TGraph::edge_type::weight_type(
const TNode &)>,
52 typename F2 = std::function<void(
const TNode &,
const typename TGraph::edge_type::weight_type &)>>
59 F2 f_user = [](
const TNode &,
60 const typename TGraph::edge_type::weight_type &) {});
65 typename F1 = std::function<
typename TGraph::edge_type::weight_type(
const TNode &,
const TNode &)>
73 return findPath(
graph,
start, goal, [&](
const TNode &n) {
return f_heuristic(goal, n); });
83 template<
typename TNode,
typename TWeight>
92 template<
typename TGraph,
typename TNode,
typename F1,
typename F2>
95 search(
const TGraph &
graph,
96 IDAStar::Data<TNode, typename TGraph::edge_type::weight_type> &data,
98 typename TGraph::edge_type::weight_type gscore,
99 typename TGraph::edge_type::weight_type bound,
109template<
typename TGraph,
typename TNode,
typename F1,
typename F2>
116 using weight_type =
typename TGraph::edge_type::weight_type;
118 Data<TNode, weight_type> data;
119 data.path.push_back(
start);
120 data.path_set.insert(
start);
122 weight_type bound = f_heuristic(
start);
126 ext::tie(found, t) = search(
graph, data, goal, 0, bound, f_heuristic, f_user);
140template<
typename TGraph,
typename TNode,
typename F1,
typename F2>
142IDAStar::search(
const TGraph &
graph,
143 IDAStar::Data<TNode, typename TGraph::edge_type::weight_type> &data,
145 typename TGraph::edge_type::weight_type gscore,
146 typename TGraph::edge_type::weight_type bound,
149 using weight_type =
typename TGraph::edge_type::weight_type;
151 TNode n = data.path.back();
152 weight_type f = gscore + f_heuristic(n);
163 data.path_size = gscore;
168 for (
const auto &s_edge:
graph.successorEdges(n)) {
172 if (data.path_set.find(s) != data.path_set.end()) {
177 if (s_edge.weight() < 0) {
178 throw std::out_of_range(
"IDAStar: Detect negative weight on edge in graph.");
184 data.path.push_back(s);
185 data.path_set.insert(s);
187 search(
graph, data, goal, gscore + s_edge.weight(), bound, f_heuristic, f_user);
191 }
else if (t <
min) {
195 data.path.pop_back();
196 data.path_set.erase(data.path_set.find(s));
Class extending the pair class from the standard library. Original reason is to allow printing of the...
Definition: pair.hpp:43
Class extending the vector class from the standard library. Original reason is to allow printing of t...
Definition: vector.hpp:45
static TNode const & other(const TEdge &e, const TNode &n)
Definition: IDAStar.hpp:25
static ext::pair< ext::vector< TNode >, typename TGraph::edge_type::weight_type > findPathRegistration(const TGraph &graph, const TNode &start, const TNode &goal, F1 f_heuristic)
Definition: IDAStar.hpp:69
static ext::pair< ext::vector< TNode >, typename TGraph::edge_type::weight_type > findPath(const TGraph &graph, const TNode &start, const TNode &goal, F1 f_heuristic, F2 f_user=[](const TNode &, const typename TGraph::edge_type::weight_type &) {})
Definition: IDAStar.hpp:111
constexpr tuple< Elements &... > tie(Elements &... args) noexcept
Helper of extended tuple of references construction. The tuple is constructed to reffer to values in ...
Definition: tuple.hpp:218
constexpr const T & max(const T &a)
Root case of maximum computation. The maximum from one value is the value itself.
Definition: algorithm.hpp:278
constexpr const T & min(const T &a)
Definition: algorithm.hpp:310
constexpr auto make_pair(T1 &&x, T2 &&y)
Definition: pair.hpp:79
Definition: ReconstructPath.hpp:14
void start(measurements::stealth_string name, measurements::Type type)
Definition: measurements.cpp:14