GraphLibrary  0.0.1
A simple library that implements various graph algorithms.
 All Classes Namespaces Files Functions Variables Typedefs Macros
TransitiveClosure.hpp
Go to the documentation of this file.
1 #ifndef GL_TRANSITIVE_CLOSURE_HPP
2 #define GL_TRANSITIVE_CLOSURE_HPP
3 
4 #include "../structures/Graph.hpp"
5 #include "DFS.hpp"
6 
7 namespace gl {
8 namespace algorithm {
9 
16  template <class Graph>
17  typename Graph::ordered_list_t transitiveClosure (const Graph& graph, const typename Graph::idx_t node) {
18  typename Graph::visit_list_t visited(graph.numNodes(),false); // list of visited nodes
19  typename Graph::ordered_list_t out;
20  gl::algorithm::DFS_recursive(graph, node, visited, out);
21  out.clear();
22  // fill out list with visited nodes
23  for(typename Graph::idx_t i = 0; i < graph.numNodes(); ++i) {
24  if (visited[i]) {
25  out.emplace_back(i);
26  }
27  }
28  return out;
29  }
30 
31 } /* namespace algorithm */
32 } /* namespace gl */
33 
34 #endif /* GL_TRANSITIVE_CLOSURE_HPP */
void DFS_recursive(const GRAPH &graph, const typename GRAPH::idx_t node, typename GRAPH::visit_list_t &visited, typename GRAPH::ordered_list_t &out)
Recursive call for DFS.
Definition: DFS.hpp:17
gl::index_type idx_t
Index type.
Definition: Graph.hpp:44
Graph::ordered_list_t transitiveClosure(const Graph &graph, const typename Graph::idx_t node)
Implements an algorithm that finds the (reachability based) transitive closure of a node...
Definition: TransitiveClosure.hpp:17
Stores and implements a Graph.
Definition: Graph.hpp:39
idx_t numNodes() const
Returns the number of nodes currently in the graph.
Definition: Graph.hpp:406
std::list< idx_t > ordered_list_t
Ordered List type.
Definition: Graph.hpp:49
std::vector< bool > visit_list_t
Visited-List type.
Definition: Graph.hpp:50