Stable version of TGTA approach implementation (automaton + product)
* src/ta/tgta.hh, src/ta/tgta.cc, src/ta/tgtaexplicit.hh, src/ta/tgtaexplicit.hh, src/ta/tgtaproduct.hh, src/ta/tgtaproduct.cc, src/taalgos/minimize.cc, src/taalgos/minimize.hh, src/taalgos/emptinessta.hh, src/taalgos/emptinessta.hh, src/taalgos/emptinessta.cc, src/taalgos/tgba2ta.hh, src/taalgos/tgba2ta.cc: rename tgbta to tgta in this source files. * src/ta/tgbtaexplicit.hh, src/ta/tgbtaproduct.hh, src/ta/tgbta.cc, src/ta/tgbtaproduct.cc, src/ta/tgbta.hh, src/ta/tgbtaexplicit.cc: Rename as... * src/ta/taexplicit.cc, src/ta/taexplicit.hh, src/ta/taproduct.cc, src/ta/taproduct.hh, src/ta/tgtaexplicit.cc: ... these. * src/taalgos/sba2ta.hh, src/taalgos/sba2ta.cc: deleted because the implementation of all the transformations beteween TGBA and the different forms of TA are new implemented in src/taalgos/tgba2ta.hh and src/taalgos/tgba2ta.cc. * src/tgbatest/ltl2tgba.cc: rename the options of commands that build the different forms of TA. * src/ta/ta.hh: BUG Fix * src/ta/Makefile.am, src/tgbatest/ltl2ta.test: impacts of this renaming
This commit is contained in:
parent
c76e651bad
commit
5a706300b0
24 changed files with 1308 additions and 1580 deletions
|
|
@ -39,16 +39,412 @@
|
|||
#include <stack>
|
||||
#include "tgba2ta.hh"
|
||||
#include "taalgos/statessetbuilder.hh"
|
||||
#include "ta/tgbtaexplicit.hh"
|
||||
#include "ta/tgtaexplicit.hh"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace spot
|
||||
{
|
||||
|
||||
namespace
|
||||
{
|
||||
typedef std::pair<spot::state*, tgba_succ_iterator*> pair_state_iter;
|
||||
}
|
||||
|
||||
void
|
||||
transform_to_single_pass_automaton(ta_explicit* testing_automata,
|
||||
state_ta_explicit* artificial_livelock_accepting_state = 0)
|
||||
{
|
||||
|
||||
if (artificial_livelock_accepting_state != 0)
|
||||
{
|
||||
state_ta_explicit* artificial_livelock_accepting_state_added =
|
||||
testing_automata->add_state(artificial_livelock_accepting_state);
|
||||
|
||||
// unique artificial_livelock_accepting_state
|
||||
assert(artificial_livelock_accepting_state_added
|
||||
== artificial_livelock_accepting_state);
|
||||
artificial_livelock_accepting_state->set_livelock_accepting_state(true);
|
||||
artificial_livelock_accepting_state->free_transitions();
|
||||
}
|
||||
|
||||
|
||||
|
||||
ta::states_set_t states_set = testing_automata->get_states_set();
|
||||
ta::states_set_t::iterator it;
|
||||
|
||||
state_ta_explicit::transitions* transitions_to_livelock_states =
|
||||
new state_ta_explicit::transitions;
|
||||
|
||||
for (it = states_set.begin(); it != states_set.end(); it++)
|
||||
{
|
||||
|
||||
state_ta_explicit* source = static_cast<state_ta_explicit*> (*it);
|
||||
|
||||
transitions_to_livelock_states->clear();
|
||||
|
||||
state_ta_explicit::transitions* trans = source->get_transitions();
|
||||
state_ta_explicit::transitions::iterator it_trans;
|
||||
|
||||
if (trans != 0)
|
||||
for (it_trans = trans->begin(); it_trans != trans->end();)
|
||||
{
|
||||
state_ta_explicit* dest = (*it_trans)->dest;
|
||||
|
||||
state_ta_explicit::transitions* dest_trans =
|
||||
(dest)->get_transitions();
|
||||
bool dest_trans_empty = dest_trans == 0 || dest_trans->empty();
|
||||
|
||||
|
||||
|
||||
//select transitions where a destination is a livelock state
|
||||
// which isn't a Buchi accepting state and has successors
|
||||
if (dest->is_livelock_accepting_state()
|
||||
&& (!dest->is_accepting_state()) && (!dest_trans_empty))
|
||||
{
|
||||
transitions_to_livelock_states->push_front(*it_trans);
|
||||
|
||||
}
|
||||
|
||||
//optimization to have, after
|
||||
// minimization, an unique livelock state which has no successors
|
||||
if (dest->is_livelock_accepting_state() && (dest_trans_empty))
|
||||
{
|
||||
dest->set_accepting_state(false);
|
||||
|
||||
}
|
||||
|
||||
it_trans++;
|
||||
|
||||
}
|
||||
|
||||
if (transitions_to_livelock_states != 0)
|
||||
{
|
||||
state_ta_explicit::transitions::iterator it_trans;
|
||||
|
||||
for (it_trans = transitions_to_livelock_states->begin(); it_trans
|
||||
!= transitions_to_livelock_states->end(); it_trans++)
|
||||
{
|
||||
if (artificial_livelock_accepting_state != 0)
|
||||
{
|
||||
testing_automata->create_transition(source,
|
||||
(*it_trans)->condition,
|
||||
(*it_trans)->acceptance_conditions,
|
||||
artificial_livelock_accepting_state, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
testing_automata->create_transition(source,
|
||||
(*it_trans)->condition,
|
||||
(*it_trans)->acceptance_conditions,
|
||||
((*it_trans)->dest)->stuttering_reachable_livelock,
|
||||
true);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
delete transitions_to_livelock_states;
|
||||
|
||||
for (it = states_set.begin(); it != states_set.end(); it++)
|
||||
{
|
||||
|
||||
state_ta_explicit* state = static_cast<state_ta_explicit*> (*it);
|
||||
state_ta_explicit::transitions* state_trans =
|
||||
(state)->get_transitions();
|
||||
bool state_trans_empty = state_trans == 0 || state_trans->empty();
|
||||
|
||||
if (state->is_livelock_accepting_state()
|
||||
&& (!state->is_accepting_state()) && (!state_trans_empty))
|
||||
state->set_livelock_accepting_state(false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
compute_livelock_acceptance_states(ta_explicit* testing_automata,
|
||||
bool single_pass_emptiness_check,
|
||||
state_ta_explicit* artificial_livelock_accepting_state)
|
||||
{
|
||||
// We use five main data in this algorithm:
|
||||
// * sscc: a stack of strongly stuttering-connected components (SSCC)
|
||||
scc_stack_ta sscc;
|
||||
|
||||
// * arc, a stack of acceptance conditions between each of these SCC,
|
||||
std::stack<bdd> arc;
|
||||
|
||||
// * h: a hash of all visited nodes, with their order,
|
||||
// (it is called "Hash" in Couvreur's paper)
|
||||
numbered_state_heap* h =
|
||||
numbered_state_heap_hash_map_factory::instance()->build();
|
||||
///< Heap of visited states.
|
||||
|
||||
// * num: the number of visited nodes. Used to set the order of each
|
||||
// visited node,
|
||||
int num = 0;
|
||||
|
||||
// * todo: the depth-first search stack. This holds pairs of the
|
||||
// form (STATE, ITERATOR) where ITERATOR is a tgba_succ_iterator
|
||||
// over the successors of STATE. In our use, ITERATOR should
|
||||
// always be freed when TODO is popped, but STATE should not because
|
||||
// it is also used as a key in H.
|
||||
std::stack<pair_state_iter> todo;
|
||||
|
||||
// * init: the set of the depth-first search initial states
|
||||
std::stack<state*> init_set;
|
||||
|
||||
ta::states_set_t::const_iterator it;
|
||||
ta::states_set_t init_states = testing_automata->get_initial_states_set();
|
||||
for (it = init_states.begin(); it != init_states.end(); it++)
|
||||
{
|
||||
state* init_state = (*it);
|
||||
init_set.push(init_state);
|
||||
|
||||
}
|
||||
|
||||
while (!init_set.empty())
|
||||
{
|
||||
// Setup depth-first search from initial states.
|
||||
|
||||
{
|
||||
state_ta_explicit* init =
|
||||
down_cast<state_ta_explicit*> (init_set.top());
|
||||
init_set.pop();
|
||||
state_ta_explicit* init_clone = init;
|
||||
numbered_state_heap::state_index_p h_init = h->find(init_clone);
|
||||
|
||||
if (h_init.first)
|
||||
continue;
|
||||
|
||||
h->insert(init_clone, ++num);
|
||||
sscc.push(num);
|
||||
arc.push(bddfalse);
|
||||
sscc.top().is_accepting
|
||||
= testing_automata->is_accepting_state(init);
|
||||
tgba_succ_iterator* iter = testing_automata->succ_iter(init);
|
||||
iter->first();
|
||||
todo.push(pair_state_iter(init, iter));
|
||||
|
||||
}
|
||||
|
||||
while (!todo.empty())
|
||||
{
|
||||
|
||||
state* curr = todo.top().first;
|
||||
|
||||
numbered_state_heap::state_index_p spi = h->find(curr);
|
||||
// If we have reached a dead component, ignore it.
|
||||
if (*spi.second == -1)
|
||||
{
|
||||
todo.pop();
|
||||
continue;
|
||||
}
|
||||
|
||||
// We are looking at the next successor in SUCC.
|
||||
tgba_succ_iterator* succ = todo.top().second;
|
||||
|
||||
// If there is no more successor, backtrack.
|
||||
if (succ->done())
|
||||
{
|
||||
// We have explored all successors of state CURR.
|
||||
|
||||
// Backtrack TODO.
|
||||
todo.pop();
|
||||
|
||||
// fill rem with any component removed,
|
||||
numbered_state_heap::state_index_p spi = h->index(curr);
|
||||
assert(spi.first);
|
||||
|
||||
sscc.rem().push_front(curr);
|
||||
|
||||
// When backtracking the root of an SSCC, we must also
|
||||
// remove that SSCC from the ROOT stacks. We must
|
||||
// discard from H all reachable states from this SSCC.
|
||||
assert(!sscc.empty());
|
||||
if (sscc.top().index == *spi.second)
|
||||
{
|
||||
// removing states
|
||||
std::list<state*>::iterator i;
|
||||
bool is_livelock_accepting_sscc = (sscc.rem().size() > 1)
|
||||
&& ((sscc.top().is_accepting) || (sscc.top().condition
|
||||
== testing_automata->all_acceptance_conditions()));
|
||||
|
||||
trace
|
||||
<< "*** sscc.size() = ***"
|
||||
<< sscc.size() << std::endl;
|
||||
for (i = sscc.rem().begin(); i != sscc.rem().end(); ++i)
|
||||
{
|
||||
numbered_state_heap::state_index_p spi = h->index((*i));
|
||||
assert(spi.first->compare(*i) == 0);
|
||||
assert(*spi.second != -1);
|
||||
*spi.second = -1;
|
||||
|
||||
if (is_livelock_accepting_sscc)
|
||||
{//if it is an accepting sscc add the state to
|
||||
//G (=the livelock-accepting states set)
|
||||
trace << "*** sscc.size() > 1: states: ***"
|
||||
<< testing_automata->format_state(*i)
|
||||
<< std::endl;
|
||||
state_ta_explicit * livelock_accepting_state =
|
||||
down_cast<state_ta_explicit*> (*i);
|
||||
|
||||
livelock_accepting_state->set_livelock_accepting_state(
|
||||
true);
|
||||
|
||||
if (single_pass_emptiness_check)
|
||||
{
|
||||
livelock_accepting_state->set_accepting_state(
|
||||
true);
|
||||
livelock_accepting_state->stuttering_reachable_livelock
|
||||
= livelock_accepting_state;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
assert(!arc.empty());
|
||||
sscc.pop();
|
||||
arc.pop();
|
||||
|
||||
}
|
||||
|
||||
// automata reduction
|
||||
testing_automata->delete_stuttering_and_hole_successors(curr);
|
||||
|
||||
delete succ;
|
||||
// Do not delete CURR: it is a key in H.
|
||||
continue;
|
||||
}
|
||||
|
||||
// Fetch the values destination state we are interested in...
|
||||
state* dest = succ->current_state();
|
||||
|
||||
bdd acc_cond = succ->current_acceptance_conditions();
|
||||
// ... and point the iterator to the next successor, for
|
||||
// the next iteration.
|
||||
succ->next();
|
||||
// We do not need SUCC from now on.
|
||||
|
||||
|
||||
// Are we going to a new state through a stuttering transition?
|
||||
bool is_stuttering_transition =
|
||||
testing_automata->get_state_condition(curr)
|
||||
== testing_automata->get_state_condition(dest);
|
||||
state* dest_clone = dest;
|
||||
spi = h->find(dest_clone);
|
||||
|
||||
// Is this a new state?
|
||||
if (!spi.first)
|
||||
{
|
||||
if (!is_stuttering_transition)
|
||||
{
|
||||
init_set.push(dest);
|
||||
dest_clone->destroy();
|
||||
continue;
|
||||
}
|
||||
|
||||
// Number it, stack it, and register its successors
|
||||
// for later processing.
|
||||
h->insert(dest_clone, ++num);
|
||||
sscc.push(num);
|
||||
arc.push(acc_cond);
|
||||
sscc.top().is_accepting = testing_automata->is_accepting_state(
|
||||
dest);
|
||||
|
||||
tgba_succ_iterator* iter = testing_automata->succ_iter(dest);
|
||||
iter->first();
|
||||
todo.push(pair_state_iter(dest, iter));
|
||||
continue;
|
||||
}
|
||||
|
||||
// If we have reached a dead component, ignore it.
|
||||
if (*spi.second == -1)
|
||||
continue;
|
||||
|
||||
trace
|
||||
<< "***compute_livelock_acceptance_states: CYCLE***" << std::endl;
|
||||
|
||||
if (!curr->compare(dest))
|
||||
{
|
||||
state_ta_explicit * self_loop_state =
|
||||
down_cast<state_ta_explicit*> (curr);
|
||||
assert(self_loop_state);
|
||||
|
||||
if (testing_automata->is_accepting_state(self_loop_state)
|
||||
|| (acc_cond
|
||||
== testing_automata->all_acceptance_conditions()))
|
||||
{
|
||||
self_loop_state->set_livelock_accepting_state(true);
|
||||
if (single_pass_emptiness_check)
|
||||
{
|
||||
self_loop_state->set_accepting_state(true);
|
||||
self_loop_state->stuttering_reachable_livelock
|
||||
= self_loop_state;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
trace
|
||||
<< "***compute_livelock_acceptance_states: CYCLE: self_loop_state***"
|
||||
<< std::endl;
|
||||
|
||||
}
|
||||
|
||||
// Now this is the most interesting case. We have reached a
|
||||
// state S1 which is already part of a non-dead SSCC. Any such
|
||||
// non-dead SSCC has necessarily been crossed by our path to
|
||||
// this state: there is a state S2 in our path which belongs
|
||||
// to this SSCC too. We are going to merge all states between
|
||||
// this S1 and S2 into this SSCC.
|
||||
//
|
||||
// This merge is easy to do because the order of the SSCC in
|
||||
// ROOT is ascending: we just have to merge all SSCCs from the
|
||||
// top of ROOT that have an index greater to the one of
|
||||
// the SSCC of S2 (called the "threshold").
|
||||
int threshold = *spi.second;
|
||||
std::list<state*> rem;
|
||||
bool acc = false;
|
||||
|
||||
while (threshold < sscc.top().index)
|
||||
{
|
||||
assert(!sscc.empty());
|
||||
assert(!arc.empty());
|
||||
acc |= sscc.top().is_accepting;
|
||||
acc_cond |= sscc.top().condition;
|
||||
acc_cond |= arc.top();
|
||||
rem.splice(rem.end(), sscc.rem());
|
||||
sscc.pop();
|
||||
arc.pop();
|
||||
}
|
||||
|
||||
// Note that we do not always have
|
||||
// threshold == sscc.top().index
|
||||
// after this loop, the SSCC whose index is threshold might have
|
||||
// been merged with a lower SSCC.
|
||||
|
||||
// Accumulate all acceptance conditions into the merged SSCC.
|
||||
sscc.top().is_accepting |= acc;
|
||||
sscc.top().condition |= acc_cond;
|
||||
|
||||
sscc.rem().splice(sscc.rem().end(), rem);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
delete h;
|
||||
|
||||
if ((artificial_livelock_accepting_state != 0)
|
||||
|| single_pass_emptiness_check)
|
||||
transform_to_single_pass_automaton(testing_automata,
|
||||
artificial_livelock_accepting_state);
|
||||
|
||||
}
|
||||
|
||||
ta_explicit*
|
||||
build_ta(ta_explicit* ta, bdd atomic_propositions_set_,
|
||||
bool artificial_livelock_accepting_state_mode, bool degeneralized)
|
||||
build_ta(ta_explicit* ta, bdd atomic_propositions_set_, bool degeneralized,
|
||||
bool single_pass_emptiness_check, bool artificial_livelock_state_mode)
|
||||
{
|
||||
|
||||
std::stack<state_ta_explicit*> todo;
|
||||
|
|
@ -115,17 +511,17 @@ namespace spot
|
|||
all_props -= dest_condition;
|
||||
state_ta_explicit* new_dest;
|
||||
if (degeneralized)
|
||||
{
|
||||
{
|
||||
|
||||
new_dest
|
||||
= new state_ta_explicit(
|
||||
tgba_state->clone(),
|
||||
dest_condition,
|
||||
false,
|
||||
new_dest
|
||||
= new state_ta_explicit(
|
||||
tgba_state->clone(),
|
||||
dest_condition,
|
||||
false,
|
||||
((const tgba_sba_proxy*) tgba_)->state_is_accepting(
|
||||
tgba_state));
|
||||
tgba_state));
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
new_dest = new state_ta_explicit(tgba_state->clone(),
|
||||
|
|
@ -136,7 +532,7 @@ namespace spot
|
|||
|
||||
if (dest != new_dest)
|
||||
{
|
||||
// the state dest already exists in the testing automata
|
||||
// the state dest already exists in the automaton
|
||||
new_dest->get_tgba_state()->destroy();
|
||||
delete new_dest;
|
||||
}
|
||||
|
|
@ -163,11 +559,11 @@ namespace spot
|
|||
|
||||
trace
|
||||
<< "*** build_ta: artificial_livelock_accepting_state_mode = ***"
|
||||
<< artificial_livelock_accepting_state_mode << std::endl;
|
||||
<< artificial_livelock_state_mode << std::endl;
|
||||
|
||||
if (artificial_livelock_accepting_state_mode)
|
||||
if (artificial_livelock_state_mode)
|
||||
{
|
||||
|
||||
single_pass_emptiness_check = true;
|
||||
artificial_livelock_accepting_state = new state_ta_explicit(
|
||||
ta->get_tgba()->get_init_state(), bddtrue, false, false, true, 0);
|
||||
trace
|
||||
|
|
@ -176,7 +572,8 @@ namespace spot
|
|||
|
||||
}
|
||||
|
||||
compute_livelock_acceptance_states(ta, artificial_livelock_accepting_state);
|
||||
compute_livelock_acceptance_states(ta, single_pass_emptiness_check,
|
||||
artificial_livelock_accepting_state);
|
||||
|
||||
return ta;
|
||||
|
||||
|
|
@ -184,19 +581,19 @@ namespace spot
|
|||
|
||||
ta_explicit*
|
||||
tgba_to_ta(const tgba* tgba_, bdd atomic_propositions_set_,
|
||||
bool artificial_initial_state_mode,
|
||||
bool artificial_livelock_accepting_state_mode, bool degeneralized)
|
||||
bool degeneralized, bool artificial_initial_state_mode,
|
||||
bool single_pass_emptiness_check, bool artificial_livelock_state_mode)
|
||||
{
|
||||
ta_explicit* ta;
|
||||
|
||||
state* tgba_init_state = tgba_->get_init_state();
|
||||
if (artificial_initial_state_mode)
|
||||
{
|
||||
state_ta_explicit* ta_init_state = new state_ta_explicit(
|
||||
state_ta_explicit* artificial_init_state = new state_ta_explicit(
|
||||
tgba_init_state->clone(), bddfalse, true);
|
||||
|
||||
ta = new spot::ta_explicit(tgba_, tgba_->all_acceptance_conditions(),
|
||||
ta_init_state);
|
||||
artificial_init_state);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -205,413 +602,38 @@ namespace spot
|
|||
tgba_init_state->destroy();
|
||||
|
||||
// build ta automata:
|
||||
build_ta(ta, atomic_propositions_set_,
|
||||
artificial_livelock_accepting_state_mode, degeneralized);
|
||||
build_ta(ta, atomic_propositions_set_, degeneralized,
|
||||
single_pass_emptiness_check, artificial_livelock_state_mode);
|
||||
return ta;
|
||||
}
|
||||
|
||||
void
|
||||
add_artificial_livelock_accepting_state(ta_explicit* testing_automata,
|
||||
state_ta_explicit* artificial_livelock_accepting_state)
|
||||
{
|
||||
|
||||
state_ta_explicit* artificial_livelock_accepting_state_added =
|
||||
testing_automata->add_state(artificial_livelock_accepting_state);
|
||||
|
||||
// unique artificial_livelock_accepting_state
|
||||
assert(artificial_livelock_accepting_state_added
|
||||
== artificial_livelock_accepting_state);
|
||||
|
||||
trace
|
||||
<< "*** add_artificial_livelock_accepting_state: "
|
||||
<< "assert(artificial_livelock_accepting_state_added == "
|
||||
<< "artificial_livelock_accepting_state) = ***"
|
||||
<< (artificial_livelock_accepting_state_added
|
||||
== artificial_livelock_accepting_state) << std::endl;
|
||||
|
||||
ta::states_set_t states_set = testing_automata->get_states_set();
|
||||
ta::states_set_t::iterator it;
|
||||
|
||||
std::set<bdd, bdd_less_than>* conditions_to_livelock_accepting_states =
|
||||
new std::set<bdd, bdd_less_than>;
|
||||
|
||||
for (it = states_set.begin(); it != states_set.end(); it++)
|
||||
{
|
||||
|
||||
state_ta_explicit* source = static_cast<state_ta_explicit*> (*it);
|
||||
|
||||
conditions_to_livelock_accepting_states->clear();
|
||||
|
||||
state_ta_explicit::transitions* trans = source->get_transitions();
|
||||
state_ta_explicit::transitions::iterator it_trans;
|
||||
|
||||
if (trans != 0)
|
||||
for (it_trans = trans->begin(); it_trans != trans->end();)
|
||||
{
|
||||
state_ta_explicit* dest = (*it_trans)->dest;
|
||||
|
||||
state_ta_explicit::transitions* dest_trans =
|
||||
(dest)->get_transitions();
|
||||
bool dest_trans_empty = dest_trans == 0 || dest_trans->empty();
|
||||
|
||||
//TA++
|
||||
if (dest->is_livelock_accepting_state()
|
||||
&& (!dest->is_accepting_state() || dest_trans_empty))
|
||||
{
|
||||
conditions_to_livelock_accepting_states->insert(
|
||||
(*it_trans)->condition);
|
||||
|
||||
}
|
||||
|
||||
//remove hole successors states
|
||||
if (dest_trans_empty)
|
||||
{
|
||||
source->get_transitions((*it_trans)->condition)->remove(
|
||||
*it_trans);
|
||||
delete (*it_trans);
|
||||
it_trans = trans->erase(it_trans);
|
||||
}
|
||||
else
|
||||
{
|
||||
it_trans++;
|
||||
}
|
||||
}
|
||||
|
||||
if (conditions_to_livelock_accepting_states != 0)
|
||||
{
|
||||
std::set<bdd, bdd_less_than>::iterator it_conditions;
|
||||
for (it_conditions
|
||||
= conditions_to_livelock_accepting_states->begin(); it_conditions
|
||||
!= conditions_to_livelock_accepting_states->end(); it_conditions++)
|
||||
{
|
||||
|
||||
testing_automata->create_transition(source, (*it_conditions),
|
||||
bddfalse, artificial_livelock_accepting_state, true);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
delete conditions_to_livelock_accepting_states;
|
||||
|
||||
for (it = states_set.begin(); it != states_set.end(); it++)
|
||||
{
|
||||
|
||||
state_ta_explicit* state = static_cast<state_ta_explicit*> (*it);
|
||||
state_ta_explicit::transitions* state_trans =
|
||||
(state)->get_transitions();
|
||||
bool state_trans_empty = state_trans == 0 || state_trans->empty();
|
||||
|
||||
if (state->is_livelock_accepting_state()
|
||||
&& (!state->is_accepting_state()) && (!state_trans_empty))
|
||||
state->set_livelock_accepting_state(false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
typedef std::pair<spot::state*, tgba_succ_iterator*> pair_state_iter;
|
||||
}
|
||||
|
||||
void
|
||||
compute_livelock_acceptance_states(ta_explicit* testing_automata,
|
||||
state_ta_explicit* artificial_livelock_accepting_state)
|
||||
{
|
||||
// We use five main data in this algorithm:
|
||||
// * sscc: a stack of strongly stuttering-connected components (SSCC)
|
||||
scc_stack_ta sscc;
|
||||
|
||||
// * arc, a stack of acceptance conditions between each of these SCC,
|
||||
std::stack<bdd> arc;
|
||||
|
||||
// * h: a hash of all visited nodes, with their order,
|
||||
// (it is called "Hash" in Couvreur's paper)
|
||||
numbered_state_heap* h =
|
||||
numbered_state_heap_hash_map_factory::instance()->build();
|
||||
///< Heap of visited states.
|
||||
|
||||
// * num: the number of visited nodes. Used to set the order of each
|
||||
// visited node,
|
||||
int num = 0;
|
||||
|
||||
// * todo: the depth-first search stack. This holds pairs of the
|
||||
// form (STATE, ITERATOR) where ITERATOR is a tgba_succ_iterator
|
||||
// over the successors of STATE. In our use, ITERATOR should
|
||||
// always be freed when TODO is popped, but STATE should not because
|
||||
// it is also used as a key in H.
|
||||
std::stack<pair_state_iter> todo;
|
||||
|
||||
// * init: the set of the depth-first search initial states
|
||||
std::stack<state*> init_set;
|
||||
|
||||
ta::states_set_t::const_iterator it;
|
||||
ta::states_set_t init_states = testing_automata->get_initial_states_set();
|
||||
for (it = init_states.begin(); it != init_states.end(); it++)
|
||||
{
|
||||
state* init_state = (*it);
|
||||
init_set.push(init_state);
|
||||
|
||||
}
|
||||
|
||||
while (!init_set.empty())
|
||||
{
|
||||
// Setup depth-first search from initial states.
|
||||
|
||||
{
|
||||
state_ta_explicit* init =
|
||||
down_cast<state_ta_explicit*> (init_set.top());
|
||||
init_set.pop();
|
||||
state_ta_explicit* init_clone = init;
|
||||
numbered_state_heap::state_index_p h_init = h->find(init_clone);
|
||||
|
||||
if (h_init.first)
|
||||
continue;
|
||||
|
||||
h->insert(init_clone, ++num);
|
||||
sscc.push(num);
|
||||
arc.push(bddfalse);
|
||||
sscc.top().is_accepting
|
||||
= testing_automata->is_accepting_state(init);
|
||||
tgba_succ_iterator* iter = testing_automata->succ_iter(init);
|
||||
iter->first();
|
||||
todo.push(pair_state_iter(init, iter));
|
||||
|
||||
}
|
||||
|
||||
while (!todo.empty())
|
||||
{
|
||||
|
||||
state* curr = todo.top().first;
|
||||
|
||||
numbered_state_heap::state_index_p spi = h->find(curr);
|
||||
// If we have reached a dead component, ignore it.
|
||||
if (*spi.second == -1)
|
||||
{
|
||||
todo.pop();
|
||||
continue;
|
||||
}
|
||||
|
||||
// We are looking at the next successor in SUCC.
|
||||
tgba_succ_iterator* succ = todo.top().second;
|
||||
|
||||
// If there is no more successor, backtrack.
|
||||
if (succ->done())
|
||||
{
|
||||
// We have explored all successors of state CURR.
|
||||
|
||||
// Backtrack TODO.
|
||||
todo.pop();
|
||||
|
||||
// fill rem with any component removed,
|
||||
numbered_state_heap::state_index_p spi = h->index(curr);
|
||||
assert(spi.first);
|
||||
|
||||
sscc.rem().push_front(curr);
|
||||
|
||||
// When backtracking the root of an SSCC, we must also
|
||||
// remove that SSCC from the ROOT stacks. We must
|
||||
// discard from H all reachable states from this SSCC.
|
||||
assert(!sscc.empty());
|
||||
if (sscc.top().index == *spi.second)
|
||||
{
|
||||
// removing states
|
||||
std::list<state*>::iterator i;
|
||||
bool is_livelock_accepting_sscc = (sscc.rem().size() > 1)
|
||||
&& ((sscc.top().is_accepting) || (sscc.top().condition
|
||||
== testing_automata->all_acceptance_conditions()));
|
||||
|
||||
for (i = sscc.rem().begin(); i != sscc.rem().end(); ++i)
|
||||
{
|
||||
numbered_state_heap::state_index_p spi = h->index((*i));
|
||||
assert(spi.first->compare(*i) == 0);
|
||||
assert(*spi.second != -1);
|
||||
*spi.second = -1;
|
||||
if (is_livelock_accepting_sscc)
|
||||
{//if it is an accepting sscc add the state to
|
||||
//G (=the livelock-accepting states set)
|
||||
|
||||
state_ta_explicit * livelock_accepting_state =
|
||||
down_cast<state_ta_explicit*> (*i);
|
||||
|
||||
livelock_accepting_state->set_livelock_accepting_state(
|
||||
true);
|
||||
|
||||
//case STA (Single-pass Testing Automata) or case
|
||||
//STGTA (Single-pass Transition-based Generalised Testing Automata)
|
||||
if (artificial_livelock_accepting_state != 0)
|
||||
livelock_accepting_state->set_accepting_state(
|
||||
true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
assert(!arc.empty());
|
||||
sscc.pop();
|
||||
arc.pop();
|
||||
|
||||
}
|
||||
|
||||
// automata reduction
|
||||
testing_automata->delete_stuttering_and_hole_successors(curr);
|
||||
|
||||
delete succ;
|
||||
// Do not delete CURR: it is a key in H.
|
||||
continue;
|
||||
}
|
||||
|
||||
// Fetch the values destination state we are interested in...
|
||||
state* dest = succ->current_state();
|
||||
|
||||
bdd acc_cond = succ->current_acceptance_conditions();
|
||||
// ... and point the iterator to the next successor, for
|
||||
// the next iteration.
|
||||
succ->next();
|
||||
// We do not need SUCC from now on.
|
||||
|
||||
|
||||
// Are we going to a new state through a stuttering transition?
|
||||
bool is_stuttering_transition =
|
||||
testing_automata->get_state_condition(curr)
|
||||
== testing_automata->get_state_condition(dest);
|
||||
state* dest_clone = dest;
|
||||
spi = h->find(dest_clone);
|
||||
|
||||
// Is this a new state?
|
||||
if (!spi.first)
|
||||
{
|
||||
if (!is_stuttering_transition)
|
||||
{
|
||||
init_set.push(dest);
|
||||
dest_clone->destroy();
|
||||
continue;
|
||||
}
|
||||
|
||||
// Number it, stack it, and register its successors
|
||||
// for later processing.
|
||||
h->insert(dest_clone, ++num);
|
||||
sscc.push(num);
|
||||
arc.push(acc_cond);
|
||||
sscc.top().is_accepting = testing_automata->is_accepting_state(
|
||||
dest);
|
||||
|
||||
tgba_succ_iterator* iter = testing_automata->succ_iter(dest);
|
||||
iter->first();
|
||||
todo.push(pair_state_iter(dest, iter));
|
||||
continue;
|
||||
}
|
||||
|
||||
// If we have reached a dead component, ignore it.
|
||||
if (*spi.second == -1)
|
||||
continue;
|
||||
|
||||
trace
|
||||
<< "***compute_livelock_acceptance_states: CYCLE***" << std::endl;
|
||||
|
||||
if (!curr->compare(dest))
|
||||
{
|
||||
state_ta_explicit * self_loop_state =
|
||||
down_cast<state_ta_explicit*> (curr);
|
||||
assert(self_loop_state);
|
||||
|
||||
if (testing_automata->is_accepting_state(self_loop_state)
|
||||
|| (acc_cond
|
||||
== testing_automata->all_acceptance_conditions()))
|
||||
{
|
||||
self_loop_state->set_livelock_accepting_state(true);
|
||||
if (artificial_livelock_accepting_state != 0)
|
||||
self_loop_state->set_accepting_state(true);
|
||||
|
||||
}
|
||||
|
||||
trace
|
||||
<< "***compute_livelock_acceptance_states: CYCLE: self_loop_state***"
|
||||
<< std::endl;
|
||||
|
||||
}
|
||||
|
||||
// Now this is the most interesting case. We have reached a
|
||||
// state S1 which is already part of a non-dead SSCC. Any such
|
||||
// non-dead SSCC has necessarily been crossed by our path to
|
||||
// this state: there is a state S2 in our path which belongs
|
||||
// to this SSCC too. We are going to merge all states between
|
||||
// this S1 and S2 into this SSCC.
|
||||
//
|
||||
// This merge is easy to do because the order of the SSCC in
|
||||
// ROOT is ascending: we just have to merge all SSCCs from the
|
||||
// top of ROOT that have an index greater to the one of
|
||||
// the SSCC of S2 (called the "threshold").
|
||||
int threshold = *spi.second;
|
||||
std::list<state*> rem;
|
||||
bool acc = false;
|
||||
|
||||
while (threshold < sscc.top().index)
|
||||
{
|
||||
assert(!sscc.empty());
|
||||
assert(!arc.empty());
|
||||
acc |= sscc.top().is_accepting;
|
||||
acc_cond |= sscc.top().condition;
|
||||
acc_cond |= arc.top();
|
||||
rem.splice(rem.end(), sscc.rem());
|
||||
sscc.pop();
|
||||
arc.pop();
|
||||
}
|
||||
|
||||
// Note that we do not always have
|
||||
// threshold == sscc.top().index
|
||||
// after this loop, the SSCC whose index is threshold might have
|
||||
// been merged with a lower SSCC.
|
||||
|
||||
// Accumulate all acceptance conditions into the merged SSCC.
|
||||
sscc.top().is_accepting |= acc;
|
||||
sscc.top().condition |= acc_cond;
|
||||
|
||||
sscc.rem().splice(sscc.rem().end(), rem);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
delete h;
|
||||
|
||||
trace
|
||||
<< "*** compute_livelock_acceptance_states: PRE call add_artificial_livelock_accepting_state() method ... (artificial_livelock_accepting_state != 0) :***"
|
||||
<< (artificial_livelock_accepting_state != 0) << std::endl;
|
||||
|
||||
if (artificial_livelock_accepting_state != 0)
|
||||
add_artificial_livelock_accepting_state(testing_automata,
|
||||
artificial_livelock_accepting_state);
|
||||
|
||||
trace
|
||||
<< "*** compute_livelock_acceptance_states: POST call add_artificial_livelock_accepting_state() method ***"
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
tgbta_explicit*
|
||||
tgba_to_tgbta(const tgba* tgba_, bdd atomic_propositions_set_)
|
||||
tgta_explicit*
|
||||
tgba_to_tgta(const tgba* tgba_, bdd atomic_propositions_set_)
|
||||
{
|
||||
|
||||
state* tgba_init_state = tgba_->get_init_state();
|
||||
state_ta_explicit* ta_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->destroy();
|
||||
|
||||
tgbta_explicit* tgbta = new spot::tgbta_explicit(tgba_,
|
||||
tgba_->all_acceptance_conditions(), ta_init_state);
|
||||
tgta_explicit* tgta = new spot::tgta_explicit(tgba_,
|
||||
tgba_->all_acceptance_conditions(), artificial_init_state);
|
||||
|
||||
// build ta automata:
|
||||
build_ta(tgbta, atomic_propositions_set_, true, false);
|
||||
// build a Generalized TA automaton involving a single_pass_emptiness_check
|
||||
// (without an artificial livelock state):
|
||||
build_ta(tgta, atomic_propositions_set_, false, true, false);
|
||||
|
||||
trace
|
||||
<< "***tgba_to_tgbta: POST build_ta***" << std::endl;
|
||||
|
||||
// adapt a ta automata to build tgbta automata :
|
||||
ta::states_set_t states_set = tgbta->get_states_set();
|
||||
// adapt a ta automata to build tgta automata :
|
||||
ta::states_set_t states_set = tgta->get_states_set();
|
||||
ta::states_set_t::iterator it;
|
||||
tgba_succ_iterator* initial_states_iter = tgbta->succ_iter(
|
||||
tgbta->get_artificial_initial_state());
|
||||
tgba_succ_iterator* initial_states_iter = tgta->succ_iter(
|
||||
tgta->get_artificial_initial_state());
|
||||
initial_states_iter->first();
|
||||
if (initial_states_iter->done())
|
||||
return tgbta;
|
||||
return tgta;
|
||||
bdd first_state_condition = (initial_states_iter)->current_condition();
|
||||
delete initial_states_iter;
|
||||
|
||||
|
|
@ -630,21 +652,14 @@ namespace spot
|
|||
bool trans_empty = (trans == 0 || trans->empty());
|
||||
if (trans_empty || state->is_accepting_state())
|
||||
{
|
||||
trace
|
||||
<< "***tgba_to_tgbta: PRE if (state->is_livelock_accepting_state()) ... create_transition ***"
|
||||
<< std::endl;
|
||||
tgbta->create_transition(state, bdd_stutering_transition,
|
||||
tgbta->all_acceptance_conditions(), state);
|
||||
trace
|
||||
<< "***tgba_to_tgbta: POST if (state->is_livelock_accepting_state()) ... create_transition ***"
|
||||
<< std::endl;
|
||||
|
||||
tgta->create_transition(state, bdd_stutering_transition,
|
||||
tgta->all_acceptance_conditions(), state);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (state->compare(tgbta->get_artificial_initial_state()))
|
||||
tgbta->create_transition(state, bdd_stutering_transition, bddfalse,
|
||||
if (state->compare(tgta->get_artificial_initial_state()))
|
||||
tgta->create_transition(state, bdd_stutering_transition, bddfalse,
|
||||
state);
|
||||
|
||||
state->set_livelock_accepting_state(false);
|
||||
|
|
@ -654,7 +669,7 @@ namespace spot
|
|||
|
||||
}
|
||||
|
||||
return tgbta;
|
||||
return tgta;
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue