pdegen & toparity: minor refactor
* spot/twaalgos/degen.hh (is_partially_degeneralizable): Pass the forbid vector by reference, and document it. I hope that not passing forbid by copy will get rid of a spurious "potential nullptr" warning by gcc on Arch Linux. * spot/twaalgos/degen.cc: Adjust, and refactor the code a bit. * spot/twaalgos/toparity.cc: Likewise.
This commit is contained in:
parent
ed91f59bbd
commit
2bd2abd4c9
3 changed files with 126 additions and 128 deletions
|
|
@ -872,7 +872,7 @@ namespace spot
|
|||
acc_cond::mark_t
|
||||
is_partially_degeneralizable(const const_twa_graph_ptr& aut,
|
||||
bool allow_inf, bool allow_fin,
|
||||
std::vector<acc_cond::mark_t> forbid)
|
||||
const std::vector<acc_cond::mark_t>& forbid)
|
||||
{
|
||||
auto& code = aut->get_acceptance();
|
||||
|
||||
|
|
@ -881,16 +881,19 @@ namespace spot
|
|||
|
||||
acc_cond::mark_t res = {};
|
||||
unsigned res_sz = -1U;
|
||||
auto update = [&](const acc_cond::mark_t& m)
|
||||
|
||||
auto keep_smallest_mark = [&](const acc_cond::mark_t& m)
|
||||
{
|
||||
if (std::find(forbid.begin(), forbid.end(), m) != forbid.end())
|
||||
return false;
|
||||
unsigned sz = m.count();
|
||||
if (sz > 1 && sz < res_sz)
|
||||
{
|
||||
res_sz = sz;
|
||||
res = m;
|
||||
}
|
||||
// If we have found a pair to degeneralize, we
|
||||
// won't find
|
||||
// If we have found a pair to degeneralize, we won't find a
|
||||
// smaller one.
|
||||
return res_sz == 2;
|
||||
};
|
||||
|
||||
|
|
@ -906,22 +909,14 @@ namespace spot
|
|||
case acc_cond::acc_op::Fin:
|
||||
case acc_cond::acc_op::FinNeg:
|
||||
pos -= 2;
|
||||
if (allow_fin)
|
||||
{
|
||||
auto m = code[pos].mark;
|
||||
if (!std::count(forbid.begin(), forbid.end(), m) && update(m))
|
||||
if (allow_fin && keep_smallest_mark(code[pos].mark))
|
||||
return res;
|
||||
}
|
||||
break;
|
||||
case acc_cond::acc_op::Inf:
|
||||
case acc_cond::acc_op::InfNeg:
|
||||
pos -= 2;
|
||||
if (allow_inf)
|
||||
{
|
||||
auto m = code[pos].mark;
|
||||
if (!std::count(forbid.begin(), forbid.end(), m) && update(m))
|
||||
if (allow_inf && keep_smallest_mark(code[pos].mark))
|
||||
return res;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -158,11 +158,14 @@ namespace spot
|
|||
///
|
||||
/// The optional arguments \a allow_inf and \a allow_fin, can be set
|
||||
/// to false to disallow one type of match.
|
||||
///
|
||||
/// If you need to disallow certain marks from being returned, pass
|
||||
/// them in the \a forbid vector.
|
||||
SPOT_API acc_cond::mark_t
|
||||
is_partially_degeneralizable(const const_twa_graph_ptr& aut,
|
||||
bool allow_inf = true,
|
||||
bool allow_fin = true,
|
||||
std::vector<acc_cond::mark_t> forbid = {});
|
||||
bool allow_inf = true, bool allow_fin = true,
|
||||
const std::vector<acc_cond::mark_t>&
|
||||
forbid = {});
|
||||
|
||||
/// \ingroup twa_algorithms
|
||||
/// \brief Propagate marks around the automaton
|
||||
|
|
|
|||
|
|
@ -2248,7 +2248,8 @@ namespace spot
|
|||
{
|
||||
// If we don't try to find a parity prefix, we can stop
|
||||
// to construct the tree when it has not parity shape.
|
||||
zielonka_tree_options zopt = zielonka_tree_options::MERGE_SUBTREES
|
||||
zielonka_tree_options zopt =
|
||||
zielonka_tree_options::MERGE_SUBTREES
|
||||
| zielonka_tree_options::CHECK_PARITY;
|
||||
if (!opt_.parity_prefix)
|
||||
zopt = zopt | zielonka_tree_options::ABORT_WRONG_SHAPE;
|
||||
|
|
@ -2265,21 +2266,21 @@ namespace spot
|
|||
&& try_parity_prefix_general(sub_aut))
|
||||
return;
|
||||
|
||||
if (opt_.generic_emptiness && !tried_emptiness
|
||||
&& try_emptiness(sub_aut, tried_emptiness))
|
||||
if (opt_.generic_emptiness
|
||||
&& !tried_emptiness && try_emptiness(sub_aut, tried_emptiness))
|
||||
return;
|
||||
|
||||
// Buchi_type_to_buchi is more general that Rabin_to_buchi so
|
||||
// we just call rabin_to_buchi if buchi_type_to_buchi is false.
|
||||
if (!opt_.buchi_type_to_buchi && !opt_.parity_type_to_parity
|
||||
&& opt_.rabin_to_buchi
|
||||
if (!opt_.buchi_type_to_buchi
|
||||
&& !opt_.parity_type_to_parity && opt_.rabin_to_buchi
|
||||
&& try_rabin_to_buchi(sub_aut))
|
||||
return;
|
||||
|
||||
// As parity_type_to_parity is stronger, we don't
|
||||
// try if this option is used.
|
||||
if (opt_.buchi_type_to_buchi && !opt_.parity_type_to_parity
|
||||
&& try_buchi_type(sub_aut))
|
||||
if (opt_.buchi_type_to_buchi
|
||||
&& !opt_.parity_type_to_parity && try_buchi_type(sub_aut))
|
||||
return;
|
||||
|
||||
// We don't do it if parity_prefix_general is true as on a parity-type
|
||||
|
|
@ -2289,16 +2290,15 @@ namespace spot
|
|||
&& try_parity_type(sub_aut))
|
||||
return;
|
||||
|
||||
if (opt_.partial_degen
|
||||
&& is_partially_degeneralizable(sub_aut, true, true))
|
||||
if (opt_.partial_degen)
|
||||
{
|
||||
auto deg = sub_aut;
|
||||
twa_graph_ptr deg = sub_aut;
|
||||
std::vector<acc_cond::mark_t> forbid;
|
||||
auto m = is_partially_degeneralizable(sub_aut, true, true, forbid);
|
||||
bool changed = false;
|
||||
while (m)
|
||||
while (acc_cond::mark_t m =
|
||||
is_partially_degeneralizable(deg, true, true, forbid))
|
||||
{
|
||||
auto tmp = partial_degeneralize(deg, m);
|
||||
twa_graph_ptr tmp = partial_degeneralize(deg, m);
|
||||
simplify_acceptance_here(tmp);
|
||||
if (keep_deg(deg, tmp))
|
||||
{
|
||||
|
|
@ -2308,10 +2308,10 @@ namespace spot
|
|||
changed_structure = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
forbid.emplace_back(m);
|
||||
m = is_partially_degeneralizable(deg, true, true, forbid);
|
||||
}
|
||||
|
||||
}
|
||||
if (changed)
|
||||
{
|
||||
sub_aut = deg;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue