12#ifndef MCRL2_PBES_STRUCTURE_GRAPH_H
13#define MCRL2_PBES_STRUCTURE_GRAPH_H
16#include <boost/dynamic_bitset.hpp>
17#include <boost/range/adaptor/filtered.hpp>
19#include "mcrl2/atermpp/standard_containers/vector.h"
20#include "mcrl2/core/detail/print_utility.h"
21#include "mcrl2/pbes/pbes.h"
35 return std::numeric_limits<
unsigned int>::max();
56 using index_type =
unsigned int;
84 predecessors.erase(std::remove(predecessors.begin(), predecessors.end(), u), predecessors.end());
95 successors.erase(std::remove(successors.begin(), successors.end(), u), successors.end());
100 return ((decoration != structure_graph::d_none) || (rank != data::undefined_index()))
101 && (!successors.empty() || (decoration == d_true || decoration == d_false));
104 void inline mark(atermpp::term_mark_stack& todo)
const
106 mark_term(m_formula, todo);
143 std::size_t i = &v - &
static_cast<
const vertex&>(vertices.front());
151 structure_graph(vertex_vector vertices, index_type initial_vertex, boost::dynamic_bitset<> exclude)
164 return m_vertices.size();
194 return all_vertices() | boost::adaptors::filtered(vertices_not_contained_in(m_vertices, m_exclude));
199 return all_predecessors(u) | boost::adaptors::filtered(integers_not_contained_in(m_exclude));
204 return all_successors(u) | boost::adaptors::filtered(integers_not_contained_in(m_exclude));
214 return m_vertices[u];
219 return m_vertices[u];
234 return !m_exclude[u];
240 return m_exclude.all();
246 return std::all_of(m_vertices.begin(), m_vertices.end(), [](
const vertex& u) {
return u.is_defined(); });
250template <
typename StructureGraph>
253 std::vector<
typename StructureGraph::index_type> result;
254 for (
auto v: G.predecessors(u))
261template <
typename StructureGraph>
264 std::vector<
typename StructureGraph::index_type> result;
265 for (
auto v: G.successors(u))
281 default : { out <<
"none";
break; }
289 out <<
"vertex(formula = " << u.formula()
290 <<
", decoration = " << u.decoration
291 <<
", rank = " << (u.rank == data::undefined_index() ? std::string(
"undefined") : std::to_string(u.rank))
292 <<
", predecessors = " << core::detail::print_list(u.predecessors)
293 <<
", successors = " << core::detail::print_list(u.successors)
294 <<
", strategy = " << (u.strategy == undefined_vertex() ? std::string(
"undefined") : std::to_string(u.strategy))
299template <
typename StructureGraph>
302 auto N = G.all_vertices().size();
303 for (std::size_t i = 0; i < N; i++)
307 const structure_graph::vertex& u = G.find_vertex(i);
308 out << std::setw(4) << i <<
" "
309 <<
"vertex(formula = " << u.formula()
310 <<
", decoration = " << u.decoration
311 <<
", rank = " << (u.rank == data::undefined_index() ? std::string(
"undefined") : std::to_string(u.rank))
312 <<
", predecessors = " << core::detail::print_list(structure_graph_predecessors(G, i))
313 <<
", successors = " << core::detail::print_list(structure_graph_successors(G, i))
314 <<
", strategy = " << (u.strategy == undefined_vertex() ? std::string(
"undefined") : std::to_string(u.strategy))
321 out <<
" empty" << std::endl;
329 return print_structure_graph(out, G);
boost::dynamic_bitset & exclude()
boost::filtered_range< vertices_not_contained_in, const vertex_vector > vertices() const
structure_graph(vertex_vector vertices, index_type initial_vertex, boost::dynamic_bitset<> exclude)
index_type initial_vertex() const
boost::filtered_range< integers_not_contained_in, const std::vector< index_type > > predecessors(index_type u) const
const std::vector< index_type > & all_successors(index_type u) const
boost::dynamic_bitset m_exclude
const std::vector< index_type > & all_predecessors(index_type u) const
std::size_t extent() const
const boost::dynamic_bitset & exclude() const
structure_graph()=default
const vertex_vector & all_vertices() const
boost::filtered_range< integers_not_contained_in, const std::vector< index_type > > successors(index_type u) const
const vertex & find_vertex(index_type u) const
bool contains(index_type u) const
index_type m_initial_vertex
vertex & find_vertex(index_type u)
std::size_t rank(index_type u) const
index_type strategy(index_type u) const
decoration_type decoration(index_type u) const
std::vector< typename StructureGraph::index_type > structure_graph_successors(const StructureGraph &G, typename StructureGraph::index_type u)
std::ostream & operator<<(std::ostream &out, const structure_graph::decoration_type &decoration)
std::ostream & operator<<(std::ostream &out, const structure_graph::vertex &u)
constexpr unsigned int undefined_vertex()
std::vector< typename StructureGraph::index_type > structure_graph_predecessors(const StructureGraph &G, typename StructureGraph::index_type u)
std::ostream & print_structure_graph(std::ostream &out, const StructureGraph &G)
std::ostream & operator<<(std::ostream &out, const structure_graph &G)
bool operator()(index_type i) const
integers_not_contained_in(const boost::dynamic_bitset<> &subset_)
const boost::dynamic_bitset & subset
void remove_predecessor(index_type u)
std::vector< index_type > successors
atermpp::detail::reference_aterm< pbes_expression > m_formula
vertex(pbes_expression formula_, decoration_type decoration_=structure_graph::d_none, std::size_t rank_=data::undefined_index(), std::vector< index_type > pred_=std::vector< index_type >(), std::vector< index_type > succ_=std::vector< index_type >(), index_type strategy_=undefined_vertex())
decoration_type decoration
const pbes_expression & formula() const
std::vector< index_type > predecessors
void mark(atermpp::term_mark_stack &todo) const
void remove_successor(index_type u)
const boost::dynamic_bitset & subset
vertices_not_contained_in(const vertex_vector &vertices_, const boost::dynamic_bitset<> &subset_)
const vertex_vector & vertices
bool operator()(const vertex &v) const