Add a new form of TA with a Single-pass emptiness check (STA)
* src/ta/ta.cc, src/ta/ta.hh, src/ta/taexplicit.cc, src/ta/taexplicit.hh, src/ta/taproduct.cc,src/ta/taproduct.hh, src/taalgos/dotty.cc, src/taalgos/emptinessta.cc, src/taalgos/emptinessta.hh, src/taalgos/minimize.cc, src/taalgos/reachiter.cc, src/taalgos/sba2ta.cc, src/taalgos/sba2ta.hh, src/tgbatest/ltl2ta.test, src/tgbatest/ltl2tgba.cc: Impacts of the implementation of a new variant of TA, called STA, which involve a Single-pass emptiness check. The new options (-in and -lv) added to build the new variants of TA allow to add two artificial states: 1- an initial artificial state to have an unique initial state (-in) 2- a livelock artificial state which has no successors in order to obtain the new form of TA which requires only a Single-pass emptiness- check: STA (-lv).
This commit is contained in:
parent
310973f88c
commit
782ba0010b
15 changed files with 1224 additions and 711 deletions
|
|
@ -43,10 +43,24 @@ namespace spot
|
|||
os_ << "digraph G {" << std::endl;
|
||||
|
||||
int n = 0;
|
||||
const ta::states_set_t init_states_set =
|
||||
t_automata_->get_initial_states_set();
|
||||
|
||||
spot::state* artificial_initial_state =
|
||||
t_automata_->get_artificial_initial_state();
|
||||
|
||||
ta::states_set_t init_states_set;
|
||||
|
||||
ta::states_set_t::const_iterator it;
|
||||
|
||||
if (artificial_initial_state != 0)
|
||||
{
|
||||
init_states_set.insert(artificial_initial_state);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
init_states_set = t_automata_->get_initial_states_set();
|
||||
}
|
||||
|
||||
for (it = (init_states_set.begin()); it != init_states_set.end(); it++)
|
||||
{
|
||||
// cout << (*it).first << " => " << (*it).second << endl;
|
||||
|
|
@ -60,6 +74,7 @@ namespace spot
|
|||
+ "\"]" << std::endl;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
// Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
||||
// 02111-1307, USA.
|
||||
|
||||
// #define TRACE
|
||||
//#define TRACE
|
||||
|
||||
#include <iostream>
|
||||
#ifdef TRACE
|
||||
|
|
@ -34,7 +34,7 @@
|
|||
namespace spot
|
||||
{
|
||||
|
||||
ta_check::ta_check(const ta* a, option_map o) :
|
||||
ta_check::ta_check(const ta_product* a, option_map o) :
|
||||
a_(a), o_(o)
|
||||
{
|
||||
is_full_2_pass_ = o.get("is_full_2_pass", 0);
|
||||
|
|
@ -46,7 +46,7 @@ namespace spot
|
|||
}
|
||||
|
||||
bool
|
||||
ta_check::check()
|
||||
ta_check::check(bool disable_second_pass)
|
||||
{
|
||||
|
||||
// We use five main data in this algorithm:
|
||||
|
|
@ -54,7 +54,7 @@ namespace spot
|
|||
// * 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.
|
||||
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,
|
||||
|
|
@ -71,276 +71,291 @@ namespace spot
|
|||
std::stack<spot::state*> init_set;
|
||||
|
||||
Sgi::hash_map<const state*, std::string, state_ptr_hash, state_ptr_equal>
|
||||
colour;
|
||||
colour;
|
||||
|
||||
trace
|
||||
<< "PASS 1" << std::endl;
|
||||
//const std::string WHITE = "W";
|
||||
//const std::string GREY = "G";
|
||||
//const std::string BLUE = "B";
|
||||
//const std::string BLACK = "BK";
|
||||
|
||||
Sgi::hash_map<const state*, std::set<const state*, state_ptr_less_than>,
|
||||
state_ptr_hash, state_ptr_equal> liveset;
|
||||
state_ptr_hash, state_ptr_equal> liveset;
|
||||
|
||||
std::stack<spot::state*> livelock_roots;
|
||||
|
||||
bool livelock_acceptance_states_not_found = true;
|
||||
|
||||
const ta::states_set_t init_states_set = a_->get_initial_states_set();
|
||||
|
||||
ta::states_set_t::const_iterator it;
|
||||
for (it = init_states_set.begin(); it != init_states_set.end(); it++)
|
||||
{
|
||||
state* init_state = (*it);
|
||||
init_set.push(init_state);
|
||||
//colour[init_state] = WHITE;
|
||||
state* init_state = (*it);
|
||||
init_set.push(init_state);
|
||||
|
||||
}
|
||||
|
||||
while (!init_set.empty())
|
||||
{
|
||||
// Setup depth-first search from initial states.
|
||||
// Setup depth-first search from initial states.
|
||||
|
||||
{
|
||||
state* init = init_set.top();
|
||||
init_set.pop();
|
||||
{
|
||||
state* init = init_set.top();
|
||||
init_set.pop();
|
||||
|
||||
numbered_state_heap::state_index_p h_init = h->find(init);
|
||||
numbered_state_heap::state_index_p h_init = h->find(init);
|
||||
|
||||
if (h_init.first)
|
||||
continue;
|
||||
if (h_init.first)
|
||||
continue;
|
||||
|
||||
h->insert(init, ++num);
|
||||
scc.push(num);
|
||||
h->insert(init, ++num);
|
||||
scc.push(num);
|
||||
|
||||
ta_succ_iterator* iter = a_->succ_iter(init);
|
||||
iter->first();
|
||||
todo.push(pair_state_iter(init, iter));
|
||||
//colour[init] = GREY;
|
||||
inc_depth();
|
||||
ta_succ_iterator* iter = a_->succ_iter(init);
|
||||
iter->first();
|
||||
todo.push(pair_state_iter(init, iter));
|
||||
|
||||
//push potential root of live-lock accepting cycle
|
||||
if (a_->is_livelock_accepting_state(init))
|
||||
livelock_roots.push(init);
|
||||
inc_depth();
|
||||
|
||||
}
|
||||
//push potential root of live-lock accepting cycle
|
||||
if (a_->is_livelock_accepting_state(init))
|
||||
livelock_roots.push(init);
|
||||
|
||||
while (!todo.empty())
|
||||
{
|
||||
}
|
||||
|
||||
state* curr = todo.top().first;
|
||||
while (!todo.empty())
|
||||
{
|
||||
|
||||
// We are looking at the next successor in SUCC.
|
||||
ta_succ_iterator* succ = todo.top().second;
|
||||
state* curr = todo.top().first;
|
||||
|
||||
// If there is no more successor, backtrack.
|
||||
if (succ->done())
|
||||
{
|
||||
// We have explored all successors of state CURR.
|
||||
// We are looking at the next successor in SUCC.
|
||||
ta_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();
|
||||
dec_depth();
|
||||
trace
|
||||
<< "PASS 1 : backtrack" << std::endl;
|
||||
// Backtrack TODO.
|
||||
todo.pop();
|
||||
dec_depth();
|
||||
trace
|
||||
<< "PASS 1 : backtrack" << std::endl;
|
||||
|
||||
// fill rem with any component removed,
|
||||
numbered_state_heap::state_index_p spi =
|
||||
h->index(curr->clone());
|
||||
assert(spi.first);
|
||||
if (a_->is_livelock_accepting_state(curr))
|
||||
{
|
||||
livelock_acceptance_states_not_found = false;
|
||||
trace
|
||||
<< "PASS 1 : livelock accepting state found" << std::endl;
|
||||
|
||||
scc.rem().push_front(curr);
|
||||
inc_depth();
|
||||
}
|
||||
|
||||
// set the h value of the Backtracked state to negative value.
|
||||
// colour[curr] = BLUE;
|
||||
*spi.second = -std::abs(*spi.second);
|
||||
// fill rem with any component removed,
|
||||
numbered_state_heap::state_index_p spi =
|
||||
h->index(curr->clone());
|
||||
assert(spi.first);
|
||||
|
||||
// Backtrack livelock_roots.
|
||||
if (!livelock_roots.empty() && !livelock_roots.top()->compare(
|
||||
curr))
|
||||
livelock_roots.pop();
|
||||
scc.rem().push_front(curr);
|
||||
inc_depth();
|
||||
|
||||
// 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(!scc.empty());
|
||||
if (scc.top().index == std::abs(*spi.second))
|
||||
{
|
||||
// removing states
|
||||
std::list<state*>::iterator i;
|
||||
// set the h value of the Backtracked state to negative value.
|
||||
// colour[curr] = BLUE;
|
||||
*spi.second = -std::abs(*spi.second);
|
||||
|
||||
for (i = scc.rem().begin(); i != scc.rem().end(); ++i)
|
||||
{
|
||||
numbered_state_heap::state_index_p spi = h->index(
|
||||
(*i)->clone());
|
||||
assert(spi.first->compare(*i) == 0);
|
||||
assert(*spi.second != -1);
|
||||
*spi.second = -1;
|
||||
//colour[*i] = BLACK;
|
||||
// Backtrack livelock_roots.
|
||||
if (!livelock_roots.empty() && !livelock_roots.top()->compare(
|
||||
curr))
|
||||
livelock_roots.pop();
|
||||
|
||||
}
|
||||
dec_depth(scc.rem().size());
|
||||
scc.pop();
|
||||
}
|
||||
// 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(!scc.empty());
|
||||
if (scc.top().index == std::abs(*spi.second))
|
||||
{
|
||||
// removing states
|
||||
std::list<state*>::iterator i;
|
||||
|
||||
delete succ;
|
||||
// Do not delete CURR: it is a key in H.
|
||||
continue;
|
||||
}
|
||||
for (i = scc.rem().begin(); i != scc.rem().end(); ++i)
|
||||
{
|
||||
numbered_state_heap::state_index_p spi = h->index(
|
||||
(*i)->clone());
|
||||
assert(spi.first->compare(*i) == 0);
|
||||
assert(*spi.second != -1);
|
||||
*spi.second = -1;
|
||||
//colour[*i] = BLACK;
|
||||
|
||||
// We have a successor to look at.
|
||||
inc_transitions();
|
||||
trace
|
||||
<< "PASS 1: transition" << std::endl;
|
||||
// Fetch the values destination state we are interested in...
|
||||
state* dest = succ->current_state();
|
||||
}
|
||||
dec_depth(scc.rem().size());
|
||||
scc.pop();
|
||||
}
|
||||
|
||||
//may be Buchi accepting scc
|
||||
scc.top().is_accepting = a_->is_accepting_state(curr)
|
||||
&& !succ->is_stuttering_transition();
|
||||
delete succ;
|
||||
// Do not delete CURR: it is a key in H.
|
||||
continue;
|
||||
}
|
||||
|
||||
bool is_stuttering_transition = succ->is_stuttering_transition();
|
||||
// We have a successor to look at.
|
||||
inc_transitions();
|
||||
trace
|
||||
<< "PASS 1: transition" << std::endl;
|
||||
// Fetch the values destination state we are interested in...
|
||||
state* dest = succ->current_state();
|
||||
|
||||
// ... and point the iterator to the next successor, for
|
||||
// the next iteration.
|
||||
succ->next();
|
||||
// We do not need SUCC from now on.
|
||||
bool curr_is_livelock_hole_state_in_ta_component =
|
||||
(a_->is_hole_state_in_ta_component(curr))
|
||||
&& a_->is_livelock_accepting_state(curr);
|
||||
|
||||
// Are we going to a new state?
|
||||
numbered_state_heap::state_index_p spi = h->find(dest);
|
||||
//may be Buchi accepting scc or livelock accepting state (contains a TA hole and livelock accepting state)
|
||||
scc.top().is_accepting = (a_->is_accepting_state(curr)
|
||||
&& !succ->is_stuttering_transition())
|
||||
|| curr_is_livelock_hole_state_in_ta_component;
|
||||
|
||||
// Is this a new state?
|
||||
if (!spi.first)
|
||||
{
|
||||
// Number it, stack it, and register its successors
|
||||
// for later processing.
|
||||
h->insert(dest, ++num);
|
||||
scc.push(num);
|
||||
bool is_stuttering_transition = succ->is_stuttering_transition();
|
||||
|
||||
ta_succ_iterator* iter = a_->succ_iter(dest);
|
||||
iter->first();
|
||||
todo.push(pair_state_iter(dest, iter));
|
||||
//colour[dest] = GREY;
|
||||
inc_depth();
|
||||
// ... and point the iterator to the next successor, for
|
||||
// the next iteration.
|
||||
succ->next();
|
||||
// We do not need SUCC from now on.
|
||||
|
||||
//push potential root of live-lock accepting cycle
|
||||
if (a_->is_livelock_accepting_state(dest)
|
||||
&& !is_stuttering_transition)
|
||||
livelock_roots.push(dest);
|
||||
// Are we going to a new state?
|
||||
numbered_state_heap::state_index_p spi = h->find(dest);
|
||||
|
||||
continue;
|
||||
}
|
||||
// Is this a new state?
|
||||
if (!spi.first)
|
||||
{
|
||||
// Number it, stack it, and register its successors
|
||||
// for later processing.
|
||||
h->insert(dest, ++num);
|
||||
scc.push(num);
|
||||
|
||||
// If we have reached a dead component, ignore it.
|
||||
if (*spi.second == -1)
|
||||
continue;
|
||||
ta_succ_iterator* iter = a_->succ_iter(dest);
|
||||
iter->first();
|
||||
todo.push(pair_state_iter(dest, iter));
|
||||
//colour[dest] = GREY;
|
||||
inc_depth();
|
||||
|
||||
// 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 = std::abs(*spi.second);
|
||||
std::list<state*> rem;
|
||||
bool acc = false;
|
||||
//push potential root of live-lock accepting cycle
|
||||
if (a_->is_livelock_accepting_state(dest)
|
||||
&& !is_stuttering_transition)
|
||||
livelock_roots.push(dest);
|
||||
|
||||
while (threshold < scc.top().index)
|
||||
{
|
||||
assert(!scc.empty());
|
||||
continue;
|
||||
}
|
||||
|
||||
acc |= scc.top().is_accepting;
|
||||
// If we have reached a dead component, ignore it.
|
||||
if (*spi.second == -1)
|
||||
continue;
|
||||
|
||||
rem.splice(rem.end(), scc.rem());
|
||||
scc.pop();
|
||||
// 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 = std::abs(*spi.second);
|
||||
std::list<state*> rem;
|
||||
bool acc = false;
|
||||
|
||||
}
|
||||
// Note that we do not always have
|
||||
// threshold == scc.top().index
|
||||
// after this loop, the SSCC whose index is threshold might have
|
||||
// been merged with a lower SSCC.
|
||||
while (threshold < scc.top().index)
|
||||
{
|
||||
assert(!scc.empty());
|
||||
|
||||
// Accumulate all acceptance conditions into the merged SSCC.
|
||||
scc.top().is_accepting |= acc;
|
||||
acc |= scc.top().is_accepting;
|
||||
|
||||
scc.rem().splice(scc.rem().end(), rem);
|
||||
if (scc.top().is_accepting)
|
||||
{
|
||||
clear(h, todo, init_set);
|
||||
trace
|
||||
<< "PASS 1: SUCCESS" << std::endl;
|
||||
return true;
|
||||
}
|
||||
rem.splice(rem.end(), scc.rem());
|
||||
scc.pop();
|
||||
|
||||
//ADDLINKS
|
||||
if (!is_full_2_pass_ && a_->is_livelock_accepting_state(curr)
|
||||
&& is_stuttering_transition)
|
||||
{
|
||||
trace
|
||||
<< "PASS 1: heuristic livelock detection " << std::endl;
|
||||
const state* dest = spi.first;
|
||||
std::set<const state*, state_ptr_less_than> liveset_dest =
|
||||
liveset[dest];
|
||||
}
|
||||
// Note that we do not always have
|
||||
// threshold == scc.top().index
|
||||
// after this loop, the SSCC whose index is threshold might have
|
||||
// been merged with a lower SSCC.
|
||||
|
||||
std::set<const state*, state_ptr_less_than> liveset_curr =
|
||||
liveset[curr];
|
||||
// Accumulate all acceptance conditions into the merged SSCC.
|
||||
scc.top().is_accepting |= acc;
|
||||
|
||||
int h_livelock_root = 0;
|
||||
if (!livelock_roots.empty())
|
||||
h_livelock_root = *(h->find((livelock_roots.top()))).second;
|
||||
scc.rem().splice(scc.rem().end(), rem);
|
||||
if (scc.top().is_accepting)
|
||||
{
|
||||
clear(h, todo, init_set);
|
||||
trace
|
||||
<< "PASS 1: SUCCESS" << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (heuristic_livelock_detection(dest, h, h_livelock_root,
|
||||
liveset_curr))
|
||||
{
|
||||
clear(h, todo, init_set);
|
||||
return true;
|
||||
}
|
||||
//ADDLINKS
|
||||
if (!is_full_2_pass_ && a_->is_livelock_accepting_state(curr)
|
||||
&& is_stuttering_transition)
|
||||
{
|
||||
trace
|
||||
<< "PASS 1: heuristic livelock detection " << std::endl;
|
||||
const state* dest = spi.first;
|
||||
std::set<const state*, state_ptr_less_than> liveset_dest =
|
||||
liveset[dest];
|
||||
|
||||
std::set<const state*, state_ptr_less_than>::const_iterator it;
|
||||
for (it = liveset_dest.begin(); it != liveset_dest.end(); it++)
|
||||
{
|
||||
const state* succ = (*it);
|
||||
if (heuristic_livelock_detection(succ, h, h_livelock_root,
|
||||
liveset_curr))
|
||||
{
|
||||
clear(h, todo, init_set);
|
||||
return true;
|
||||
}
|
||||
std::set<const state*, state_ptr_less_than> liveset_curr =
|
||||
liveset[curr];
|
||||
|
||||
}
|
||||
int h_livelock_root = 0;
|
||||
if (!livelock_roots.empty())
|
||||
h_livelock_root = *(h->find((livelock_roots.top()))).second;
|
||||
|
||||
}
|
||||
}
|
||||
if (heuristic_livelock_detection(dest, h, h_livelock_root,
|
||||
liveset_curr))
|
||||
{
|
||||
clear(h, todo, init_set);
|
||||
return true;
|
||||
}
|
||||
|
||||
std::set<const state*, state_ptr_less_than>::const_iterator it;
|
||||
for (it = liveset_dest.begin(); it != liveset_dest.end(); it++)
|
||||
{
|
||||
const state* succ = (*it);
|
||||
if (heuristic_livelock_detection(succ, h, h_livelock_root,
|
||||
liveset_curr))
|
||||
{
|
||||
clear(h, todo, init_set);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
clear(h, todo, init_set);
|
||||
|
||||
if (disable_second_pass || livelock_acceptance_states_not_found)
|
||||
return false;
|
||||
|
||||
return livelock_detection(a_);
|
||||
}
|
||||
|
||||
bool
|
||||
ta_check::heuristic_livelock_detection(const state * u,
|
||||
numbered_state_heap* h, int h_livelock_root, std::set<const state*,
|
||||
state_ptr_less_than> liveset_curr)
|
||||
state_ptr_less_than> liveset_curr)
|
||||
{
|
||||
numbered_state_heap::state_index_p hu = h->find(u);
|
||||
|
||||
if (*hu.second > 0) // colour[u] == GREY
|
||||
{
|
||||
|
||||
if (*hu.second >= h_livelock_root)
|
||||
{
|
||||
trace
|
||||
<< "PASS 1: heuristic livelock detection SUCCESS" << std::endl;
|
||||
return true;
|
||||
}
|
||||
if (*hu.second >= h_livelock_root)
|
||||
{
|
||||
trace
|
||||
<< "PASS 1: heuristic livelock detection SUCCESS" << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
liveset_curr.insert(u);
|
||||
liveset_curr.insert(u);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
@ -358,7 +373,7 @@ namespace spot
|
|||
// * 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.
|
||||
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,
|
||||
|
|
@ -378,195 +393,191 @@ namespace spot
|
|||
// * init: the set of the depth-first search initial states
|
||||
std::stack<spot::state*> init_set;
|
||||
|
||||
|
||||
|
||||
const ta::states_set_t init_states_set = a_->get_initial_states_set();
|
||||
ta::states_set_t::const_iterator it;
|
||||
for (it = init_states_set.begin(); it != init_states_set.end(); it++)
|
||||
{
|
||||
state* init_state = (*it);
|
||||
init_set.push(init_state);
|
||||
|
||||
state* init_state = (*it);
|
||||
init_set.push(init_state);
|
||||
|
||||
}
|
||||
|
||||
|
||||
while (!init_set.empty())
|
||||
{
|
||||
// Setup depth-first search from initial states.
|
||||
{
|
||||
state* init = init_set.top();
|
||||
init_set.pop();
|
||||
numbered_state_heap::state_index_p h_init = h->find(init);
|
||||
// Setup depth-first search from initial states.
|
||||
{
|
||||
state* init = init_set.top();
|
||||
init_set.pop();
|
||||
numbered_state_heap::state_index_p h_init = h->find(init);
|
||||
|
||||
if (h_init.first)
|
||||
continue;
|
||||
if (h_init.first)
|
||||
continue;
|
||||
|
||||
h->insert(init, ++num);
|
||||
sscc.push(num);
|
||||
sscc.top().is_accepting = t->is_livelock_accepting_state(init);
|
||||
ta_succ_iterator* iter = t->succ_iter(init);
|
||||
iter->first();
|
||||
todo.push(pair_state_iter(init, iter));
|
||||
inc_depth();
|
||||
h->insert(init, ++num);
|
||||
sscc.push(num);
|
||||
sscc.top().is_accepting = t->is_livelock_accepting_state(init);
|
||||
ta_succ_iterator* iter = t->succ_iter(init);
|
||||
iter->first();
|
||||
todo.push(pair_state_iter(init, iter));
|
||||
inc_depth();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
while (!todo.empty())
|
||||
{
|
||||
while (!todo.empty())
|
||||
{
|
||||
|
||||
state* curr = todo.top().first;
|
||||
state* curr = todo.top().first;
|
||||
|
||||
// We are looking at the next successor in SUCC.
|
||||
ta_succ_iterator* succ = todo.top().second;
|
||||
// We are looking at the next successor in SUCC.
|
||||
ta_succ_iterator* succ = todo.top().second;
|
||||
|
||||
// If there is no more successor, backtrack.
|
||||
if (succ->done())
|
||||
{
|
||||
// We have explored all successors of state CURR.
|
||||
// If there is no more successor, backtrack.
|
||||
if (succ->done())
|
||||
{
|
||||
// We have explored all successors of state CURR.
|
||||
|
||||
// Backtrack TODO.
|
||||
todo.pop();
|
||||
dec_depth();
|
||||
trace
|
||||
<< "PASS 2 : backtrack" << std::endl;
|
||||
// Backtrack TODO.
|
||||
todo.pop();
|
||||
dec_depth();
|
||||
trace
|
||||
<< "PASS 2 : backtrack" << std::endl;
|
||||
|
||||
// fill rem with any component removed,
|
||||
numbered_state_heap::state_index_p spi =
|
||||
h->index(curr->clone());
|
||||
assert(spi.first);
|
||||
// fill rem with any component removed,
|
||||
numbered_state_heap::state_index_p spi =
|
||||
h->index(curr->clone());
|
||||
assert(spi.first);
|
||||
|
||||
sscc.rem().push_front(curr);
|
||||
inc_depth();
|
||||
sscc.rem().push_front(curr);
|
||||
inc_depth();
|
||||
|
||||
// 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;
|
||||
// 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;
|
||||
|
||||
for (i = sscc.rem().begin(); i != sscc.rem().end(); ++i)
|
||||
{
|
||||
numbered_state_heap::state_index_p spi = h->index(
|
||||
(*i)->clone());
|
||||
assert(spi.first->compare(*i) == 0);
|
||||
assert(*spi.second != -1);
|
||||
*spi.second = -1;
|
||||
}
|
||||
dec_depth(sscc.rem().size());
|
||||
sscc.pop();
|
||||
}
|
||||
for (i = sscc.rem().begin(); i != sscc.rem().end(); ++i)
|
||||
{
|
||||
numbered_state_heap::state_index_p spi = h->index(
|
||||
(*i)->clone());
|
||||
assert(spi.first->compare(*i) == 0);
|
||||
assert(*spi.second != -1);
|
||||
*spi.second = -1;
|
||||
}
|
||||
dec_depth(sscc.rem().size());
|
||||
sscc.pop();
|
||||
}
|
||||
|
||||
delete succ;
|
||||
// Do not delete CURR: it is a key in H.
|
||||
delete succ;
|
||||
// Do not delete CURR: it is a key in H.
|
||||
|
||||
continue;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
// We have a successor to look at.
|
||||
inc_transitions();
|
||||
trace
|
||||
<< "PASS 2 : transition" << std::endl;
|
||||
// Fetch the values destination state we are interested in...
|
||||
state* dest = succ->current_state();
|
||||
// We have a successor to look at.
|
||||
inc_transitions();
|
||||
trace
|
||||
<< "PASS 2 : transition" << std::endl;
|
||||
// Fetch the values destination state we are interested in...
|
||||
state* dest = succ->current_state();
|
||||
|
||||
bool is_stuttering_transition = succ->is_stuttering_transition();
|
||||
// ... and point the iterator to the next successor, for
|
||||
// the next iteration.
|
||||
succ->next();
|
||||
// We do not need SUCC from now on.
|
||||
bool is_stuttering_transition = succ->is_stuttering_transition();
|
||||
// ... and point the iterator to the next successor, for
|
||||
// the next iteration.
|
||||
succ->next();
|
||||
// We do not need SUCC from now on.
|
||||
|
||||
numbered_state_heap::state_index_p spi = h->find(dest);
|
||||
numbered_state_heap::state_index_p spi = h->find(dest);
|
||||
|
||||
// Is this a new state?
|
||||
if (!spi.first)
|
||||
{
|
||||
// Is this a new state?
|
||||
if (!spi.first)
|
||||
{
|
||||
|
||||
// Are we going to a new state through a stuttering transition?
|
||||
// Are we going to a new state through a stuttering transition?
|
||||
|
||||
if (!is_stuttering_transition)
|
||||
{
|
||||
init_set.push(dest);
|
||||
continue;
|
||||
}
|
||||
if (!is_stuttering_transition)
|
||||
{
|
||||
init_set.push(dest);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Number it, stack it, and register its successors
|
||||
// for later processing.
|
||||
h->insert(dest, ++num);
|
||||
sscc.push(num);
|
||||
sscc.top().is_accepting = t->is_livelock_accepting_state(dest);
|
||||
// Number it, stack it, and register its successors
|
||||
// for later processing.
|
||||
h->insert(dest, ++num);
|
||||
sscc.push(num);
|
||||
sscc.top().is_accepting = t->is_livelock_accepting_state(dest);
|
||||
|
||||
ta_succ_iterator* iter = t->succ_iter(dest);
|
||||
iter->first();
|
||||
todo.push(pair_state_iter(dest, iter));
|
||||
inc_depth();
|
||||
continue;
|
||||
}
|
||||
ta_succ_iterator* iter = t->succ_iter(dest);
|
||||
iter->first();
|
||||
todo.push(pair_state_iter(dest, iter));
|
||||
inc_depth();
|
||||
continue;
|
||||
}
|
||||
|
||||
// If we have reached a dead component, ignore it.
|
||||
if (*spi.second == -1)
|
||||
continue;
|
||||
// If we have reached a dead component, ignore it.
|
||||
if (*spi.second == -1)
|
||||
continue;
|
||||
|
||||
//self loop state
|
||||
if (!curr->compare(spi.first))
|
||||
{
|
||||
state * self_loop_state = (curr);
|
||||
//self loop state
|
||||
if (!curr->compare(spi.first))
|
||||
{
|
||||
state * self_loop_state = (curr);
|
||||
|
||||
if (t->is_livelock_accepting_state(self_loop_state))
|
||||
{
|
||||
clear(h, todo, init_set);
|
||||
trace
|
||||
<< "PASS 2: SUCCESS" << std::endl;
|
||||
return true;
|
||||
}
|
||||
if (t->is_livelock_accepting_state(self_loop_state))
|
||||
{
|
||||
clear(h, todo, init_set);
|
||||
trace
|
||||
<< "PASS 2: SUCCESS" << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// 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;
|
||||
// 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());
|
||||
while (threshold < sscc.top().index)
|
||||
{
|
||||
assert(!sscc.empty());
|
||||
|
||||
acc |= sscc.top().is_accepting;
|
||||
acc |= sscc.top().is_accepting;
|
||||
|
||||
rem.splice(rem.end(), sscc.rem());
|
||||
sscc.pop();
|
||||
rem.splice(rem.end(), sscc.rem());
|
||||
sscc.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.
|
||||
}
|
||||
// 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;
|
||||
// Accumulate all acceptance conditions into the merged SSCC.
|
||||
sscc.top().is_accepting |= acc;
|
||||
|
||||
sscc.rem().splice(sscc.rem().end(), rem);
|
||||
if (sscc.top().is_accepting)
|
||||
{
|
||||
clear(h, todo, init_set);
|
||||
trace
|
||||
<< "PASS 2: SUCCESS" << std::endl;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
sscc.rem().splice(sscc.rem().end(), rem);
|
||||
if (sscc.top().is_accepting)
|
||||
{
|
||||
clear(h, todo, init_set);
|
||||
trace
|
||||
<< "PASS 2: SUCCESS" << std::endl;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
clear(h, todo, init_set);
|
||||
|
|
@ -582,16 +593,16 @@ namespace spot
|
|||
|
||||
while (!init_states.empty())
|
||||
{
|
||||
a_->free_state(init_states.top());
|
||||
init_states.pop();
|
||||
a_->free_state(init_states.top());
|
||||
init_states.pop();
|
||||
}
|
||||
|
||||
// Release all iterators in TODO.
|
||||
while (!todo.empty())
|
||||
{
|
||||
delete todo.top().second;
|
||||
todo.pop();
|
||||
dec_depth();
|
||||
delete todo.top().second;
|
||||
todo.pop();
|
||||
dec_depth();
|
||||
}
|
||||
delete h;
|
||||
}
|
||||
|
|
@ -604,7 +615,7 @@ namespace spot
|
|||
|
||||
//TODO sscc;
|
||||
os << scc.size() << " strongly connected components in search stack"
|
||||
<< std::endl;
|
||||
<< std::endl;
|
||||
os << transitions() << " transitions explored" << std::endl;
|
||||
os << max_depth() << " items max in DFS search stack" << std::endl;
|
||||
return os;
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@
|
|||
#ifndef SPOT_TAALGOS_EMPTINESS_HH
|
||||
# define SPOT_TAALGOS_EMPTINESS_HH
|
||||
|
||||
#include "ta/ta.hh"
|
||||
#include "ta/taproduct.hh"
|
||||
#include "misc/optionmap.hh"
|
||||
#include "tgbaalgos/gtec/nsheap.hh"
|
||||
#include "tgbaalgos/emptiness_stats.hh"
|
||||
|
|
@ -43,13 +43,13 @@ namespace spot
|
|||
class ta_check : public ec_statistics
|
||||
{
|
||||
public:
|
||||
ta_check(const ta* a, option_map o = option_map());
|
||||
ta_check(const ta_product* a, option_map o = option_map());
|
||||
virtual
|
||||
~ta_check();
|
||||
|
||||
/// Check whether the automaton's language is empty.
|
||||
virtual bool
|
||||
check();
|
||||
check(bool disable_second_pass = false);
|
||||
|
||||
virtual bool
|
||||
livelock_detection(const ta* t);
|
||||
|
|
@ -75,7 +75,7 @@ namespace spot
|
|||
heuristic_livelock_detection(const state * stuttering_succ,
|
||||
numbered_state_heap* h, int h_livelock_root, std::set<const state*,
|
||||
state_ptr_less_than> liveset_curr);
|
||||
const ta* a_; ///< The automaton.
|
||||
const ta_product* a_; ///< The automaton.
|
||||
option_map o_; ///< The options
|
||||
|
||||
bool is_full_2_pass_;
|
||||
|
|
|
|||
|
|
@ -106,7 +106,7 @@ namespace spot
|
|||
state* tgba_state = tgba->add_state(src_num);
|
||||
bdd tgba_condition = bddtrue;
|
||||
bool is_initial_state = a->is_initial_state(src);
|
||||
if (is_initial_state)
|
||||
if ((a->get_artificial_initial_state() == 0) && is_initial_state)
|
||||
tgba_condition = a->get_state_condition(src);
|
||||
bool is_accepting_state = a->is_accepting_state(src);
|
||||
bool is_livelock_accepting_state = a->is_livelock_accepting_state(src);
|
||||
|
|
@ -120,10 +120,16 @@ namespace spot
|
|||
if (ta_src != new_src)
|
||||
{
|
||||
new_src->destroy();
|
||||
tgba_state->destroy();
|
||||
}
|
||||
else if (a->get_artificial_initial_state() != 0)
|
||||
{
|
||||
if (a->get_artificial_initial_state() == src)
|
||||
ta->set_artificial_initial_state(new_src);
|
||||
}
|
||||
else if (is_initial_state)
|
||||
ta->add_to_initial_states_set(new_src);
|
||||
{
|
||||
ta->add_to_initial_states_set(new_src);
|
||||
}
|
||||
|
||||
ta_succ_iterator* succit = a->succ_iter(src);
|
||||
|
||||
|
|
@ -138,7 +144,7 @@ namespace spot
|
|||
state* tgba_state = tgba->add_state(i->second);
|
||||
bdd tgba_condition = bddtrue;
|
||||
is_initial_state = a->is_initial_state(dst);
|
||||
if (is_initial_state)
|
||||
if ((a->get_artificial_initial_state() == 0) && is_initial_state)
|
||||
tgba_condition = a->get_state_condition(dst);
|
||||
bool is_accepting_state = a->is_accepting_state(dst);
|
||||
bool is_livelock_accepting_state = a->is_livelock_accepting_state(
|
||||
|
|
@ -153,8 +159,13 @@ namespace spot
|
|||
if (ta_dst != new_dst)
|
||||
{
|
||||
new_dst->destroy();
|
||||
tgba_state->destroy();
|
||||
}
|
||||
else if (a->get_artificial_initial_state() != 0)
|
||||
{
|
||||
if (a->get_artificial_initial_state() == dst)
|
||||
ta->set_artificial_initial_state(new_dst);
|
||||
}
|
||||
|
||||
else if (is_initial_state)
|
||||
ta->add_to_initial_states_set(new_dst);
|
||||
|
||||
|
|
@ -196,11 +207,17 @@ namespace spot
|
|||
|
||||
std::set<const state*>::iterator it;
|
||||
|
||||
spot::state* artificial_initial_state = ta_->get_artificial_initial_state();
|
||||
|
||||
for (it = states_set.begin(); it != states_set.end(); it++)
|
||||
{
|
||||
const state* s = (*it);
|
||||
|
||||
if (ta_->is_initial_state(s))
|
||||
if (s == artificial_initial_state)
|
||||
{
|
||||
I->insert(s);
|
||||
}
|
||||
else if (artificial_initial_state == 0 && ta_->is_initial_state(s))
|
||||
{
|
||||
I->insert(s);
|
||||
}
|
||||
|
|
@ -254,12 +271,13 @@ namespace spot
|
|||
}
|
||||
|
||||
}
|
||||
delete I;
|
||||
|
||||
if (!G->empty())
|
||||
delete I;
|
||||
|
||||
if (!G->empty())
|
||||
{
|
||||
unsigned s = G->size();
|
||||
unsigned num = ++set_num;
|
||||
unsigned num = set_num;
|
||||
set_num++;
|
||||
used_var[num] = s;
|
||||
free_var.erase(num);
|
||||
if (s > 1)
|
||||
|
|
@ -276,7 +294,8 @@ namespace spot
|
|||
if (!F->empty())
|
||||
{
|
||||
unsigned s = F->size();
|
||||
unsigned num = ++set_num;
|
||||
unsigned num = set_num;
|
||||
set_num++;
|
||||
used_var[num] = s;
|
||||
free_var.erase(num);
|
||||
if (s > 1)
|
||||
|
|
@ -292,7 +311,8 @@ namespace spot
|
|||
if (!G_F->empty())
|
||||
{
|
||||
unsigned s = G_F->size();
|
||||
unsigned num = ++set_num;
|
||||
unsigned num = set_num;
|
||||
set_num++;
|
||||
used_var[num] = s;
|
||||
free_var.erase(num);
|
||||
if (s > 1)
|
||||
|
|
@ -308,7 +328,8 @@ namespace spot
|
|||
if (!S->empty())
|
||||
{
|
||||
unsigned s = S->size();
|
||||
unsigned num = ++set_num;
|
||||
unsigned num = set_num;
|
||||
set_num++;
|
||||
used_var[num] = s;
|
||||
free_var.erase(num);
|
||||
if (s > 1)
|
||||
|
|
|
|||
|
|
@ -51,10 +51,23 @@ namespace spot
|
|||
{
|
||||
int n = 0;
|
||||
start();
|
||||
const ta::states_set_t init_states_set =
|
||||
t_automata_->get_initial_states_set();
|
||||
|
||||
spot::state* artificial_initial_state =
|
||||
t_automata_->get_artificial_initial_state();
|
||||
|
||||
ta::states_set_t init_states_set;
|
||||
|
||||
ta::states_set_t::const_iterator it;
|
||||
|
||||
if (artificial_initial_state != 0)
|
||||
{
|
||||
init_states_set.insert(artificial_initial_state);
|
||||
}
|
||||
else
|
||||
{
|
||||
init_states_set = t_automata_->get_initial_states_set();
|
||||
}
|
||||
|
||||
for (it = init_states_set.begin(); it != init_states_set.end(); it++)
|
||||
{
|
||||
state* init_state = (*it);
|
||||
|
|
@ -89,7 +102,7 @@ namespace spot
|
|||
{
|
||||
if (ws)
|
||||
process_link(tn, s->second, si);
|
||||
t_automata_->free_state(current);
|
||||
t_automata_->free_state(current);
|
||||
}
|
||||
}
|
||||
delete si;
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@
|
|||
#include "tgbaalgos/gtec/nsheap.hh"
|
||||
#include <stack>
|
||||
#include "sba2ta.hh"
|
||||
#include "taalgos/statessetbuilder.hh"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
|
@ -36,93 +37,193 @@ namespace spot
|
|||
{
|
||||
|
||||
ta*
|
||||
sba_to_ta(const tgba_sba_proxy* tgba_, bdd atomic_propositions_set_)
|
||||
sba_to_ta(const tgba_sba_proxy* tgba_, bdd atomic_propositions_set_,
|
||||
bool artificial_initial_state_mode,
|
||||
bool artificial_livelock_accepting_state_mode)
|
||||
{
|
||||
|
||||
ta_explicit* ta = new spot::ta_explicit(tgba_);
|
||||
|
||||
ta_explicit* ta;
|
||||
std::stack<state_ta_explicit*> todo;
|
||||
|
||||
// build Initial states set:
|
||||
state* tgba_init_state = tgba_->get_init_state();
|
||||
|
||||
if (artificial_initial_state_mode)
|
||||
{
|
||||
state_ta_explicit* ta_init_state = new state_ta_explicit(
|
||||
tgba_init_state->clone(), bddtrue, true);
|
||||
|
||||
ta = new spot::ta_explicit(tgba_, ta_init_state);
|
||||
}
|
||||
else
|
||||
{
|
||||
ta = new spot::ta_explicit(tgba_);
|
||||
}
|
||||
|
||||
bdd tgba_condition = tgba_->support_conditions(tgba_init_state);
|
||||
|
||||
bdd satone_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;
|
||||
state_ta_explicit* init_state = new state_ta_explicit(
|
||||
tgba_init_state->clone(), satone_tgba_condition, true,
|
||||
tgba_->state_is_accepting(tgba_init_state));
|
||||
state_ta_explicit* is = ta->add_state(init_state);
|
||||
assert(is == init_state);
|
||||
ta->add_to_initial_states_set(is);
|
||||
todo.push(init_state);
|
||||
tgba_condition -= satone_tgba_condition;
|
||||
state_ta_explicit* init_state = new state_ta_explicit(
|
||||
tgba_init_state->clone(), satone_tgba_condition, true,
|
||||
tgba_->state_is_accepting(tgba_init_state));
|
||||
state_ta_explicit* s = ta->add_state(init_state);
|
||||
assert(s == init_state);
|
||||
ta->add_to_initial_states_set(s);
|
||||
|
||||
todo.push(init_state);
|
||||
}
|
||||
tgba_init_state->destroy();
|
||||
|
||||
while (!todo.empty())
|
||||
{
|
||||
state_ta_explicit* source = todo.top();
|
||||
todo.pop();
|
||||
state_ta_explicit* source = todo.top();
|
||||
todo.pop();
|
||||
|
||||
tgba_succ_iterator* tgba_succ_it = tgba_->succ_iter(
|
||||
source->get_tgba_state());
|
||||
for (tgba_succ_it->first(); !tgba_succ_it->done(); tgba_succ_it->next())
|
||||
{
|
||||
const state* tgba_state = tgba_succ_it->current_state();
|
||||
bdd tgba_condition = tgba_succ_it->current_condition();
|
||||
bdd satone_tgba_condition;
|
||||
while ((satone_tgba_condition = bdd_satoneset(tgba_condition,
|
||||
atomic_propositions_set_, bddtrue)) != bddfalse)
|
||||
{
|
||||
tgba_succ_iterator* tgba_succ_it = tgba_->succ_iter(
|
||||
source->get_tgba_state());
|
||||
for (tgba_succ_it->first(); !tgba_succ_it->done(); tgba_succ_it->next())
|
||||
{
|
||||
const state* tgba_state = tgba_succ_it->current_state();
|
||||
bdd tgba_condition = tgba_succ_it->current_condition();
|
||||
bdd satone_tgba_condition;
|
||||
while ((satone_tgba_condition = bdd_satoneset(tgba_condition,
|
||||
atomic_propositions_set_, bddtrue)) != bddfalse)
|
||||
{
|
||||
|
||||
tgba_condition -= satone_tgba_condition;
|
||||
tgba_condition -= satone_tgba_condition;
|
||||
|
||||
bdd all_props = bddtrue;
|
||||
bdd dest_condition;
|
||||
if (satone_tgba_condition == source->get_tgba_condition())
|
||||
while ((dest_condition = bdd_satoneset(all_props,
|
||||
atomic_propositions_set_, bddtrue)) != bddfalse)
|
||||
{
|
||||
all_props -= dest_condition;
|
||||
state_ta_explicit* new_dest = new state_ta_explicit(
|
||||
tgba_state->clone(), dest_condition, false,
|
||||
tgba_->state_is_accepting(tgba_state));
|
||||
bdd all_props = bddtrue;
|
||||
bdd dest_condition;
|
||||
if (satone_tgba_condition == source->get_tgba_condition())
|
||||
while ((dest_condition = bdd_satoneset(all_props,
|
||||
atomic_propositions_set_, bddtrue)) != bddfalse)
|
||||
{
|
||||
all_props -= dest_condition;
|
||||
state_ta_explicit* new_dest = new state_ta_explicit(
|
||||
tgba_state->clone(), dest_condition, false,
|
||||
tgba_->state_is_accepting(tgba_state));
|
||||
|
||||
state_ta_explicit* dest = ta->add_state(new_dest);
|
||||
state_ta_explicit* dest = ta->add_state(new_dest);
|
||||
|
||||
if (dest != new_dest)
|
||||
{
|
||||
// the state dest already exists in the testing automata
|
||||
new_dest->get_tgba_state()->destroy();
|
||||
delete new_dest;
|
||||
}
|
||||
else
|
||||
{
|
||||
todo.push(dest);
|
||||
}
|
||||
if (dest != new_dest)
|
||||
{
|
||||
// the state dest already exists in the testing automata
|
||||
new_dest->get_tgba_state()->destroy();
|
||||
delete new_dest;
|
||||
}
|
||||
else
|
||||
{
|
||||
todo.push(dest);
|
||||
}
|
||||
|
||||
ta->create_transition(source, bdd_setxor(
|
||||
source->get_tgba_condition(),
|
||||
dest->get_tgba_condition()), dest);
|
||||
}
|
||||
ta->create_transition(source, bdd_setxor(
|
||||
source->get_tgba_condition(),
|
||||
dest->get_tgba_condition()), dest);
|
||||
}
|
||||
|
||||
}
|
||||
tgba_state->destroy();
|
||||
}
|
||||
delete tgba_succ_it;
|
||||
}
|
||||
tgba_state->destroy();
|
||||
}
|
||||
delete tgba_succ_it;
|
||||
|
||||
}
|
||||
|
||||
compute_livelock_acceptance_states(ta);
|
||||
if (artificial_livelock_accepting_state_mode)
|
||||
{
|
||||
|
||||
state_ta_explicit* artificial_livelock_accepting_state =
|
||||
new state_ta_explicit(ta->get_tgba()->get_init_state(), bddfalse,
|
||||
false, false, true, 0, true);
|
||||
|
||||
state_ta_explicit* artificial_livelock_accepting_state_added = ta->add_state(artificial_livelock_accepting_state);
|
||||
|
||||
// unique artificial_livelock_accepting_state
|
||||
assert(artificial_livelock_accepting_state_added
|
||||
== artificial_livelock_accepting_state);
|
||||
|
||||
add_artificial_livelock_accepting_state(ta,
|
||||
artificial_livelock_accepting_state_added);
|
||||
|
||||
}
|
||||
|
||||
return ta;
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
add_artificial_livelock_accepting_state(ta_explicit* testing_automata,
|
||||
state_ta_explicit* artificial_livelock_accepting_state)
|
||||
{
|
||||
|
||||
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;
|
||||
|
||||
if (dest->is_livelock_accepting_state())
|
||||
{
|
||||
conditions_to_livelock_accepting_states->insert(
|
||||
(*it_trans)->condition);
|
||||
|
||||
}
|
||||
|
||||
//remove hole successors states
|
||||
state_ta_explicit::transitions* dest_trans =
|
||||
(dest)->get_transitions();
|
||||
bool dest_trans_empty = dest_trans == 0 || dest_trans->empty();
|
||||
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),
|
||||
artificial_livelock_accepting_state);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
delete conditions_to_livelock_accepting_states;
|
||||
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
typedef std::pair<spot::state*, tgba_succ_iterator*> pair_state_iter;
|
||||
|
|
@ -138,7 +239,7 @@ namespace spot
|
|||
// * 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.
|
||||
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,
|
||||
|
|
@ -158,201 +259,200 @@ namespace spot
|
|||
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 = down_cast<state_ta_explicit*> (*it);
|
||||
init_set.push(init_state);
|
||||
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->clone();
|
||||
numbered_state_heap::state_index_p h_init = h->find(init_clone);
|
||||
// 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->clone();
|
||||
numbered_state_heap::state_index_p h_init = h->find(init_clone);
|
||||
|
||||
if (h_init.first)
|
||||
continue;
|
||||
if (h_init.first)
|
||||
continue;
|
||||
|
||||
h->insert(init_clone, ++num);
|
||||
sscc.push(num);
|
||||
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));
|
||||
h->insert(init_clone, ++num);
|
||||
sscc.push(num);
|
||||
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())
|
||||
{
|
||||
while (!todo.empty())
|
||||
{
|
||||
|
||||
state* curr = todo.top().first;
|
||||
state* curr = todo.top().first;
|
||||
|
||||
numbered_state_heap::state_index_p spi = h->find(curr->clone());
|
||||
// If we have reached a dead component, ignore it.
|
||||
if (*spi.second == -1)
|
||||
{
|
||||
todo.pop();
|
||||
continue;
|
||||
}
|
||||
numbered_state_heap::state_index_p spi = h->find(curr->clone());
|
||||
// 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;
|
||||
// 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.
|
||||
// If there is no more successor, backtrack.
|
||||
if (succ->done())
|
||||
{
|
||||
// We have explored all successors of state CURR.
|
||||
|
||||
// Backtrack TODO.
|
||||
todo.pop();
|
||||
// Backtrack TODO.
|
||||
todo.pop();
|
||||
|
||||
// fill rem with any component removed,
|
||||
numbered_state_heap::state_index_p spi =
|
||||
h->index(curr->clone());
|
||||
assert(spi.first);
|
||||
// fill rem with any component removed,
|
||||
numbered_state_heap::state_index_p spi =
|
||||
h->index(curr->clone());
|
||||
assert(spi.first);
|
||||
|
||||
sscc.rem().push_front(curr);
|
||||
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.top().is_accepting
|
||||
&& (sscc.rem().size() > 1));
|
||||
for (i = sscc.rem().begin(); i != sscc.rem().end(); ++i)
|
||||
{
|
||||
numbered_state_heap::state_index_p spi = h->index(
|
||||
(*i)->clone());
|
||||
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)
|
||||
// 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.top().is_accepting
|
||||
&& (sscc.rem().size() > 1));
|
||||
for (i = sscc.rem().begin(); i != sscc.rem().end(); ++i)
|
||||
{
|
||||
numbered_state_heap::state_index_p spi = h->index(
|
||||
(*i)->clone());
|
||||
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);
|
||||
state_ta_explicit * livelock_accepting_state =
|
||||
down_cast<state_ta_explicit*> (*i);
|
||||
|
||||
livelock_accepting_state->set_livelock_accepting_state(
|
||||
true);
|
||||
livelock_accepting_state->set_livelock_accepting_state(
|
||||
true);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
sscc.pop();
|
||||
|
||||
sscc.pop();
|
||||
}
|
||||
|
||||
}
|
||||
// automata reduction
|
||||
testing_automata->delete_stuttering_and_hole_successors(curr);
|
||||
|
||||
// automata reduction
|
||||
testing_automata->delete_stuttering_and_hole_successors(curr);
|
||||
delete succ;
|
||||
// Do not delete CURR: it is a key in H.
|
||||
continue;
|
||||
}
|
||||
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();
|
||||
// Fetch the values destination state we are interested in...
|
||||
state* dest = succ->current_state();
|
||||
|
||||
// ... and point the iterator to the next successor, for
|
||||
// the next iteration.
|
||||
succ->next();
|
||||
// We do not need SUCC from now on.
|
||||
// ... 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->clone();
|
||||
spi = h->find(dest_clone);
|
||||
// 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->clone();
|
||||
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;
|
||||
}
|
||||
// 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);
|
||||
sscc.top().is_accepting = testing_automata->is_accepting_state(
|
||||
dest);
|
||||
// Number it, stack it, and register its successors
|
||||
// for later processing.
|
||||
h->insert(dest_clone, ++num);
|
||||
sscc.push(num);
|
||||
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;
|
||||
}
|
||||
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;
|
||||
// If we have reached a dead component, ignore it.
|
||||
if (*spi.second == -1)
|
||||
continue;
|
||||
|
||||
if (!curr->compare(dest))
|
||||
{
|
||||
state_ta_explicit * self_loop_state =
|
||||
down_cast<state_ta_explicit*> (curr);
|
||||
assert(self_loop_state);
|
||||
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))
|
||||
self_loop_state->set_livelock_accepting_state(true);
|
||||
if (testing_automata->is_accepting_state(self_loop_state))
|
||||
self_loop_state->set_livelock_accepting_state(true);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// 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;
|
||||
// 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());
|
||||
while (threshold < sscc.top().index)
|
||||
{
|
||||
assert(!sscc.empty());
|
||||
|
||||
acc |= sscc.top().is_accepting;
|
||||
acc |= sscc.top().is_accepting;
|
||||
|
||||
rem.splice(rem.end(), sscc.rem());
|
||||
sscc.pop();
|
||||
rem.splice(rem.end(), sscc.rem());
|
||||
sscc.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.
|
||||
}
|
||||
// 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;
|
||||
// Accumulate all acceptance conditions into the merged SSCC.
|
||||
sscc.top().is_accepting |= acc;
|
||||
|
||||
sscc.rem().splice(sscc.rem().end(), rem);
|
||||
sscc.rem().splice(sscc.rem().end(), rem);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
delete h;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,13 +31,18 @@
|
|||
#include "misc/bddlt.hh"
|
||||
#include "ta/taexplicit.hh"
|
||||
|
||||
|
||||
namespace spot
|
||||
{
|
||||
ta* sba_to_ta(const tgba_sba_proxy* tgba_to_convert, bdd atomic_propositions_set);
|
||||
ta*
|
||||
sba_to_ta(const tgba_sba_proxy* tgba_to_convert, bdd atomic_propositions_set, bool artificial_initial_state_mode = true,
|
||||
bool artificial_livelock_accepting_state_mode = false);
|
||||
|
||||
void
|
||||
compute_livelock_acceptance_states(ta_explicit* testing_automata);
|
||||
|
||||
void compute_livelock_acceptance_states(ta_explicit* testing_automata);
|
||||
void
|
||||
add_artificial_livelock_accepting_state(ta_explicit* testing_automata,
|
||||
state_ta_explicit* artificial_livelock_accepting_state);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue