Commit 10e5c623 authored by Alexandre Duret-Lutz's avatar Alexandre Duret-Lutz
Browse files

Simplify copying of atomic propositions in new tgba_digraph.

* src/tgba/bdddict.cc, src/tgba/bdddict.hh
(register_all_propositions_of): New method.
* src/tgba/tgbagraph.hh (copy_ap_of): New method.
* src/dstarparse/dra2ba.cc, src/dstarparse/nra2nba.cc,
src/dstarparse/nsa2tgba.cc, src/tgbaalgos/degen.cc,
src/tgbaalgos/dtbasat.cc, src/tgbaalgos/dtgbasat.cc,
src/tgbaalgos/dupexp.cc, src/tgbaalgos/emptiness.cc,
src/tgbaalgos/minimize.cc, src/tgbaalgos/powerset.cc,
src/tgbaalgos/sccfilter.cc, src/tgbaalgos/simulation.cc,
src/tgbaalgos/stripacc.cc: Simplify using copy_ap_of.
parent 917f7007
...@@ -235,8 +235,7 @@ namespace spot ...@@ -235,8 +235,7 @@ namespace spot
sm_(sm), sm_(sm),
realizable_(realizable) realizable_(realizable)
{ {
bdd_dict* bd = a->aut->get_dict(); out_->copy_ap_of(a->aut);
bd->register_all_variables_of(a->aut, out_);
out_->set_bprop(tgba_digraph::StateBasedAcc); out_->set_bprop(tgba_digraph::StateBasedAcc);
acc_ = out_->set_single_acceptance_set(); acc_ = out_->set_single_acceptance_set();
out_->new_states(num_states_ * (a->accpair_count + 1)); out_->new_states(num_states_ * (a->accpair_count + 1));
...@@ -292,7 +291,8 @@ namespace spot ...@@ -292,7 +291,8 @@ namespace spot
// accepting cycle. // accepting cycle.
out_->new_transition(in, out + shift, cond); out_->new_transition(in, out + shift, cond);
// Acceptance transitions are those in the Li set. (Löding's Fi set.) // Acceptance transitions are those in the Li
// set. (Löding's Fi set.)
out_->new_acc_transition(in + shift, out + shift, cond, out_->new_acc_transition(in + shift, out + shift, cond,
l.get(i)); l.get(i));
} }
......
...@@ -44,10 +44,7 @@ namespace spot ...@@ -44,10 +44,7 @@ namespace spot
d_(a), d_(a),
num_states_(a->aut->num_states()) num_states_(a->aut->num_states())
{ {
bdd_dict* bd = out_->get_dict(); out_->copy_ap_of(aut);
bd->register_all_variables_of(aut, out_);
// Invent a new acceptance set for the degeneralized automaton.
out_->set_single_acceptance_set(); out_->set_single_acceptance_set();
out_->set_bprop(tgba_digraph::StateBasedAcc); out_->set_bprop(tgba_digraph::StateBasedAcc);
out_->new_states(num_states_ * (d_->accpair_count + 1)); out_->new_states(num_states_ * (d_->accpair_count + 1));
......
...@@ -102,11 +102,9 @@ namespace spot ...@@ -102,11 +102,9 @@ namespace spot
tgba_digraph* nsa_to_tgba(const dstar_aut* nsa) tgba_digraph* nsa_to_tgba(const dstar_aut* nsa)
{ {
assert(nsa->type == Streett); assert(nsa->type == Streett);
tgba_digraph* a = nsa->aut; auto a = nsa->aut;
bdd_dict* dict = a->get_dict(); auto res = new tgba_digraph(a->get_dict());
res->copy_ap_of(a);
tgba_digraph* res = new tgba_digraph(dict);
dict->register_all_variables_of(a, res);
// Create accpair_count acceptance sets for the output. // Create accpair_count acceptance sets for the output.
unsigned npairs = nsa->accpair_count; unsigned npairs = nsa->accpair_count;
......
...@@ -245,18 +245,31 @@ namespace spot ...@@ -245,18 +245,31 @@ namespace spot
bdd_dict::register_all_variables_of(const void* from_other, bdd_dict::register_all_variables_of(const void* from_other,
const void* for_me) const void* for_me)
{ {
bdd_info_map::iterator i; auto j = priv_->free_anonymous_list_of.find(from_other);
for (i = bdd_map.begin(); i != bdd_map.end(); ++i) if (j != priv_->free_anonymous_list_of.end())
priv_->free_anonymous_list_of[for_me] = j->second;
for (auto& i: bdd_map)
{ {
ref_set& s = i->refs; ref_set& s = i.refs;
if (s.find(from_other) != s.end()) if (s.find(from_other) != s.end())
s.insert(for_me); s.insert(for_me);
} }
bdd_dict_priv::free_anonymous_list_of_type::const_iterator j = }
priv_->free_anonymous_list_of.find(from_other);
if (j != priv_->free_anonymous_list_of.end()) void
priv_->free_anonymous_list_of[for_me] = j->second; bdd_dict::register_all_propositions_of(const void* from_other,
const void* for_me)
{
for (auto& i: bdd_map)
{
if (i.type != var_type::var)
continue;
ref_set& s = i.refs;
if (s.find(from_other) != s.end())
s.insert(for_me);
}
} }
void void
......
...@@ -169,12 +169,22 @@ namespace spot ...@@ -169,12 +169,22 @@ namespace spot
/// \brief Duplicate the variable usage of another object. /// \brief Duplicate the variable usage of another object.
/// ///
/// This tells this dictionary that the \a for_me object /// This tells this dictionary that the \a for_me object will be
/// will be using the same BDD variables as the \a from_other objects. /// using the same BDD variables as the \a from_other objects.
/// This ensure that the variables won't be freed when \a from_other /// This ensures that the variables won't be freed when \a
/// is deleted if \a from_other is still alive. /// from_other is deleted if \a from_other is still alive.
void register_all_variables_of(const void* from_other, const void* for_me); void register_all_variables_of(const void* from_other, const void* for_me);
/// \brief Register the same propositions as another object.
///
/// This tells this dictionary that the \a for_me object will be
/// using the same BDD variable used for atomic propositions by
/// the \a from_other object. This ensures that the variables
/// won't be freed when \a from_other is deleted if \a from_other
/// is still alive.
void register_all_propositions_of(const void* from_other,
const void* for_me);
/// \brief Release all variables used by an object. /// \brief Release all variables used by an object.
/// ///
/// Usually called in the destructor if \a me. /// Usually called in the destructor if \a me.
......
...@@ -351,6 +351,11 @@ namespace spot ...@@ -351,6 +351,11 @@ namespace spot
set_acceptance_conditions(a->neg_acceptance_conditions()); set_acceptance_conditions(a->neg_acceptance_conditions());
} }
void copy_ap_of(const tgba* a)
{
dict_->register_all_propositions_of(a, this);
}
virtual bdd all_acceptance_conditions() const virtual bdd all_acceptance_conditions() const
{ {
return all_acceptance_conditions_; return all_acceptance_conditions_;
......
...@@ -260,14 +260,11 @@ namespace spot ...@@ -260,14 +260,11 @@ namespace spot
// The result automaton is an SBA. // The result automaton is an SBA.
auto res = new tgba_digraph(dict); auto res = new tgba_digraph(dict);
res->copy_ap_of(a);
res->set_single_acceptance_set(); res->set_single_acceptance_set();
if (want_sba) if (want_sba)
res->set_bprop(tgba_digraph::StateBasedAcc); res->set_bprop(tgba_digraph::StateBasedAcc);
// We use the same BDD variables as the input, except for the
// acceptance.
dict->register_all_variables_of(a, res);
// Create an order of acceptance conditions. Each entry in this // Create an order of acceptance conditions. Each entry in this
// vector correspond to an acceptance set. Each index can // vector correspond to an acceptance set. Each index can
// be used as a level in degen_state to indicate the next expected // be used as a level in degen_state to indicate the next expected
......
...@@ -671,7 +671,7 @@ namespace spot ...@@ -671,7 +671,7 @@ namespace spot
{ {
auto autdict = aut->get_dict(); auto autdict = aut->get_dict();
auto a = new tgba_digraph(autdict); auto a = new tgba_digraph(autdict);
autdict->register_all_variables_of(aut, a); a->copy_ap_of(aut);
bdd acc = a->set_single_acceptance_set(); bdd acc = a->set_single_acceptance_set();
a->new_states(satdict.cand_size); a->new_states(satdict.cand_size);
......
...@@ -843,8 +843,7 @@ namespace spot ...@@ -843,8 +843,7 @@ namespace spot
{ {
auto autdict = aut->get_dict(); auto autdict = aut->get_dict();
auto a = new tgba_digraph(autdict); auto a = new tgba_digraph(autdict);
autdict->register_all_variables_of(aut, a); a->copy_ap_of(aut);
autdict->unregister_all_typed_variables(bdd_dict::acc, aut);
a->set_acceptance_conditions(satdict.all_cand_acc.back()); a->set_acceptance_conditions(satdict.all_cand_acc.back());
a->new_states(satdict.cand_size); a->new_states(satdict.cand_size);
......
...@@ -38,7 +38,7 @@ namespace spot ...@@ -38,7 +38,7 @@ namespace spot
: T(a), out_(new tgba_digraph(a->get_dict())) : T(a), out_(new tgba_digraph(a->get_dict()))
{ {
out_->copy_acceptance_conditions_of(a); out_->copy_acceptance_conditions_of(a);
a->get_dict()->register_all_variables_of(a, out_); out_->copy_ap_of(a);
} }
tgba_digraph* tgba_digraph*
......
...@@ -287,7 +287,8 @@ namespace spot ...@@ -287,7 +287,8 @@ namespace spot
{ {
auto d = a->get_dict(); auto d = a->get_dict();
auto res = new tgba_digraph(d); auto res = new tgba_digraph(d);
d->register_all_variables_of(a, res); res->copy_ap_of(a);
res->copy_acceptance_conditions_of(a);
const state* s = a->get_init_state(); const state* s = a->get_init_state();
unsigned src; unsigned src;
......
...@@ -119,8 +119,7 @@ namespace spot ...@@ -119,8 +119,7 @@ namespace spot
{ {
auto dict = a->get_dict(); auto dict = a->get_dict();
auto res = new tgba_digraph(dict); auto res = new tgba_digraph(dict);
dict->register_all_variables_of(a, res); res->copy_ap_of(a);
dict->unregister_all_typed_variables(bdd_dict::acc, res);
res->set_bprop(tgba_digraph::StateBasedAcc); res->set_bprop(tgba_digraph::StateBasedAcc);
// For each set, create a state in the resulting automaton. // For each set, create a state in the resulting automaton.
...@@ -139,15 +138,9 @@ namespace spot ...@@ -139,15 +138,9 @@ namespace spot
// For each transition in the initial automaton, add the corresponding // For each transition in the initial automaton, add the corresponding
// transition in res. // transition in res.
bdd allacc = bddfalse;
if (!final->empty()) if (!final->empty())
{ res->set_single_acceptance_set();
int accvar =
dict->register_acceptance_variable(ltl::constant::true_instance(),
res);
allacc = bdd_ithvar(accvar);
res->set_acceptance_conditions(allacc);
}
for (sit = sets.begin(); sit != sets.end(); ++sit) for (sit = sets.begin(); sit != sets.end(); ++sit)
{ {
...@@ -167,11 +160,8 @@ namespace spot ...@@ -167,11 +160,8 @@ namespace spot
dst->destroy(); dst->destroy();
if (i == state_num.end()) // Ignore useless destinations. if (i == state_num.end()) // Ignore useless destinations.
continue; continue;
bdd acc = bddfalse; res->new_acc_transition(src_num, i->second,
if (accepting) succit->current_condition(), accepting);
acc = allacc;
res->new_transition(src_num, i->second,
succit->current_condition(), acc);
} }
} }
res->merge_transitions(); res->merge_transitions();
......
...@@ -51,10 +51,8 @@ namespace spot ...@@ -51,10 +51,8 @@ namespace spot
power_set seen; power_set seen;
todo_list todo; todo_list todo;
auto d = aut->get_dict(); auto res = new tgba_digraph(aut->get_dict());
auto res = new tgba_digraph(d); res->copy_ap_of(aut);
d->register_all_variables_of(aut, res);
d->unregister_all_typed_variables(bdd_dict::acc, res);
{ {
power_state ps; power_state ps;
......
...@@ -434,11 +434,11 @@ namespace spot ...@@ -434,11 +434,11 @@ namespace spot
tgba_digraph* scc_filter_apply(const tgba_digraph* aut, tgba_digraph* scc_filter_apply(const tgba_digraph* aut,
scc_info* given_si, Args&&... args) scc_info* given_si, Args&&... args)
{ {
bdd_dict* bd = aut->get_dict(); tgba_digraph* filtered = new tgba_digraph(aut->get_dict());
tgba_digraph* filtered = new tgba_digraph(bd);
unsigned in_n = aut->num_states(); // Number of input states. unsigned in_n = aut->num_states(); // Number of input states.
if (in_n == 0) // Nothing to filter. if (in_n == 0) // Nothing to filter.
return filtered; return filtered;
filtered->copy_ap_of(aut);
// Compute scc_info if not supplied. // Compute scc_info if not supplied.
scc_info* si = given_si; scc_info* si = given_si;
...@@ -457,7 +457,6 @@ namespace spot ...@@ -457,7 +457,6 @@ namespace spot
else else
inout.push_back(-1U); inout.push_back(-1U);
bd->register_all_variables_of(aut, filtered);
{ {
bdd all = aut->all_acceptance_conditions(); bdd all = aut->all_acceptance_conditions();
bdd neg = aut->neg_acceptance_conditions(); bdd neg = aut->neg_acceptance_conditions();
......
...@@ -230,9 +230,8 @@ namespace spot ...@@ -230,9 +230,8 @@ namespace spot
{ {
if (Cosimulation) if (Cosimulation)
{ {
bdd_dict* bd = a_->get_dict(); a_ = new tgba_digraph(a_->get_dict());
a_ = new tgba_digraph(bd); a_->copy_ap_of(old_a_);
bd->register_all_variables_of(old_a_, a_);
a_->copy_acceptance_conditions_of(old_a_); a_->copy_acceptance_conditions_of(old_a_);
} }
unsigned ns = old_a_->num_states(); unsigned ns = old_a_->num_states();
...@@ -546,9 +545,8 @@ namespace spot ...@@ -546,9 +545,8 @@ namespace spot
acc_compl reverser(all_acceptance_conditions_, acc_compl reverser(all_acceptance_conditions_,
a_->neg_acceptance_conditions()); a_->neg_acceptance_conditions());
bdd_dict* d = a_->get_dict(); tgba_digraph* res = new tgba_digraph(a_->get_dict());
tgba_digraph* res = new tgba_digraph(d); res->copy_ap_of(a_);
d->register_all_variables_of(a_, res);
res->set_acceptance_conditions(all_acceptance_conditions_); res->set_acceptance_conditions(all_acceptance_conditions_);
if (Sba) if (Sba)
res->set_bprop(tgba_digraph::StateBasedAcc); res->set_bprop(tgba_digraph::StateBasedAcc);
......
...@@ -29,6 +29,5 @@ namespace spot ...@@ -29,6 +29,5 @@ namespace spot
for (auto& t: a->out(s)) for (auto& t: a->out(s))
t.acc = bddfalse; t.acc = bddfalse;
a->set_acceptance_conditions(bddfalse); a->set_acceptance_conditions(bddfalse);
a->get_dict()->unregister_all_typed_variables(bdd_dict::acc, a);
} }
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment