1 # ifndef TOPOLOGICAL_SORT_H
2 # define TOPOLOGICAL_SORT_H
4 # include <tpl_dynListQueue.H>
5 # include <tpl_graph.H>
18 template <
class GT,
class SA = Dft_Show_Arc<GT> >
32 template <
template <
class>
class List>
33 void topological_sort(
typename GT::Node * curr,
34 List<typename GT::Node*> &
list)
43 const size_t & n = gptr->get_num_nodes();
47 it.has_curr() and list.size() < n; it.
next())
48 topological_sort(it.get_tgt_node(), list);
65 template <
template <
class>
class List>
68 if (not g.is_digraph())
69 throw std::domain_error(
"g is not a digraph");
71 g.reset_bit_nodes(Depth_First);
74 List<typename GT::Node*> list;
77 const size_t & n = gptr->get_num_nodes();
78 for (
typename GT::Node_Iterator it(g); it.has_curr() and list.size() < n;
81 typename GT::Node * curr = it.get_current_node();
83 topological_sort(curr, list);
93 perform<DynDlist>(g).swap(list);
106 template <
class GT,
class SA = Dft_Show_Arc<GT> >
128 template <
template <
class>
class List>
131 if (not g.is_digraph())
132 throw std::domain_error(
"g is not a digraph");
134 g.reset_counter_nodes();
136 List<typename GT::Node*>
list;
144 for (
typename GT::Node_Iterator it(g); it.has_curr(); it.next())
146 typename GT::Node * p = it.get_current_node();
151 while (not q.is_empty())
153 typename GT::Node * p = q.
get();
162 typename GT::Node * tgt = it.get_tgt_node();
183 template <
template <
class>
class RankList =
DynDlist,
184 template <
class>
class List =
DynList>
185 RankList<List<typename GT::Node*>>
ranks(GT & g)
187 if (not g.is_digraph())
188 throw std::domain_error(
"g is not a digraph");
190 g.reset_counter_nodes();
193 for (
typename GT::Node_Iterator i(g); i.has_curr(); i.next())
195 j.has_curr(); j.
next())
200 for (
typename GT::Node_Iterator it(g); it.has_curr(); it.next())
202 typename GT::Node * p = it.get_current_node();
207 RankList<List<typename GT::Node*>>
ranks;
208 while (not q.is_empty())
210 List<typename GT::Node*> rank;
213 while (not q.is_empty())
215 typename GT::Node * p = q.
get();
221 typename GT::Node * tgt = it.get_tgt_node();
227 ranks.append(std::move(rank));
236 this->ranks<>(g).swap(
list);
241 this->ranks<DynList>(g).swap(
list);
247 this->perform<DynDlist>(g).swap(list);
253 # endif // TOPOLOGICAL_SORT_H
void operator()(GT &g, DynDlist< typename GT::Node * > &list)
Definition: topological_sort.H:91
Definition: topological_sort.H:19
Definition: topological_sort.H:107
Definition: tpl_graph.H:751
#define IS_NODE_VISITED(p, bit)
Definition: aleph-graph.H:242
Definition: tpl_dynListQueue.H:22
List< typename GT::Node * > perform(GT &g)
Definition: topological_sort.H:129
#define NODE_COUNTER(p)
Definition: aleph-graph.H:226
Definition: tpl_graph.H:1186
void next()
Adelanta el iterador una posición.
Definition: filter_iterator.H:143
#define NODE_BITS(p)
Definition: aleph-graph.H:221
RankList< List< typename GT::Node * > > ranks(GT &g)
Definition: topological_sort.H:185
T get()
Definition: tpl_dynListQueue.H:107
Definition: tpl_graph.H:694
List< typename GT::Node * > perform(GT &g)
Definition: topological_sort.H:66
T & put(const T &data)
Definition: tpl_dynListQueue.H:86