40 template<
class Graph,
class Events>
42 const vertex_type& source,
44 : m_g(g), m_source(source), m_events(events)
53 template<
class Graph,
class Events>
57 std::queue<vertex_type> pending_vertices;
58 vertex_type current_vertex;
59 std::vector<vertex_type> neighbourhood;
60 typename std::vector<vertex_type>::const_iterator it;
64 for (vertex_iterator it_v=m_g.vertex_begin(); it_v!=m_g.vertex_end(); ++it_v)
65 seen_vertices[*it_v] = 0;
67 seen_vertices[m_source] = 1;
68 pending_vertices.push( m_source );
70 while ( !pending_vertices.empty() )
72 current_vertex = pending_vertices.front();
73 m_events.start_vertex(current_vertex);
75 m_g.neighbours( current_vertex, neighbourhood );
77 for( it = neighbourhood.begin(); it != neighbourhood.end(); ++it )
79 if ( seen_vertices[*it] == 0 )
81 m_events.visit_edge(current_vertex, *it);
82 seen_vertices[*it] = 1;
86 pending_vertices.pop();
87 m_events.end_vertex( current_vertex );
88 seen_vertices[current_vertex] = 2;
104 template<
class Graph,
class Events>
106 : m_g(g), m_events(events)
115 template<
class Graph,
class Events>
123 for (it=m_g.vertex_begin(); it!=m_g.vertex_end(); ++it)
124 seen_vertices[*it] = 0;
126 for (it = m_g.vertex_begin(); it!=m_g.vertex_end(); ++it)
127 if ( seen_vertices[*it] == 0 )
128 recursive_scan( *it, seen_vertices );
135 template<
class Graph,
class Events>
137 (
const vertex_type& s, coloration& seen_vertices )
139 std::vector<vertex_type> neighbourhood;
140 typename std::vector<vertex_type>::const_iterator it;
142 m_events.start_vertex(s);
143 seen_vertices[s] = 1;
145 m_g.neighbours( s, neighbourhood );
147 for( it = neighbourhood.begin(); it != neighbourhood.end(); ++it )
148 if ( seen_vertices[*it] == 0 )
150 m_events.visit_edge(s, *it);
151 recursive_scan( *it, seen_vertices );
154 m_events.end_vertex(s);
155 seen_vertices[s] = 2;
178 template<
class Graph>
181 m_result.resize( g.vertices_count() );
182 m_next_index = (int)g.vertices_count()-1;
187 template<
class Graph>
190 m_result[m_next_index] = s;
195 template<
class Graph>
203 template<
class Graph>
204 const typename claw::topological_sort<Graph>::vertex_type &
207 return m_result[index];
211 template<
class Graph>
212 typename claw::topological_sort<Graph>::const_iterator
215 return m_result.begin();
219 template<
class Graph>
220 typename claw::topological_sort<Graph>::const_iterator
223 return m_result.end();