33#ifndef UG_BASE_LIB_ALGEBRA_ORDERING_STRATEGIES_ALGORITHMS_TOPOLOGICAL_ORDERING_H
34#define UG_BASE_LIB_ALGEBRA_ORDERING_STRATEGIES_ALGORITHMS_TOPOLOGICAL_ORDERING_H
36#include <boost/graph/adjacency_list.hpp>
37#include <boost/graph/graph_traits.hpp>
38#include <boost/graph/properties.hpp>
58template <
typename O_t,
typename G_t>
60 typedef typename boost::graph_traits<G_t>::vertex_descriptor vd_t;
61 typedef typename boost::graph_traits<G_t>::edge_descriptor ed_t;
62 typedef typename boost::graph_traits<G_t>::vertex_iterator vIt_t;
63 typedef typename boost::graph_traits<G_t>::in_edge_iterator in_edge_iterator;
68 UG_THROW(
"topological_ordering_core: Graph is empty!");
72 std::vector<int> indegs(n);
73 std::vector<BOOL> isindeq(n,
false);
79 if(indegs[*vIt] == 0){
86 UG_THROW(
"topological_ordering_core: Graph is not cycle-free [1]!\n");
89 std::pair<in_edge_iterator, in_edge_iterator> e;
93 while(!deq.empty() && miss < deq.size()){
98 if(indegs[cur_v] > 0){
114 for(; e.first != e.second; ++e.first){
115 ed_t
const& edg = *e.first;
128 else if(indegs[t] > 0){
137 UG_THROW(
"topological_ordering_core: Graph is not cycle-free [2]!\n");
141template <
typename O_t,
typename G_t>
143 typedef typename boost::graph_traits<G_t>::vertex_descriptor vd_t;
144 typedef typename boost::graph_traits<G_t>::vertex_iterator vIt_t;
145 typedef typename boost::graph_traits<G_t>::adjacency_iterator nIt_t;
150 UG_THROW(
"topological_ordering_core: Graph is empty!");
154 std::vector<int> indegs(n);
155 std::vector<BOOL> isindeq(n,
false);
156 std::deque<vd_t> deq;
168 if(indegs[*vIt] == 0){
169 deq.push_front(*vIt);
170 isindeq[*vIt] =
true;
175 UG_THROW(
"topological_ordering_core: Graph is not cycle-free [1]!\n");
181 while(!deq.empty() && miss < deq.size()){
186 if(indegs[cur_v] > 0){
187 deq.push_back(cur_v);
208 if(indegs[*nIt] == 0){
209 deq.push_front(*nIt);
210 isindeq[*nIt] =
true;
212 else if(indegs[*nIt] > 0){
214 isindeq[*nIt] =
true;
221 UG_THROW(
"topological_ordering_core: Graph is not cycle-free [2]!\n");
227template <
typename TAlgebra,
typename O_t>
231 typedef typename TAlgebra::matrix_type
M_t;
232 typedef typename TAlgebra::vector_type
V_t;
233 typedef typename boost::graph_traits<M_t>::vertex_descriptor
vd_t;
261 #ifdef UG_ENABLE_DEBUG_LOGS
269 UG_THROW(
name() <<
"::init: Algorithm does not support induced subgraph version!");
273 UG_THROW(
name() <<
"::init: Algorithm does not support induced subgraph version!");
284 virtual const char*
name()
const {
return "TopologicalOrdering";}
Definition smart_pointer.h:108
Definition bidirectional.h:47
Definition IOrderingAlgorithm.h:52
Definition topological_ordering.h:229
void init(M_t *, const O_t &)
Definition topological_ordering.h:272
TAlgebra::vector_type V_t
Definition topological_ordering.h:232
void check()
Definition topological_ordering.h:276
SmartPtr< IOrderingAlgorithm< TAlgebra, O_t > > clone()
Definition topological_ordering.h:242
TopologicalOrdering(const TopologicalOrdering< TAlgebra, O_t > &parent)
clone constructor
Definition topological_ordering.h:239
boost::graph_traits< M_t >::vertex_descriptor vd_t
Definition topological_ordering.h:233
O_t & ordering()
Definition topological_ordering.h:280
BidirectionalMatrix< M_t > bidir
Definition topological_ordering.h:287
virtual const char * name() const
Definition topological_ordering.h:284
TAlgebra::matrix_type M_t
Definition topological_ordering.h:231
void compute()
Definition topological_ordering.h:247
void init(M_t *A)
Definition topological_ordering.h:259
IOrderingAlgorithm< TAlgebra, O_t > baseclass
Definition topological_ordering.h:234
void init(M_t *, const V_t &, const O_t &)
Definition topological_ordering.h:268
void init(M_t *A, const V_t &)
Definition topological_ordering.h:255
TopologicalOrdering()
Definition topological_ordering.h:236
O_t o
Definition topological_ordering.h:288
#define UG_THROW(msg)
Definition error.h:57
#define UG_LOG(msg)
Definition log.h:367
#define UG_COND_THROW(cond, msg)
UG_COND_THROW(cond, msg) : performs a UG_THROW(msg) if cond == true.
Definition error.h:61
std::pair< typename graph_traits< T >::adjacency_iterator, typename graph_traits< T >::adjacency_iterator > adjacent_vertices(size_t v, ug::BidirectionalMatrix< T > const &M)
Definition bidirectional_boost.h:108
int out_degree(int v, ug::BidirectionalMatrix< T > const &M)
Definition bidirectional_boost.h:76
std::pair< SM_out_edge_iterator< typename T::value_type, false >, SM_out_edge_iterator< typename T::value_type, false > > in_edges(size_t v, ug::BidirectionalMatrix< T > const &g)
Definition bidirectional_boost.h:147
std::pair< counting_iterator< size_t >, counting_iterator< size_t > > vertices(ug::BidirectionalMatrix< T > const &M)
Definition bidirectional_boost.h:60
int num_vertices(ug::BidirectionalMatrix< T > const &M)
Definition bidirectional_boost.h:70
size_t source(SM_edge< typename T::value_type > const &e, ug::BidirectionalMatrix< T > const &)
Definition bidirectional_boost.h:94
void topological_ordering_core_bidirectional(O_t &o, G_t &g, bool inverse)
Definition topological_ordering.h:59
bool is_permutation(O_t &o)
Definition permutation_util.h:135
void topological_ordering_core_directed(O_t &o, G_t &g, bool inverse)
Definition topological_ordering.h:142
SmartPtr< T, FreePolicy > make_sp(T *inst)
returns a SmartPtr for the passed raw pointer
Definition smart_pointer.h:836