genem: Implement accepting cycle search

Implement an accepting run search in spot::sccinfo, use it with the
generic emptiness check.

* spot/twaalgos/sccinfo.cc, spot/twaalgos/sccinfo.hh: Here.
* spot/twaalgos/genem.cc, spot/twaalgos/genem.hh: Use it.
* tests/python/genem.py: Test it.
This commit is contained in:
Clément Gillard 2018-12-11 13:43:53 +01:00 committed by Alexandre Duret-Lutz
parent 4ecd066c0e
commit 51ca5ecdb1
5 changed files with 217 additions and 16 deletions

View file

@ -50,10 +50,11 @@ namespace spot
}
};
bool scc_split_check(const scc_info& si, unsigned scc,
bool scc_split_check(const scc_info& si, unsigned scc, twa_run_ptr run,
acc_cond::mark_t tocut,
bool (*ec_scc)(const scc_info& si,
unsigned scc,
twa_run_ptr run,
acc_cond::mark_t tocut))
{
struct filter_data_t {
@ -85,14 +86,21 @@ namespace spot
acc = acc.remove(si.common_sets_of(scc), false);
temporary_acc_set tmp(si.get_aut(), acc);
scc_info upper_si(si.get_aut(), si.one_state_of(scc), filter, &data,
scc_info_options::STOP_ON_ACC);
if (upper_si.one_accepting_scc() >= 0)
scc_info_options::STOP_ON_ACC
| scc_info_options::TRACK_STATES);
const int accepting_scc = upper_si.one_accepting_scc();
if (accepting_scc >= 0)
{
if (run)
upper_si.get_accepting_run(accepting_scc, run);
return false;
}
if (!acc.uses_fin_acceptance())
return true;
unsigned nscc = upper_si.scc_count();
for (unsigned scc = 0; scc < nscc; ++scc)
if (!ec_scc(upper_si, scc, tocut))
if (!ec_scc(upper_si, scc, run, tocut))
return false;
return true;
}
@ -100,6 +108,7 @@ namespace spot
template <bool deal_with_disjunct>
bool generic_emptiness_check_for_scc_nocopy(const scc_info& si,
unsigned scc,
twa_run_ptr run,
acc_cond::mark_t
tocut = {})
{
@ -112,11 +121,15 @@ namespace spot
if (acc.is_f())
return true;
if (acc.is_t())
{
if (run)
si.get_accepting_run(scc, run);
return false;
}
temporary_acc_set tmp(si.get_aut(), acc);
if (acc_cond::mark_t fu = acc.fin_unit())
return scc_split_check
(si, scc, tocut | fu,
(si, scc, run, tocut | fu,
generic_emptiness_check_for_scc_nocopy<deal_with_disjunct>);
if (deal_with_disjunct)
@ -141,7 +154,7 @@ namespace spot
if (acc_cond::mark_t fu = one.fin_unit())
plus = fu;
if (!scc_split_check
(si, scc, tocut | plus,
(si, scc, run, tocut | plus,
generic_emptiness_check_for_scc_nocopy
<deal_with_disjunct>))
return false;
@ -157,7 +170,7 @@ namespace spot
tmp.set(acc_cond::acc_code());
for (unsigned d: pos[-1].mark.sets())
if (!scc_split_check
(si, scc,
(si, scc, run,
tocut | acc_cond::mark_t({d}),
generic_emptiness_check_for_scc_nocopy
<deal_with_disjunct>))
@ -170,36 +183,54 @@ namespace spot
assert(fo >= 0);
// Try to accept when Fin(fo) == true
if (!scc_split_check
(si, scc, tocut | acc_cond::mark_t({(unsigned) fo}),
(si, scc, run, tocut | acc_cond::mark_t({(unsigned) fo}),
generic_emptiness_check_for_scc_nocopy
<deal_with_disjunct>))
return false;
// Try to accept when Fin(fo) == false
tmp.set(acc.force_inf({(unsigned) fo}));
return generic_emptiness_check_for_scc_nocopy
<deal_with_disjunct>(si, scc, tocut);
return true;
<deal_with_disjunct>(si, scc, run, tocut);
}
template <bool deal_with_disjunct>
bool generic_emptiness_check_main_nocopy(const twa_graph_ptr& aut)
bool generic_emptiness_check_main_nocopy(const twa_graph_ptr& aut,
twa_run_ptr run)
{
cleanup_acceptance_here(aut, false);
auto& aut_acc = aut->acc();
if (aut_acc.is_f())
return true;
if (!aut->acc().uses_fin_acceptance())
{
if (run)
{
auto p = aut->accepting_run();
if (p)
{
*run = *p;
return false;
}
return true;
}
return aut->is_empty();
}
scc_info si(aut, scc_info_options::STOP_ON_ACC
| scc_info_options::TRACK_STATES);
if (si.one_accepting_scc() >= 0)
const int accepting_scc = si.one_accepting_scc();
if (accepting_scc >= 0)
{
if (run)
si.get_accepting_run(accepting_scc, run);
return false;
}
unsigned nscc = si.scc_count();
for (unsigned scc = 0; scc < nscc; ++scc)
if (!generic_emptiness_check_for_scc_nocopy
<deal_with_disjunct>(si, scc))
<deal_with_disjunct>(si, scc, run))
return false;
return true;
}
@ -212,17 +243,35 @@ namespace spot
"does not support alternating automata");
auto aut_ = std::const_pointer_cast<twa_graph>(aut);
acc_cond old = aut_->acc();
bool res = generic_emptiness_check_main_nocopy<true>(aut_);
bool res = generic_emptiness_check_main_nocopy<true>(aut_, nullptr);
aut_->set_acceptance(old);
return res;
}
twa_run_ptr generic_accepting_run(const const_twa_graph_ptr& aut)
{
if (SPOT_UNLIKELY(!aut->is_existential()))
throw std::runtime_error("generic_accepting_run() "
"does not support alternating automata");
auto aut_ = std::const_pointer_cast<twa_graph>(aut);
acc_cond old = aut_->acc();
twa_run_ptr run = std::make_shared<twa_run>(aut_);
bool res = generic_emptiness_check_main_nocopy<true>(aut_, run);
aut_->set_acceptance(old);
if (!res)
return run;
return nullptr;
}
bool generic_emptiness_check_for_scc(const scc_info& si,
unsigned scc)
{
if (SPOT_UNLIKELY(!si.get_aut()->is_existential()))
throw std::runtime_error("generic_emptiness_check_for_scc() "
"does not support alternating automata");
return generic_emptiness_check_for_scc_nocopy<true>(si, scc);
return generic_emptiness_check_for_scc_nocopy<true>(si, scc, nullptr);
}
}