12#ifndef MCRL2_PBES_PBESINST_LAZY_COUNTER_EXAMPLE_H
13#define MCRL2_PBES_PBESINST_LAZY_COUNTER_EXAMPLE_H
15#include "mcrl2/pbes/pbesinst_structure_graph.h"
16#include "mcrl2/pbes/pbesinst_structure_graph2.h"
17#include "mcrl2/pbes/replace.h"
18#include "mcrl2/pbes/rewriters/simplify_quantifiers_rewriter.h"
19#include "mcrl2/pbes/structure_graph.h"
20#include "mcrl2/utilities/exception.h"
21#include "mcrl2/utilities/logger.h"
22#include "mcrl2/utilities/math.h"
36 if (R.find(PVI.name()) != R.end())
38 const std::set<
int> Rx = R.at(PVI.name());
39 data::data_expression_vector params(PVI.parameters().begin(), PVI.parameters().end());
40 data::data_expression_vector params_r;
41 for (std::vector<data::data_expression>::size_type i = 0; i < params.size(); i++)
43 if (Rx.find(
static_cast<
int>(i)) != Rx.end())
49 params_r.push_back(params[i]);
52 return propositional_variable_instantiation(PVI.name(),
53 data::data_expression_list(params_r.begin(), params_r.end()));
75 const std::unordered_map<pbes_expression, structure_graph::index_type>& mapping,
89 mCRL2log(log::trace) <<
"rewrite_star " << Y <<
" contains free variables, not applying substitution\n";
96 mCRL2log(log::debug) <<
"X = " << X << std::endl;
98 std::unordered_set<pbes_expression> Ys;
101 auto it = mapping.find(rewrite_PVI(X, R));
102 if (it != mapping.end())
105 std::unordered_set<structure_graph::index_type> todo = {index};
106 std::unordered_set<structure_graph::index_type> done;
108 while (!todo.empty())
110 structure_graph::index_type u = *todo.begin();
111 todo.erase(todo.begin());
114 if (mapping.count(G.find_vertex(u).formula()) != 0)
118 if (G.strategy(u) == undefined_vertex() &&
119 ((!alpha && utilities::is_even(G.rank(u)) && G.decoration(u) == structure_graph::d_true)
120 || (alpha && utilities::is_odd(G.rank(u)) && G.decoration(u) == structure_graph::d_false)))
123 Ys.insert(G.find_vertex(u).formula());
126 if (G.strategy(u) != undefined_vertex()
127 && ((!alpha && G.decoration(u) == structure_graph::d_disjunction)
128 || (alpha && G.decoration(u) == structure_graph::d_conjunction)))
131 auto v = G.strategy(u);
132 if (G.rank(v) == data::undefined_index())
134 if (!mcrl2::utilities::detail::contains(done, v))
140 else if (mapping.count(G.find_vertex(v).formula()) != 0)
143 Ys.insert(G.find_vertex(v).formula());
149 for (structure_graph::index_type v: G.all_successors(u))
151 if (G.rank(v) == data::undefined_index())
153 if (!mcrl2::utilities::detail::contains(done, v))
159 else if (mapping.count(G.find_vertex(v).formula()) != 0)
162 Ys.insert(G.find_vertex(v).formula());
170 for (structure_graph::index_type v: G.all_successors(u))
172 if (G.rank(v) == data::undefined_index())
174 if (!mcrl2::utilities::detail::contains(done, v))
180 else if (mapping.count(G.find_vertex(v).formula()) != 0)
183 Ys.insert(G.find_vertex(v).formula());
190 mCRL2log(log::debug) <<
"Ys := " << core::detail::print_set(Ys) << std::endl;
192 if (std::regex_match(
static_cast<
const std::string&>(Y.name()),
194 mcrl2::pbes_system::detail::positive_or_negative))
197 mCRL2log(log::debug) <<
"rewrite_star " << Y <<
" is counter example equation (in L)" << std::endl;
202 if (mcrl2::utilities::detail::contains(Ys, rewrite_PVI(Y, R)))
204 mCRL2log(log::debug) <<
"rewrite_star " << Y <<
" ( " << rewrite_PVI(Y, R) <<
") is reachable"
213 mCRL2log(log::debug) <<
"rewrite_star " << Y <<
" " << rewrite_PVI(Y, R)
214 <<
" is not reachable, becomes false" << std::endl;
220 mCRL2log(log::debug) <<
"rewrite_star " << Y <<
" " << rewrite_PVI(Y, R)
221 <<
" is not reachable, becomes true" << std::endl;
237 const std::unordered_map<pbes_expression, structure_graph::index_type>& _mapping,
239 std::optional<data::rewriter> rewriter =
std::
nullopt,
256 return compose_substitutions(pbesinst_structure_graph_algorithm::phi_substitution(thread_index, symbol, X, phi),
257 detail::rewrite_star_substitution(symbol, X, G, alpha, mapping, R));
274 const std::unordered_map<pbes_expression, structure_graph::index_type>& _mapping,
276 std::optional<data::rewriter> rewriter =
std::
nullopt,
291 return compose_substitutions(pbesinst_structure_graph_algorithm::phi_substitution(thread_index, symbol, X, phi),
292 detail::rewrite_star_substitution(symbol, X, G, alpha, mapping, R));
parameterized boolean equation system
pbesinst_counter_example_structure_graph_algorithm2(const pbessolve_options &options, const pbes &p, const structure_graph &SG, bool _alpha, const std::unordered_map< pbes_expression, structure_graph::index_type > &_mapping, structure_graph &G, std::optional< data::rewriter > rewriter=std::nullopt, const std::unordered_map< std::string, std::set< int > > R={})
std::function< pbes_expression(const propositional_variable_instantiation &)> phi_substitution(const std::size_t thread_index, const fixpoint_symbol &symbol, const propositional_variable_instantiation &X, const pbes_expression &phi) override
const std::unordered_map< pbes_expression, structure_graph::index_type > & mapping
const structure_graph & G
const std::unordered_map< pbes_expression, structure_graph::index_type > & mapping
const structure_graph & G
std::function< pbes_expression(const propositional_variable_instantiation &)> phi_substitution(const std::size_t thread_index, const fixpoint_symbol &symbol, const propositional_variable_instantiation &X, const pbes_expression &phi) override
pbesinst_counter_example_structure_graph_algorithm(const pbessolve_options &options, const pbes &p, const structure_graph &SG, bool _alpha, const std::unordered_map< pbes_expression, structure_graph::index_type > &_mapping, structure_graph &G, std::optional< data::rewriter > rewriter=std::nullopt, const std::unordered_map< std::string, std::set< int > > R={})
Adds an optimization to pbesinst_structure_graph.
Variant of pbesinst that will compute a structure graph for a PBES. The result will be put in the str...
\brief A propositional variable instantiation
#define mCRL2log(LEVEL)
mCRL2log(LEVEL) provides the stream used to log.
propositional_variable_instantiation rewrite_PVI(const propositional_variable_instantiation PVI, const std::unordered_map< std::string, std::set< int > > R)
For a given X(e) and set of redundant params R, returns a copy of X(e) without redundancy.
const pbes_expression & true_()
std::set< data::variable > find_free_variables(const pbes_system::pbes_expression &x)
const pbes_expression & false_()
const structure_graph & G
const fixpoint_symbol & symbol
rewrite_star_substitution(const fixpoint_symbol &symbol, const propositional_variable_instantiation &X, const structure_graph &G, bool alpha, const std::unordered_map< pbes_expression, structure_graph::index_type > &mapping, const std::unordered_map< std::string, std::set< int > > &R)
pbes_expression operator()(const propositional_variable_instantiation &Y) const
const std::unordered_map< pbes_expression, structure_graph::index_type > & mapping
const propositional_variable_instantiation & X