Commit 74e20a6e authored by Alexandre Duret-Lutz's avatar Alexandre Duret-Lutz
Browse files

complete: get rid of tgba_explicit_number

* src/tgbaalgos/complete.cc, src/tgbaalgos/complete.hh
(tgba_complete_here): New method for tgba_digraph.
(tgba_complete): Rewrite using dupexp and the above.
parent df051627
...@@ -18,111 +18,96 @@ ...@@ -18,111 +18,96 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "complete.hh" #include "complete.hh"
#include "reachiter.hh"
#include "ltlast/constant.hh" #include "ltlast/constant.hh"
#include "dupexp.hh"
namespace spot namespace spot
{ {
unsigned tgba_complete_here(tgba_digraph* aut)
namespace
{ {
class tgbacomplete_iter: unsigned n = aut->num_states();
public tgba_reachable_iterator_depth_first_stack unsigned sink = -1U;
{ bdd allacc = aut->all_acceptance_conditions();
bdd_dict* dict_; if (allacc == bddfalse)
tgba_explicit_number* out_;
bdd addacc_;
typedef state_explicit_number::transition trans;
public:
tgbacomplete_iter(const tgba* a)
: tgba_reachable_iterator_depth_first_stack(a),
dict_(a->get_dict()),
out_(new tgba_explicit_number(dict_)),
addacc_(bddfalse)
{ {
dict_->register_all_variables_of(a, out_); // We cannot safely complete an automaton if it has no
// acceptance set as the added sink would become accepting.
if (a->number_of_acceptance_conditions() == 0) // In this case, add an acceptance set to all transitions.
{ const ltl::formula* t = ltl::constant::true_instance();
const ltl::formula* t = ltl::constant::true_instance(); int v = aut->get_dict()->register_acceptance_variable(t, aut);
int accvar = allacc = bdd_ithvar(v);
dict_->register_acceptance_variable(t, out_); aut->set_acceptance_conditions(allacc);
addacc_ = bdd_ithvar(accvar); for (auto& t: aut->transitions())
out_->set_acceptance_conditions(addacc_); t.acc = allacc;
}
else
{
out_->set_acceptance_conditions(a->all_acceptance_conditions());
}
} }
else
tgba_explicit_number*
result()
{
return out_;
}
void
end()
{ {
out_->merge_transitions(); // If some acceptance sets were used, loop over the states and
// create a sink state if needed. // seek a state that has only self loops, and that is not
if (out_->has_state(0)) // accepting. This will be our sink state.
for (unsigned i = 0; i < n; ++i)
{ {
trans* t = out_->create_transition(0, 0); bool selfloop = true;
t->condition = bddtrue; bdd accsum = bddfalse;
for (auto& t: aut->out(i))
{
if (t.dst != i) // Not a self-loop
{
selfloop = false;
break;
}
accsum |= t.acc;
}
if (selfloop && accsum != allacc) // We have found a sink!
{
sink = i;
break;
}
} }
} }
// If we haven't found any sink, simply add one.
if (sink == -1U)
{
sink = aut->new_state();
++n;
}
void process_state(const state*, int n, // Now complete all states (including the sink).
tgba_succ_iterator* i) for (unsigned i = 0; i < n; ++i)
{ {
// add a transition to a sink state if the state is not complete. bdd missingcond = bddtrue;
bdd all = bddtrue;
bdd acc = bddfalse; bdd acc = bddfalse;
if (i->first()) for (auto& t: aut->out(i))
{ {
// In case the automaton use state-based acceptance, propagate missingcond -= t.cond;
// the acceptance of the first transition to the one we add. // FIXME: This is ugly.
acc = i->current_acceptance_conditions(); //
// In case the automaton uses state-based acceptance, we
do // need to put the new transition in the same set as all
all -= i->current_condition(); // the other.
while (i->next()); //
} // In case the automaton uses transition-based acceptance,
if (all != bddfalse) // it does not matter what acceptance set we put the new
{ // transition into.
trans* t = out_->create_transition(n, 0); //
t->condition = all; // So in both cases, we put the transition in the same
t->acceptance_conditions = acc | addacc_; // acceptance sets as the last outgoing transition of the
// state.
acc = t.acc;
} }
// In case the automaton use state-based acceptance, propagate
// the acceptance of the first transition to the one we add.
if (missingcond != bddfalse)
aut->new_transition(i, sink, missingcond, acc);
} }
return sink;
}
void tgba_digraph* tgba_complete(const tgba* aut)
process_link(const state*, int in,
const state*, int out,
const tgba_succ_iterator* si)
{
assert(in > 0);
assert(out > 0);
trans* t1 = out_->create_transition(in, out);
t1->condition = si->current_condition();
t1->acceptance_conditions =
si->current_acceptance_conditions() | addacc_;
}
};
} // anonymous
tgba_explicit_number* tgba_complete(const tgba* aut)
{ {
tgbacomplete_iter ci(aut); tgba_digraph* res = tgba_dupexp_dfs(aut);
ci.run(); tgba_complete_here(res);
return ci.result(); return res;
} }
}
}
// -*- coding: utf-8 -*- // -*- coding: utf-8 -*-
// Copyright (C) 2013 Laboratoire de Recherche et Développement // Copyright (C) 2013, 2014 Laboratoire de Recherche et Développement
// de l'Epita. // de l'Epita.
// //
// This file is part of Spot, a model checking library. // This file is part of Spot, a model checking library.
...@@ -20,13 +20,23 @@ ...@@ -20,13 +20,23 @@
#ifndef SPOT_TGBAALGOS_COMPLETE_HH #ifndef SPOT_TGBAALGOS_COMPLETE_HH
# define SPOT_TGBAALGOS_COMPLETE_HH # define SPOT_TGBAALGOS_COMPLETE_HH
#include "tgba/tgbaexplicit.hh" #include "tgba/tgbagraph.hh"
namespace spot namespace spot
{ {
/// Complete a TGBA /// \brief Complete a tgba_digraph in place.
SPOT_API tgba_explicit_number* ///
tgba_complete(const tgba* aut); /// If the tgba has no acceptance set, one will be added. The
/// returned value is the number of the sink state (it can be a new
/// state added for completion, or an existing non-accepting state
/// that has been reused as sink state because it had not outgoing
/// transitions apart from self-loops.)
SPOT_API unsigned tgba_complete_here(tgba_digraph* aut);
/// \brief Clone a tgba and complete it.
///
/// If the tgba has no acceptance set, one will be added.
SPOT_API tgba_digraph* tgba_complete(const tgba* aut);
} }
#endif // SPOT_TGBAALGOS_COMPLETE_HH #endif // SPOT_TGBAALGOS_COMPLETE_HH
Supports Markdown
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