Handle all automata through shared_ptr. (monstro patch)

A type such as 'const tgba_digraph*' and 'tgba_digraph*' are replaced
by 'const_tgba_digraph_ptr' and 'tgba_digraph_ptr'.  Additionally 'new
tgba_digraph(...)' is replaced by 'make_tgba_digraph(...)'.

This convention is followed by all automata types. Those smart
pointers should normally be passed by const reference as input of
function to avoid the atomic increments/decrements, but I probably
missed a few, as this huge patch took me nearly 12h.

* src/kripke/fwd.hh, src/tgba/fwd.hh: New files.
* src/kripke/Makefile.am, src/tgba/Makefile.am: Adjust.
* iface/dve2/dve2.cc, iface/dve2/dve2.hh, iface/dve2/dve2check.cc,
src/bin/common_output.hh, src/bin/dstar2tgba.cc,
src/bin/ltl2tgba.cc, src/bin/ltl2tgta.cc, src/bin/ltlcross.cc,
src/bin/ltlfilt.cc, src/dstarparse/dra2ba.cc,
src/dstarparse/dstar2tgba.cc, src/dstarparse/dstarparse.yy,
src/dstarparse/nra2nba.cc, src/dstarparse/nsa2tgba.cc,
src/dstarparse/public.hh, src/graphtest/tgbagraph.cc,
src/kripke/fairkripke.hh, src/kripke/kripke.hh,
src/kripke/kripkeexplicit.cc, src/kripke/kripkeexplicit.hh,
src/kripke/kripkeprint.cc, src/kripke/kripkeprint.hh,
src/kripkeparse/kripkeparse.yy, src/kripkeparse/public.hh,
src/kripketest/parse_print_test.cc, src/ltlvisit/apcollect.cc,
src/ltlvisit/apcollect.hh, src/ltlvisit/contain.cc,
src/ltlvisit/contain.hh, src/neverparse/neverclaimparse.yy,
src/neverparse/public.hh, src/priv/accmap.hh,
src/priv/countstates.cc, src/priv/countstates.hh, src/saba/saba.hh,
src/saba/sabacomplementtgba.cc, src/saba/sabacomplementtgba.hh,
src/sabaalgos/sabadotty.cc, src/sabaalgos/sabadotty.hh,
src/sabaalgos/sabareachiter.cc, src/sabaalgos/sabareachiter.hh,
src/sabatest/sabacomplementtgba.cc, src/ta/ta.hh,
src/ta/taexplicit.cc, src/ta/taexplicit.hh, src/ta/taproduct.cc,
src/ta/taproduct.hh, src/ta/tgta.hh, src/ta/tgtaexplicit.cc,
src/ta/tgtaexplicit.hh, src/ta/tgtaproduct.cc,
src/ta/tgtaproduct.hh, src/taalgos/dotty.cc, src/taalgos/dotty.hh,
src/taalgos/emptinessta.cc, src/taalgos/emptinessta.hh,
src/taalgos/minimize.cc, src/taalgos/minimize.hh,
src/taalgos/reachiter.cc, src/taalgos/reachiter.hh,
src/taalgos/statessetbuilder.cc, src/taalgos/statessetbuilder.hh,
src/taalgos/stats.cc, src/taalgos/stats.hh, src/taalgos/tgba2ta.cc,
src/taalgos/tgba2ta.hh, src/tgba/bdddict.cc, src/tgba/bdddict.hh,
src/tgba/formula2bdd.hh, src/tgba/futurecondcol.cc,
src/tgba/futurecondcol.hh, src/tgba/taatgba.hh, src/tgba/tgba.cc,
src/tgba/tgba.hh, src/tgba/tgbagraph.hh,
src/tgba/tgbakvcomplement.cc, src/tgba/tgbakvcomplement.hh,
src/tgba/tgbamask.cc, src/tgba/tgbamask.hh, src/tgba/tgbaproduct.cc,
src/tgba/tgbaproduct.hh, src/tgba/tgbaproxy.cc,
src/tgba/tgbaproxy.hh, src/tgba/tgbasafracomplement.cc,
src/tgba/tgbasafracomplement.hh, src/tgba/tgbascc.cc,
src/tgba/tgbascc.hh, src/tgba/tgbasgba.cc, src/tgba/tgbasgba.hh,
src/tgba/wdbacomp.cc, src/tgba/wdbacomp.hh,
src/tgbaalgos/bfssteps.cc, src/tgbaalgos/bfssteps.hh,
src/tgbaalgos/complete.cc, src/tgbaalgos/complete.hh,
src/tgbaalgos/compsusp.cc, src/tgbaalgos/compsusp.hh,
src/tgbaalgos/cycles.hh, src/tgbaalgos/degen.cc,
src/tgbaalgos/degen.hh, src/tgbaalgos/dotty.cc,
src/tgbaalgos/dotty.hh, src/tgbaalgos/dottydec.cc,
src/tgbaalgos/dottydec.hh, src/tgbaalgos/dtbasat.cc,
src/tgbaalgos/dtbasat.hh, src/tgbaalgos/dtgbacomp.cc,
src/tgbaalgos/dtgbacomp.hh, src/tgbaalgos/dtgbasat.cc,
src/tgbaalgos/dtgbasat.hh, src/tgbaalgos/dupexp.cc,
src/tgbaalgos/dupexp.hh, src/tgbaalgos/emptiness.cc,
src/tgbaalgos/emptiness.hh, src/tgbaalgos/gtec/gtec.cc,
src/tgbaalgos/gtec/gtec.hh, src/tgbaalgos/gtec/status.cc,
src/tgbaalgos/gtec/status.hh, src/tgbaalgos/gv04.cc,
src/tgbaalgos/gv04.hh, src/tgbaalgos/isdet.cc,
src/tgbaalgos/isdet.hh, src/tgbaalgos/isweakscc.cc,
src/tgbaalgos/lbtt.cc, src/tgbaalgos/lbtt.hh,
src/tgbaalgos/ltl2taa.cc, src/tgbaalgos/ltl2taa.hh,
src/tgbaalgos/ltl2tgba_fm.cc, src/tgbaalgos/ltl2tgba_fm.hh,
src/tgbaalgos/magic.cc, src/tgbaalgos/magic.hh,
src/tgbaalgos/minimize.cc, src/tgbaalgos/minimize.hh,
src/tgbaalgos/ndfs_result.hxx, src/tgbaalgos/neverclaim.cc,
src/tgbaalgos/neverclaim.hh, src/tgbaalgos/postproc.cc,
src/tgbaalgos/postproc.hh, src/tgbaalgos/powerset.cc,
src/tgbaalgos/powerset.hh, src/tgbaalgos/projrun.cc,
src/tgbaalgos/projrun.hh, src/tgbaalgos/randomgraph.cc,
src/tgbaalgos/randomgraph.hh, src/tgbaalgos/reachiter.cc,
src/tgbaalgos/reachiter.hh, src/tgbaalgos/reducerun.cc,
src/tgbaalgos/reducerun.hh, src/tgbaalgos/replayrun.cc,
src/tgbaalgos/replayrun.hh, src/tgbaalgos/rundotdec.cc,
src/tgbaalgos/rundotdec.hh, src/tgbaalgos/safety.cc,
src/tgbaalgos/safety.hh, src/tgbaalgos/save.cc,
src/tgbaalgos/save.hh, src/tgbaalgos/scc.cc, src/tgbaalgos/scc.hh,
src/tgbaalgos/sccfilter.cc, src/tgbaalgos/sccfilter.hh,
src/tgbaalgos/sccinfo.cc, src/tgbaalgos/sccinfo.hh,
src/tgbaalgos/se05.cc, src/tgbaalgos/se05.hh,
src/tgbaalgos/simulation.cc, src/tgbaalgos/simulation.hh,
src/tgbaalgos/stats.cc, src/tgbaalgos/stats.hh,
src/tgbaalgos/stripacc.cc, src/tgbaalgos/stripacc.hh,
src/tgbaalgos/tau03.cc, src/tgbaalgos/tau03.hh,
src/tgbaalgos/tau03opt.cc, src/tgbaalgos/tau03opt.hh,
src/tgbaalgos/translate.cc, src/tgbaalgos/translate.hh,
src/tgbaparse/public.hh, src/tgbaparse/tgbaparse.yy,
src/tgbatest/complementation.cc, src/tgbatest/explprod.cc,
src/tgbatest/ltl2tgba.cc, src/tgbatest/ltlprod.cc,
src/tgbatest/maskacc.cc, src/tgbatest/powerset.cc,
src/tgbatest/randtgba.cc, src/tgbatest/taatgba.cc,
src/tgbatest/tgbaread.cc, src/tgbatest/tripprod.cc,
wrap/python/ajax/spot.in, wrap/python/spot.i,
wrap/python/tests/interdep.py: Use shared pointers for automata.
This commit is contained in:
Alexandre Duret-Lutz 2014-08-14 20:18:04 +02:00
parent ca85d4184d
commit 51151ab271
195 changed files with 1792 additions and 1837 deletions

