* src/taalgos/tgba2ta.cc: Cosmetics.

This commit is contained in:
Alexandre Duret-Lutz 2013-07-10 08:27:40 +02:00
parent 92a3366488
commit 26f48b1df2

View file

@ -1,5 +1,5 @@
// -*- coding utf-8 -*- // -*- coding utf-8 -*-
// Copyright (C) 2010, 2011, 2012 Laboratoire de Recherche et // Copyright (C) 2010, 2011, 2012, 2013 Laboratoire de Recherche et
// Développement de l'Epita (LRDE). // Développement de l'Epita (LRDE).
// //
// This file is part of Spot, a model checking library. // This file is part of Spot, a model checking library.
@ -49,27 +49,25 @@ namespace spot
namespace namespace
{ {
typedef std::pair<spot::state*, tgba_succ_iterator*> pair_state_iter; typedef std::pair<spot::state*, tgba_succ_iterator*> pair_state_iter;
}
void static void
transform_to_single_pass_automaton(ta_explicit* testing_automata, transform_to_single_pass_automaton
state_ta_explicit* artificial_livelock_accepting_state = 0) (ta_explicit* testing_automata,
state_ta_explicit* artificial_livelock_acc_state = 0)
{ {
if (artificial_livelock_accepting_state != 0) if (artificial_livelock_acc_state != 0)
{ {
state_ta_explicit* artificial_livelock_accepting_state_added = state_ta_explicit* artificial_livelock_acc_state_added =
testing_automata->add_state(artificial_livelock_accepting_state); testing_automata->add_state(artificial_livelock_acc_state);
// unique artificial_livelock_accepting_state // unique artificial_livelock_acc_state
assert(artificial_livelock_accepting_state_added assert(artificial_livelock_acc_state_added
== artificial_livelock_accepting_state); == artificial_livelock_acc_state);
artificial_livelock_accepting_state->set_livelock_accepting_state(true); artificial_livelock_acc_state->set_livelock_accepting_state(true);
artificial_livelock_accepting_state->free_transitions(); artificial_livelock_acc_state->free_transitions();
} }
ta::states_set_t states_set = testing_automata->get_states_set(); ta::states_set_t states_set = testing_automata->get_states_set();
ta::states_set_t::iterator it; ta::states_set_t::iterator it;
@ -78,7 +76,6 @@ namespace spot
for (it = states_set.begin(); it != states_set.end(); ++it) for (it = states_set.begin(); it != states_set.end(); ++it)
{ {
state_ta_explicit* source = static_cast<state_ta_explicit*> (*it); state_ta_explicit* source = static_cast<state_ta_explicit*> (*it);
transitions_to_livelock_states->clear(); transitions_to_livelock_states->clear();
@ -95,27 +92,18 @@ namespace spot
(dest)->get_transitions(); (dest)->get_transitions();
bool dest_trans_empty = dest_trans == 0 || dest_trans->empty(); bool dest_trans_empty = dest_trans == 0 || dest_trans->empty();
//select transitions where a destination is a livelock state //select transitions where a destination is a livelock state
// which isn't a Buchi accepting state and has successors // which isn't a Buchi accepting state and has successors
if (dest->is_livelock_accepting_state() if (dest->is_livelock_accepting_state()
&& (!dest->is_accepting_state()) && (!dest_trans_empty)) && (!dest->is_accepting_state()) && (!dest_trans_empty))
{
transitions_to_livelock_states->push_front(*it_trans); transitions_to_livelock_states->push_front(*it_trans);
} // optimization to have, after minimization, an unique
// livelock state which has no successors
//optimization to have, after
// minimization, an unique livelock state which has no successors
if (dest->is_livelock_accepting_state() && (dest_trans_empty)) if (dest->is_livelock_accepting_state() && (dest_trans_empty))
{
dest->set_accepting_state(false); dest->set_accepting_state(false);
}
++it_trans; ++it_trans;
} }
if (transitions_to_livelock_states != 0) if (transitions_to_livelock_states != 0)
@ -123,33 +111,33 @@ namespace spot
state_ta_explicit::transitions::iterator it_trans; state_ta_explicit::transitions::iterator it_trans;
for (it_trans = transitions_to_livelock_states->begin(); for (it_trans = transitions_to_livelock_states->begin();
it_trans != transitions_to_livelock_states->end(); ++it_trans) it_trans != transitions_to_livelock_states->end();
++it_trans)
{ {
if (artificial_livelock_accepting_state != 0) if (artificial_livelock_acc_state != 0)
{ {
testing_automata->create_transition(source, testing_automata->create_transition
(source,
(*it_trans)->condition, (*it_trans)->condition,
(*it_trans)->acceptance_conditions, (*it_trans)->acceptance_conditions,
artificial_livelock_accepting_state, true); artificial_livelock_acc_state, true);
} }
else else
{ {
testing_automata->create_transition(source, testing_automata->create_transition
(source,
(*it_trans)->condition, (*it_trans)->condition,
(*it_trans)->acceptance_conditions, (*it_trans)->acceptance_conditions,
((*it_trans)->dest)->stuttering_reachable_livelock, ((*it_trans)->dest)->stuttering_reachable_livelock,
true); true);
} }
} }
} }
} }
delete transitions_to_livelock_states; delete transitions_to_livelock_states;
for (it = states_set.begin(); it != states_set.end(); ++it) for (it = states_set.begin(); it != states_set.end(); ++it)
{ {
state_ta_explicit* state = static_cast<state_ta_explicit*> (*it); state_ta_explicit* state = static_cast<state_ta_explicit*> (*it);
state_ta_explicit::transitions* state_trans = state_ta_explicit::transitions* state_trans =
(state)->get_transitions(); (state)->get_transitions();
@ -159,14 +147,14 @@ namespace spot
&& (!state->is_accepting_state()) && (!state_trans_empty)) && (!state->is_accepting_state()) && (!state_trans_empty))
state->set_livelock_accepting_state(false); state->set_livelock_accepting_state(false);
} }
} }
void static void
compute_livelock_acceptance_states(ta_explicit* testing_automata, compute_livelock_acceptance_states(ta_explicit* testing_automata,
bool single_pass_emptiness_check, bool single_pass_emptiness_check,
state_ta_explicit* artificial_livelock_accepting_state) state_ta_explicit*
{ artificial_livelock_acc_state)
{
// We use five main data in this algorithm: // We use five main data in this algorithm:
// * sscc: a stack of strongly stuttering-connected components (SSCC) // * sscc: a stack of strongly stuttering-connected components (SSCC)
scc_stack_ta sscc; scc_stack_ta sscc;
@ -200,7 +188,6 @@ compute_livelock_acceptance_states(ta_explicit* testing_automata,
{ {
state* init_state = (*it); state* init_state = (*it);
init_set.push(init_state); init_set.push(init_state);
} }
while (!init_set.empty()) while (!init_set.empty())
@ -225,12 +212,10 @@ compute_livelock_acceptance_states(ta_explicit* testing_automata,
tgba_succ_iterator* iter = testing_automata->succ_iter(init); tgba_succ_iterator* iter = testing_automata->succ_iter(init);
iter->first(); iter->first();
todo.push(pair_state_iter(init, iter)); todo.push(pair_state_iter(init, iter));
} }
while (!todo.empty()) while (!todo.empty())
{ {
state* curr = todo.top().first; state* curr = todo.top().first;
numbered_state_heap::state_index_p spi = h->find(curr); numbered_state_heap::state_index_p spi = h->find(curr);
@ -267,14 +252,16 @@ compute_livelock_acceptance_states(ta_explicit* testing_automata,
// removing states // removing states
std::list<state*>::iterator i; std::list<state*>::iterator i;
bool is_livelock_accepting_sscc = (sscc.rem().size() > 1) bool is_livelock_accepting_sscc = (sscc.rem().size() > 1)
&& ((sscc.top().is_accepting) || (sscc.top().condition && ((sscc.top().is_accepting)
== testing_automata->all_acceptance_conditions())); || (sscc.top().condition ==
testing_automata->all_acceptance_conditions()));
trace << "*** sscc.size() = ***" trace << "*** sscc.size() = ***"
<< sscc.size() << std::endl; << sscc.size() << std::endl;
for (i = sscc.rem().begin(); i != sscc.rem().end(); ++i) for (i = sscc.rem().begin(); i != sscc.rem().end(); ++i)
{ {
numbered_state_heap::state_index_p spi = h->index((*i)); numbered_state_heap::state_index_p spi =
h->index((*i));
assert(spi.first->compare(*i) == 0); assert(spi.first->compare(*i) == 0);
assert(*spi.second != -1); assert(*spi.second != -1);
*spi.second = -1; *spi.second = -1;
@ -326,7 +313,6 @@ compute_livelock_acceptance_states(ta_explicit* testing_automata,
succ->next(); succ->next();
// We do not need SUCC from now on. // We do not need SUCC from now on.
// Are we going to a new state through a stuttering transition? // Are we going to a new state through a stuttering transition?
bool is_stuttering_transition = bool is_stuttering_transition =
testing_automata->get_state_condition(curr) testing_automata->get_state_condition(curr)
@ -349,8 +335,8 @@ compute_livelock_acceptance_states(ta_explicit* testing_automata,
h->insert(dest_clone, ++num); h->insert(dest_clone, ++num);
sscc.push(num); sscc.push(num);
arc.push(acc_cond); arc.push(acc_cond);
sscc.top().is_accepting = testing_automata->is_accepting_state( sscc.top().is_accepting =
dest); testing_automata->is_accepting_state(dest);
tgba_succ_iterator* iter = testing_automata->succ_iter(dest); tgba_succ_iterator* iter = testing_automata->succ_iter(dest);
iter->first(); iter->first();
@ -362,8 +348,7 @@ compute_livelock_acceptance_states(ta_explicit* testing_automata,
if (*spi.second == -1) if (*spi.second == -1)
continue; continue;
trace trace << "***compute_livelock_acceptance_states: CYCLE***\n";
<< "***compute_livelock_acceptance_states: CYCLE***" << std::endl;
if (!curr->compare(dest)) if (!curr->compare(dest))
{ {
@ -382,13 +367,11 @@ compute_livelock_acceptance_states(ta_explicit* testing_automata,
self_loop_state->stuttering_reachable_livelock self_loop_state->stuttering_reachable_livelock
= self_loop_state; = self_loop_state;
} }
} }
trace trace
<< "***compute_livelock_acceptance_states: CYCLE: self_loop_state***" << "***compute_livelock_acceptance_states: CYCLE: "
<< std::endl; << "self_loop_state***\n";
} }
// Now this is the most interesting case. We have reached a // Now this is the most interesting case. We have reached a
@ -434,16 +417,16 @@ compute_livelock_acceptance_states(ta_explicit* testing_automata,
} }
delete h; delete h;
if ((artificial_livelock_accepting_state != 0) if ((artificial_livelock_acc_state != 0)
|| single_pass_emptiness_check) || single_pass_emptiness_check)
transform_to_single_pass_automaton(testing_automata, transform_to_single_pass_automaton(testing_automata,
artificial_livelock_accepting_state); artificial_livelock_acc_state);
}
}
ta_explicit* ta_explicit*
build_ta(ta_explicit* ta, bdd atomic_propositions_set_, bool degeneralized, build_ta(ta_explicit* ta, bdd atomic_propositions_set_, bool degeneralized,
bool single_pass_emptiness_check, bool artificial_livelock_state_mode) bool single_pass_emptiness_check,
bool artificial_livelock_state_mode)
{ {
std::stack<state_ta_explicit*> todo; std::stack<state_ta_explicit*> todo;
@ -458,21 +441,22 @@ compute_livelock_acceptance_states(ta_explicit* testing_automata,
bdd satone_tgba_condition; bdd satone_tgba_condition;
while ((satone_tgba_condition = bdd_satoneset(tgba_condition, while ((satone_tgba_condition = bdd_satoneset(tgba_condition,
atomic_propositions_set_, bddtrue)) != bddfalse) atomic_propositions_set_,
bddtrue)) != bddfalse)
{ {
tgba_condition -= satone_tgba_condition; tgba_condition -= satone_tgba_condition;
state_ta_explicit* init_state; state_ta_explicit* init_state;
if (degeneralized) if (degeneralized)
{ {
init_state = init_state = new
new state_ta_explicit(tgba_init_state->clone(), state_ta_explicit(tgba_init_state->clone(),
satone_tgba_condition, true, satone_tgba_condition, true,
sba_->state_is_accepting(tgba_init_state)); sba_->state_is_accepting(tgba_init_state));
} }
else else
{ {
init_state = init_state = new
new state_ta_explicit(tgba_init_state->clone(), state_ta_explicit(tgba_init_state->clone(),
satone_tgba_condition, true, false); satone_tgba_condition, true, false);
} }
@ -491,24 +475,28 @@ compute_livelock_acceptance_states(ta_explicit* testing_automata,
tgba_succ_iterator* tgba_succ_it = tgba_succ_iterator* tgba_succ_it =
tgba_->succ_iter(source->get_tgba_state()); tgba_->succ_iter(source->get_tgba_state());
for (tgba_succ_it->first(); !tgba_succ_it->done(); tgba_succ_it->next()) for (tgba_succ_it->first(); !tgba_succ_it->done();
tgba_succ_it->next())
{ {
const state* tgba_state = tgba_succ_it->current_state(); const state* tgba_state = tgba_succ_it->current_state();
bdd tgba_condition = tgba_succ_it->current_condition(); bdd tgba_condition = tgba_succ_it->current_condition();
bdd tgba_acceptance_conditions = bdd tgba_acceptance_conditions =
tgba_succ_it->current_acceptance_conditions(); tgba_succ_it->current_acceptance_conditions();
bdd satone_tgba_condition; bdd satone_tgba_condition;
while ((satone_tgba_condition = bdd_satoneset(tgba_condition, while ((satone_tgba_condition =
atomic_propositions_set_, bddtrue)) != bddfalse) bdd_satoneset(tgba_condition,
atomic_propositions_set_, bddtrue))
!= bddfalse)
{ {
tgba_condition -= satone_tgba_condition; tgba_condition -= satone_tgba_condition;
bdd all_props = bddtrue; bdd all_props = bddtrue;
bdd dest_condition; bdd dest_condition;
if (satone_tgba_condition == source->get_tgba_condition()) if (satone_tgba_condition == source->get_tgba_condition())
while ((dest_condition = bdd_satoneset(all_props, while ((dest_condition =
atomic_propositions_set_, bddtrue)) != bddfalse) bdd_satoneset(all_props,
atomic_propositions_set_, bddtrue))
!= bddfalse)
{ {
all_props -= dest_condition; all_props -= dest_condition;
state_ta_explicit* new_dest; state_ta_explicit* new_dest;
@ -519,12 +507,12 @@ compute_livelock_acceptance_states(ta_explicit* testing_automata,
dest_condition, dest_condition,
false, false,
sba_->state_is_accepting(tgba_state)); sba_->state_is_accepting(tgba_state));
} }
else else
{ {
new_dest = new state_ta_explicit new_dest = new state_ta_explicit
(tgba_state->clone(), dest_condition, false, false); (tgba_state->clone(),
dest_condition, false, false);
} }
state_ta_explicit* dest = ta->add_state(new_dest); state_ta_explicit* dest = ta->add_state(new_dest);
@ -539,41 +527,37 @@ compute_livelock_acceptance_states(ta_explicit* testing_automata,
todo.push(dest); todo.push(dest);
} }
ta->create_transition(source, bdd_setxor( bdd cs = bdd_setxor(source->get_tgba_condition(),
source->get_tgba_condition(), dest->get_tgba_condition());
dest->get_tgba_condition()), ta->create_transition(source, cs,
tgba_acceptance_conditions, dest); tgba_acceptance_conditions, dest);
} }
} }
tgba_state->destroy(); tgba_state->destroy();
} }
delete tgba_succ_it; delete tgba_succ_it;
} }
state_ta_explicit* artificial_livelock_accepting_state = 0; state_ta_explicit* artificial_livelock_acc_state = 0;
trace << "*** build_ta: artificial_livelock_accepting_state_mode = ***" trace << "*** build_ta: artificial_livelock_acc_state_mode = ***"
<< artificial_livelock_state_mode << std::endl; << artificial_livelock_state_mode << std::endl;
if (artificial_livelock_state_mode) if (artificial_livelock_state_mode)
{ {
single_pass_emptiness_check = true; single_pass_emptiness_check = true;
artificial_livelock_accepting_state = new state_ta_explicit( artificial_livelock_acc_state =
ta->get_tgba()->get_init_state(), bddtrue, false, false, true, 0); new state_ta_explicit(ta->get_tgba()->get_init_state(), bddtrue,
false, false, true, 0);
trace trace
<< "*** build_ta: artificial_livelock_accepting_state = ***" << "*** build_ta: artificial_livelock_acc_state = ***"
<< artificial_livelock_accepting_state << std::endl; << artificial_livelock_acc_state << std::endl;
} }
compute_livelock_acceptance_states(ta, single_pass_emptiness_check, compute_livelock_acceptance_states(ta, single_pass_emptiness_check,
artificial_livelock_accepting_state); artificial_livelock_acc_state);
return ta; return ta;
}
} }
ta_explicit* ta_explicit*
@ -616,7 +600,6 @@ compute_livelock_acceptance_states(ta_explicit* testing_automata,
if (state->is_accepting_state()) if (state->is_accepting_state())
{ {
state_ta_explicit::transitions* trans = state->get_transitions(); state_ta_explicit::transitions* trans = state->get_transitions();
state_ta_explicit::transitions::iterator it_trans; state_ta_explicit::transitions::iterator it_trans;
@ -625,23 +608,18 @@ compute_livelock_acceptance_states(ta_explicit* testing_automata,
{ {
(*it_trans)->acceptance_conditions (*it_trans)->acceptance_conditions
= ta->all_acceptance_conditions(); = ta->all_acceptance_conditions();
} }
state->set_accepting_state(false); state->set_accepting_state(false);
} }
} }
return ta; return ta;
} }
tgta_explicit* tgta_explicit*
tgba_to_tgta(const tgba* tgba_, bdd atomic_propositions_set_) tgba_to_tgta(const tgba* tgba_, bdd atomic_propositions_set_)
{ {
state* tgba_init_state = tgba_->get_init_state(); state* tgba_init_state = tgba_->get_init_state();
state_ta_explicit* artificial_init_state = new state_ta_explicit( state_ta_explicit* artificial_init_state = new state_ta_explicit(
tgba_init_state->clone(), bddfalse, true); tgba_init_state->clone(), bddfalse, true);
@ -681,14 +659,12 @@ compute_livelock_acceptance_states(ta_explicit* testing_automata,
state_ta_explicit::transitions* trans = state->get_transitions(); state_ta_explicit::transitions* trans = state->get_transitions();
if (state->is_livelock_accepting_state()) if (state->is_livelock_accepting_state())
{ {
bool trans_empty = (trans == 0 || trans->empty()); bool trans_empty = (trans == 0 || trans->empty());
if (trans_empty || state->is_accepting_state()) if (trans_empty || state->is_accepting_state())
{ {
ta->create_transition(state, bdd_stutering_transition, ta->create_transition(state, bdd_stutering_transition,
ta->all_acceptance_conditions(), state); ta->all_acceptance_conditions(), state);
} }
} }
if (state->compare(ta->get_artificial_initial_state())) if (state->compare(ta->get_artificial_initial_state()))