42 typename F = std::function<bool(
const TNode &,
const size_t &)>>
48 F f_user = [](
const TNode &,
const size_t &) ->
bool {
return false; });
68 typename F = std::function<void(
const TNode &,
const size_t &)>>
75 F f_user = [](
const TNode &,
const size_t &) {});
77 template<
typename TGraph,
typename TNode>
106 typename F = std::function<void(
const TNode &,
const size_t &)>>
113 F f_user = [](
const TNode &,
const size_t &) {});
115 template<
typename TGraph,
typename TNode>
131 template<
typename TNode>
140 template<
typename TGraph,
typename TNode,
typename F1,
typename F2>
143 implNormal(
const TGraph &
graph,
145 unsigned long max_depth,
151 template<
typename FSucc,
typename TNode,
typename F1,
typename F2>
154 expansion(FSucc successors,
155 IDDFS::Data<TNode> &data,
158 unsigned long max_depth,
164 template<
typename TGraph,
typename TNode,
typename F1,
typename F2>
167 implBidirectional(
const TGraph &
graph,
170 unsigned long max_depth,
176 template<
typename FSucc,
typename TNode,
typename F1,
typename F2>
179 backward_expansion(FSucc successors,
180 const IDDFS::Data<TNode> &forward_data,
181 IDDFS::Data<TNode> &backward_data,
183 unsigned long max_depth,
189 template<
typename TGraph,
typename TNode>
192 constructPath(
const TGraph &
graph,
196 unsigned long max_forward_depth,
197 unsigned long max_backward_depth);
201 template<
typename TNode>
202 inline static void init(IDDFS::Data<TNode> &data,
const TNode &
start);
210template<
typename TGraph,
typename TNode,
typename F>
212 implNormal(
graph,
start, max_depth, f_user, [](
const TNode &) ->
bool {
return false; });
217template<
typename TGraph,
typename TNode,
typename F>
221 unsigned long max_depth,
224 [&](
const TNode &n,
const auto &d) ->
bool {
228 [&goal](
const TNode &n) ->
bool {
return goal == n; });
233template<
typename TGraph,
typename TNode,
typename F>
237 unsigned long max_depth,
239 return implBidirectional(
graph,
start, goal, max_depth,
240 [&](
const TNode &n,
const auto &d) ->
bool {
244 [](
const TNode &) ->
bool {
return false; });
251template<
typename TGraph,
typename TNode,
typename F1,
typename F2>
254 unsigned long max_depth,
257 for (
unsigned long i = 1;
i < max_depth; ++
i) {
264 expansion([&](
const TNode &
node) {
return graph.successors(
node); }, data,
start,
false,
i, f_user, f_stop);
276template<
typename FSucc,
typename TNode,
typename F1,
typename F2>
277bool IDDFS::expansion(FSucc successors,
278 IDDFS::Data<TNode> &data,
281 unsigned long max_depth,
284 if (max_depth == 0)
return false;
285 else if (save_nodes && max_depth == 1) {
290 if (f_user(n, data.path.size())) {
299 for (
const auto &s : successors(n)) {
302 if (data.path_set.find(s) != data.path_set.end()) {
306 data.path.push_back(s);
307 data.path_set.insert(s);
308 bool stop = expansion(successors, data, s, save_nodes, max_depth - 1, f_user, f_stop);
314 data.path.pop_back();
315 data.path_set.erase(data.path_set.find(s));
323template<
typename TGraph,
typename TNode,
typename F1,
typename F2>
327 unsigned long max_depth,
330 for (
unsigned long i = 1;
i < max_depth; ++
i) {
333 Data<TNode> forward_data;
336 init(forward_data,
start);
338 expansion([&](
const TNode &n) {
return graph.successors(n); }, forward_data,
start,
true,
i, f_user, f_stop);
345 Data<TNode> backward_data;
348 init(backward_data, goal);
350 intersection = backward_expansion([&](
const TNode &
node) {
return graph.predecessors(
node); },
359 if (!intersection.empty()) {
360 return constructPath(
graph,
start, goal, *intersection.begin(),
i,
i);
364 init(backward_data, goal);
366 intersection = backward_expansion([&](
const TNode &
node) {
return graph.predecessors(
node); },
375 if (!intersection.empty()) {
376 return constructPath(
graph,
start, goal, *intersection.begin(),
i,
i + 1);
385template<
typename FSucc,
typename TNode,
typename F1,
typename F2>
387 const IDDFS::Data<TNode> &forward_data,
388 IDDFS::Data<TNode> &backward_data,
390 unsigned long max_depth,
393 expansion(successors, backward_data,
node,
true, max_depth, f_user, f_stop);
397 std::set_intersection(forward_data.v.begin(), forward_data.v.end(),
398 backward_data.v.begin(), backward_data.v.end(),
399 std::inserter(intersection, intersection.
begin()));
406template<
typename TGraph,
typename TNode>
411 unsigned long max_forward_depth,
412 unsigned long max_backward_depth) {
413 Data<TNode> forward_data;
414 Data<TNode> backward_data;
415 init(forward_data,
start);
416 init(backward_data, goal);
419 expansion([&](
const TNode &
node) {
return graph.successors(
node); },
424 [](
const TNode &,
const size_t &) ->
bool {
return false; },
425 [&](
const TNode &n) ->
bool {
return n == intersection; }
429 expansion([&](
const TNode &
node) {
return graph.predecessors(
node); },
434 [](
const TNode &,
const size_t &) ->
bool {
return false; },
435 [&](
const TNode &n) ->
bool {
return n == intersection; }
443template<
typename TNode>
444void IDDFS::init(IDDFS::Data<TNode> &data,
const TNode &
start) {
449 data.path.push_back(
start);
450 data.path_set.insert(
start);
auto begin() &
Inherited behavior of begin for non-const instance.
Definition: set.hpp:99
Class extending the vector class from the standard library. Original reason is to allow printing of t...
Definition: vector.hpp:45
static ext::vector< TNode > joinPath(ext::vector< TNode > &forward_path, const ext::vector< TNode > &backward_path)
Definition: ReconstructPath.hpp:163
static ext::vector< TNode > findPath(const TGraph &graph, const TNode &start, const TNode &goal, unsigned long max_depth=std::numeric_limits< unsigned long >::max(), F f_user=[](const TNode &, const size_t &) {})
Definition: IDDFS.hpp:218
static ext::vector< TNode > findPathBidirectionalRegistration(const TGraph &graph, const TNode &start, const TNode &goal)
Definition: IDDFS.hpp:118
static ext::vector< TNode > findPathRegistration(const TGraph &graph, const TNode &start, const TNode &goal)
Definition: IDDFS.hpp:80
static void run(const TGraph &graph, const TNode &start, unsigned long max_depth=std::numeric_limits< unsigned long >::max(), F f_user=[](const TNode &, const size_t &) -> bool { return false;})
Definition: IDDFS.hpp:211
static ext::vector< TNode > findPathBidirectional(const TGraph &graph, const TNode &start, const TNode &goal, unsigned long max_depth=std::numeric_limits< unsigned long >::max(), F f_user=[](const TNode &, const size_t &) {})
Definition: IDDFS.hpp:234
int i
Definition: AllEpsilonClosure.h:118
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
Definition: ReconstructPath.hpp:14
void start(measurements::stealth_string name, measurements::Type type)
Definition: measurements.cpp:14