View file

@ -74,7 +74,8 @@ namespace spot
}
}
const tgba_digraph* postprocessor::do_simul(const tgba_digraph* a, int opt)
tgba_digraph_ptr
postprocessor::do_simul(const tgba_digraph_ptr& a, int opt)
{
switch (opt)
{
@ -94,8 +95,8 @@ namespace spot
}
}
const tgba_digraph* postprocessor::do_ba_simul(const tgba_digraph* a,
int opt)
tgba_digraph_ptr
postprocessor::do_ba_simul(const tgba_digraph_ptr& a, int opt)
{
switch (opt)
{
@ -112,27 +113,22 @@ namespace spot
}
const tgba_digraph* postprocessor::do_degen(const tgba_digraph* a)
tgba_digraph_ptr
postprocessor::do_degen(const tgba_digraph_ptr& a)
{
auto d = degeneralize(a,
degen_reset_, degen_order_,
degen_cache_, degen_lskip_);
delete a;
if (ba_simul_ <= 0)
return d;
auto s = do_ba_simul(d, ba_simul_);
if (s != d)
delete d;
return s;
return do_ba_simul(d, ba_simul_);
}
#define PREF_ (pref_ & (Small | Deterministic))
#define COMP_ (pref_ & Complete)
const tgba_digraph*
postprocessor::run(const tgba_digraph* a, const ltl::formula* f)
tgba_digraph_ptr
postprocessor::run(tgba_digraph_ptr a, const ltl::formula* f)
{
if (type_ == TGBA && PREF_ == Any && level_ == Low)
return a;
@ -150,64 +146,35 @@ namespace spot
// Remove useless SCCs.
if (type_ == Monitor)
{
// Do not bother about acceptance conditions, they will be
// ignored.
auto s = scc_filter_states(a);
delete a;
a = s;
}
// Do not bother about acceptance conditions, they will be
// ignored.
a = scc_filter_states(a);
else if (scc_filter_ > 0)
{
auto s = scc_filter(a, scc_filter_ > 1);
delete a;
a = s;
}
a = scc_filter(a, scc_filter_ > 1);
if (type_ == Monitor)
{
if (PREF_ == Deterministic)
{
auto m = minimize_monitor(a);
delete a;
return m;
}
a = minimize_monitor(a);
else
{
strip_acceptance_here(const_cast<tgba_digraph*>(a));
}
strip_acceptance_here(a);
if (PREF_ == Any)
return a;
auto sim = do_simul(a, simul_);
if (a == sim)
// simulation was disabled.
return a;
if (level_ != High)
{
delete a;
return sim;
}
a = do_simul(a, simul_);
// For Small,High we return the smallest between the output of
// the simulation, and that of the deterministic minimization.
auto m = minimize_monitor(a);
delete a;
if (m->num_states() > sim->num_states())
if (PREF_ == Small && level_ == High && simul_)
{
delete m;
}
else
{
delete sim;
sim = m;
auto m = minimize_monitor(a);
if (m->num_states() < a->num_states())
a = m;
}
if (COMP_ == Complete)
{
auto s = tgba_complete(sim);
delete sim;
sim = s;
}
return sim;
a = tgba_complete(a);
return a;
}
if (PREF_ == Any)
@ -219,8 +186,8 @@ namespace spot
bool dba_is_wdba = false;
bool dba_is_minimal = false;
const tgba_digraph* dba = 0;
const tgba_digraph* sim = 0;
tgba_digraph_ptr dba = 0;
tgba_digraph_ptr sim = 0;
// (Small,Low) is the only configuration where we do not run
// WDBA-minimization.
@ -228,8 +195,8 @@ namespace spot
{
bool reject_bigger = (PREF_ == Small) && (level_ == Medium);
dba = minimize_obligation(a, f, 0, reject_bigger);
if (dba == a || dba == 0) // Minimization failed.
dba = 0;
if (dba == a || !dba) // Minimization failed.
dba = nullptr;
else
dba_is_minimal = dba_is_wdba = true;
// The WDBA is a BA, so no degeneralization is required.
@ -240,18 +207,11 @@ namespace spot
if (!dba || (level_ == High && PREF_ == Small))
{
sim = do_simul(a, simul_);
if (sim != a)
delete a;
// Degeneralize the result of the simulation if needed.
// No need to do that if tba_determinisation_ will be used.
if (type_ == BA && !tba_determinisation_)
sim = do_degen(sim);
}
else
{
delete a;
}
// If WDBA failed, but the simulation returned a deterministic
// automaton, use it as dba.
@ -272,7 +232,7 @@ namespace spot
// If we don't have a DBA, attempt tba-determinization if requested.
if (tba_determinisation_ && !dba)
{
const tgba_digraph* tmpd = 0;
tgba_digraph_ptr tmpd = nullptr;
if (PREF_ == Deterministic
&& f
&& f->is_syntactic_recurrence()
@ -297,20 +257,17 @@ namespace spot
(PREF_ == Small) ? 2 : 8,
1 << ((PREF_ == Small) ? 13 : 15),
f);
if (tmp != 0 && tmp != in)
if (tmp && tmp != in)
{
// There is no point in running the reverse simulation on
// a deterministic automaton, since all prefixes are
// unique.
dba = simulation(tmp);
delete tmp;
}
delete tmpd;
if (dba && PREF_ == Deterministic)
{
// disregard the result of the simulation.
delete sim;
sim = 0;
sim = nullptr;
}
else
{
@ -340,17 +297,16 @@ namespace spot
// sure it is at least 1.
target_acc = original_acc > 0 ? original_acc : 1;
const tgba_digraph* in = 0;
const tgba_digraph* to_free = 0;
const_tgba_digraph_ptr in = 0;
if (target_acc == 1)
{
// If we are seeking a minimal DBA with unknown number of
// states, then we should start from the degeneralized,
// because the input TBA might be smaller.
if (state_based_)
to_free = in = degeneralize(dba);
in = degeneralize(dba);
else if (dba->number_of_acceptance_conditions() != 1)
to_free = in = degeneralize_tba(dba);
in = degeneralize_tba(dba);
else
in = dba;
}
@ -359,32 +315,29 @@ namespace spot
in = dba;
}
const tgba_digraph* cmp = tgba_complete(in);
const tgba_digraph* res = 0;
const_tgba_digraph_ptr res = tgba_complete(in);
if (target_acc == 1)
{
if (sat_states_ != -1)
res = dtba_sat_synthetize(cmp, sat_states_, state_based_);
res = dtba_sat_synthetize(res, sat_states_, state_based_);
else if (sat_minimize_ == 1 || sat_minimize_ == -1)
res = dtba_sat_minimize(cmp, state_based_);
res = dtba_sat_minimize(res, state_based_);
else // sat_minimize_ == 2
res = dtba_sat_minimize_dichotomy(cmp, state_based_);
res = dtba_sat_minimize_dichotomy(res, state_based_);
}
else
{
if (sat_states_ != -1)
res = dtgba_sat_synthetize(cmp, target_acc, sat_states_,
res = dtgba_sat_synthetize(res, target_acc, sat_states_,
state_based_);
else if (sat_minimize_ == 1 || sat_minimize_ == -1)
res = dtgba_sat_minimize(cmp, target_acc, state_based_);
res = dtgba_sat_minimize(res, target_acc, state_based_);
else // sat_minimize_ == 2
res = dtgba_sat_minimize_dichotomy(cmp, target_acc, state_based_);
res = dtgba_sat_minimize_dichotomy(res, target_acc, state_based_);
}
delete cmp;
delete to_free;
if (res != 0)
if (res)
{
delete dba;
if (state_based_)
// FIXME: This does not simplify generalized acceptance
// conditions, but calling scc_filter() would break the
@ -393,7 +346,6 @@ namespace spot
dba = scc_filter_states(res);
else
dba = scc_filter(res, true);
delete res;
dba_is_minimal = true;
}
}
@ -403,24 +355,14 @@ namespace spot
if (dba && !dba_is_wdba && type_ == BA
&& !(dba_is_minimal && state_based_
&& dba->number_of_acceptance_conditions() == 1))
{
auto d = degeneralize(dba);
delete dba;
dba = d;
}
dba = degeneralize(dba);
if (dba && sim)
{
if (dba->num_states() > sim->num_states())
{
delete dba;
dba = 0;
}
dba = nullptr;
else
{
delete sim;
sim = 0;
}
sim = nullptr;
}
@ -428,28 +370,21 @@ namespace spot
{
if (dba && !dba_is_minimal) // WDBA is already clean.
{
auto s = scc_filter(dba, true);
delete dba;
dba = scc_filter(dba, true);
assert(!sim);
dba = s;
}
else if (sim)
{
auto s = scc_filter(sim, true);
delete sim;
sim = scc_filter(sim, true);
assert(!dba);
sim = s;
}
}
sim = dba ? dba : sim;
if (COMP_ == Complete)
{
auto s = tgba_complete(sim);
delete sim;
sim = s;
}
sim = tgba_complete(sim);
return sim;
}
}