28 # ifndef TPL_FIND_PATH_H 29 # define TPL_FIND_PATH_H 31 # include <tpl_dynListStack.H> 32 # include <tpl_dynListQueue.H> 33 # include <tpl_graph_utils.H> 40 bool operator () (
typename GT::Node *)
const noexcept {
return false; }
75 bool find_path(
typename GT::Node * curr,
typename GT::Arc * arc,
91 for (Itor<GT, SA> i(curr, sa); i.has_curr(); i.next())
93 auto next_arc = i.get_curr();
97 ARC_BITS(next_arc).set_bit(Find_Path,
true);
98 auto next_node = g_ptr->get_connected_node(next_arc, curr);
99 if (find_path(next_node, next_arc, path, op))
109 bool find(
const GT & g,
typename GT::Node * start,
Path<GT> & path, Op & op)
111 g_ptr =
const_cast<GT*
>(&g);
117 g.reset_bit_nodes(Find_Path);
118 g.reset_bit_arcs(Find_Path);
120 NODE_BITS(start).set_bit(Find_Path,
true);
123 for (Itor<GT, SA> i(start, sa); i.has_curr(); i.next())
125 auto arc = i.get_curr();
126 ARC_BITS(arc).set_bit(Find_Path,
true);
128 auto next_node = g.get_connected_node(arc, start);
132 if (find_path(next_node, arc, path, op))
142 bool find(
const GT & g,
typename GT::Node * start,
Path<GT> & path, Op && op)
144 return find(g, start, path, op);
150 noexcept(std::is_nothrow_constructible<SA>::value and
151 std::is_nothrow_copy_assignable<SA>::value)
155 noexcept(std::is_nothrow_copy_assignable<SA>::value)
168 bool operator () (
const GT & g,
169 typename GT::Node * start,
typename GT::Node * end,
172 return find(g, start, path, [end] (
auto p) {
return p == end; });
185 typename GT::Node * start,
186 typename GT::Node * end)
189 find(g, start, ret, [end] (
auto p) {
return p == end; });
206 Path<GT> operator () (
const GT & g,
typename GT::Node * start, Op & op)
209 find<Op>(g, start, ret, op);
213 template <
class Op = Dft_Goal_Node<GT>>
214 Path<GT> operator () (
const GT & g,
typename GT::Node * start, Op && op)
217 find<Op>(g, start, ret, op);
254 bool find_path(
const GT & g,
typename GT::Node * start,
258 throw std::invalid_argument(
"Path does not belong to graph");
266 for (Itor<GT, SA> i(start, sa); i.has_curr(); i.next())
267 q.
put(i.get_current_arc());
269 NODE_BITS(start).set_bit(Find_Path,
true);
271 typename GT::Node * end =
nullptr;
276 auto src = g.get_src_node(arc);
277 auto tgt = g.get_tgt_node(arc);
285 ARC_BITS(arc).set_bit(Find_Path,
true);
295 for (Itor<GT,SA> i(tgt); i.has_curr(); i.next())
297 auto a = i.get_current_arc();
326 bool find_path(
const GT & g,
typename GT::Node * start,
329 return find_path(g, start, path, op);
335 noexcept(std::is_nothrow_copy_assignable<SA>::value)
339 noexcept(std::is_nothrow_constructible<SA>::value and
340 std::is_nothrow_copy_assignable<SA>::value)
354 Path<GT> operator () (
const GT & g,
typename GT::Node * start, Op & op)
357 find_path(g, start, ret, op);
362 Path<GT> operator () (
const GT & g,
typename GT::Node * start, Op && op)
365 find_path(g, start, ret, op);
379 bool operator () (
const GT & g,
typename GT::Node * start,
380 typename GT::Node * end,
Path<GT> & path)
382 return find_path(g, start, path, [end] (
auto p) {
return p == end; });
395 typename GT::Node * start,
typename GT::Node * end)
398 find_path(g, start, ret, [end] (
auto p) {
return p == end; });
416 template <
template <
typename T>
class Q,
class Op>
417 Path<GT> find(
typename GT::Node * start, Op & op)
424 Q<typename GT::Arc*> q;
425 for (Itor<GT, SA> it(start, sa); it.has_curr(); it.next())
427 auto a = it.get_curr();
433 typename GT::Node * end =
nullptr, * curr =
nullptr;
434 while (not q.is_empty())
440 curr = g.get_tgt_node(arc);
453 for (Itor<GT, SA> it(curr, sa); it.has_curr(); it.next())
455 auto a = it.get_curr();
458 auto tgt = it.get_node(a);
478 while (curr != start)
495 Path<GT> dfs(
typename GT::Node * start, Op & op)
497 return find<DynListStack, Op>(start, op);
501 Path<GT> dfs(
typename GT::Node * start, Op && op)
503 return find<DynListStack, Op>(start, op);
507 Path<GT> bfs(
typename GT::Node * start, Op & op)
509 return find<DynListQueue, Op>(start, op);
513 Path<GT> bfs(
typename GT::Node * start, Op && op)
515 return find<DynListQueue, Op>(start, op);
518 Path<GT> dfs(
typename GT::Node * start,
typename GT::Node * end)
520 return dfs(start, [end] (
auto p) {
return p == end; });
523 Path<GT> bfs(
typename GT::Node * start,
typename GT::Node * end)
525 return bfs(start, [end] (
auto p) {
return p == end; });
534 # endif // TPL_FIND_PATH_H const unsigned char Processing
#define NODE_COOKIE(p)
Definition: aleph-graph.H:333
bool is_empty() const noexcept
rioReturn true if this is empty
Definition: tpl_dynListQueue.H:112
void insert(Arc *arc)
Definition: tpl_graph.H:2951
#define IS_NODE_VISITED(p, bit)
Definition: aleph-graph.H:327
Definition: tpl_find_path.H:249
Definition: tpl_dynListQueue.H:50
Node * remove_last_node() noexcept(noexcept(list.remove_last()))
Definition: tpl_graph.H:3105
const unsigned char Processed
#define IS_ARC_VISITED(p, bit)
Definition: aleph-graph.H:360
Definition: tpl_graph.H:53
Definition: tpl_find_path.H:69
Definition: tpl_find_path.H:411
Definition: tpl_graph.H:1063
Definition: tpl_graph.H:1796
#define NODE_BITS(p)
Definition: aleph-graph.H:305
void set_graph(const GT &__g, Node *start_node=nullptr)
Definition: tpl_graph.H:2745
#define ARC_BITS(p)
Definition: aleph-graph.H:351
void empty() noexcept
Empty the queue.
Definition: tpl_dynListQueue.H:185
void empty()
Clean the path: all the nodes and arc are removed.
Definition: tpl_graph.H:2761
T get()
Definition: tpl_dynListQueue.H:165
void append(Arc *arc)
Definition: tpl_graph.H:2808
Definition: tpl_graph.H:1177
bool inside_graph(const GT &gr) const noexcept
Return true if this is on graph gr
Definition: tpl_graph.H:2708
T & put(const T &data)
The type of element.
Definition: tpl_dynListQueue.H:125