mCRL2
Loading...
Searching...
No Matches
reachable_nodes.h
Go to the documentation of this file.
1// Author(s): Wieger Wesselink
2// Copyright: see the accompanying file COPYING or copy at
3// https://github.com/mCRL2org/mCRL2/blob/master/COPYING
4//
5// Distributed under the Boost Software License, Version 1.0.
6// (See accompanying file LICENSE_1_0.txt or copy at
7// http://www.boost.org/LICENSE_1_0.txt)
8//
11
12#ifndef MCRL2_UTILITIES_REACHABLE_NODES_H
13#define MCRL2_UTILITIES_REACHABLE_NODES_H
14
15#include <boost/graph/adjacency_list.hpp> // to make the header compile standalone
16#include <boost/graph/depth_first_search.hpp>
17#include <boost/tuple/tuple.hpp>
18
19#include <cstddef>
20#include <iterator>
21#include <vector>
22
23namespace mcrl2 {
24
25namespace utilities {
26
28namespace detail
29{
30
31template <typename Graph>
32struct reachable_nodes_recorder: public boost::default_dfs_visitor
33{
34 typedef typename Graph::vertex_descriptor vertex_descriptor;
35 std::vector<std::size_t>& m_result;
36
37 reachable_nodes_recorder(std::vector<std::size_t>& result)
38 : m_result(result)
39 {}
40
44 void discover_vertex(vertex_descriptor u, const Graph& g)
45 {
46 m_result.push_back(boost::get(boost::vertex_index, g)[u]);
47 }
48};
49} // namespace detail
51
58template <typename Graph, typename Iter>
59std::vector<std::size_t> reachable_nodes(const Graph& g, Iter first, Iter last)
60{
61 typedef boost::color_traits<boost::default_color_type> Color;
62
63 std::vector<std::size_t> result;
64 detail::reachable_nodes_recorder<Graph> recorder(result);
65 std::vector<boost::default_color_type> colormap(boost::num_vertices(g), Color::white());
66
67 for (Iter i = first; i != last; ++i)
68 {
69 boost::default_color_type c = Color::white();
70 boost::depth_first_visit(g,
71 *i,
72 recorder,
73 boost::make_iterator_property_map(colormap.begin(), boost::get(boost::vertex_index, g), c)
74 );
75 }
76
77 return result;
78}
79
80} // namespace utilities
81
82} // namespace mcrl2
83
84#endif // MCRL2_UTILITIES_REACHABLE_NODES_H
std::vector< std::size_t > reachable_nodes(const Graph &g, Iter first, Iter last)
Compute reachable nodes in a graph.
A class that takes a linear process specification and checks all tau-summands of that LPS for conflue...
Definition indexed_set.h:72