Add Testing Automata Product & Emptiness Check

* src/taalgos/stats.hh, src/taalgos/stats.cc: Compute statistics for a
automaton.
* src/ta/ta.hh, src/ta/ta.cc: Abstract representation of a Testing
Automata(TA)
* src/ta/taexplicit.hh, src/ta/taexplicit.cc: Explicit representation of
a Testing Automata (TA)
* src/taalgos/dotty.cc: Print a TA in dot format.
* src/taalgos/reachiter.hh, src/taalgos/reachiter.cc: Iterate over all
reachable states of a TA
* src/taalgos/sba2ta.cc: implements the construction of a TA from a BA
(Buchi Automata)
* src/tgbatest/ltl2tgba.cc: add commands to test the TA implementation
* src/taalgos/emptinessta.hh, src/taalgos/emptinessta.cc: implementation
 of the TA emptiness-check algorithm
* src/ta/taproduct.hh, src/ta/taproduct.cc: representation of the
product (automaton) between a TA and a Kripke structure.
* src/ta/Makefile.am, src/taalgos/Makefile.am: add them
This commit is contained in:
Ala Eddine 2011-02-11 11:40:21 +01:00 committed by Alexandre Duret-Lutz
parent ba47b821c6
commit 81e80e6069
17 changed files with 1779 additions and 209 deletions

View file

@ -27,11 +27,14 @@ taalgosdir = $(pkgincludedir)/taalgos
taalgos_HEADERS = \
sba2ta.hh \
dotty.hh \
reachiter.hh
reachiter.hh \
stats.hh \
emptinessta.hh
noinst_LTLIBRARIES = libtaalgos.la
libtaalgos_la_SOURCES = \
sba2ta.cc \
dotty.cc \
reachiter.cc
reachiter.cc \
stats.cc \
emptinessta.cc

View file

@ -43,11 +43,11 @@ namespace spot
os_ << "digraph G {" << std::endl;
int n = 0;
const ta::states_set_t* init_states_set =
const ta::states_set_t init_states_set =
t_automata_->get_initial_states_set();
ta::states_set_t::const_iterator it;
for (it = (init_states_set->begin()); it != init_states_set->end(); it++)
for (it = (init_states_set.begin()); it != init_states_set.end(); it++)
{
// cout << (*it).first << " => " << (*it).second << endl;
@ -99,7 +99,7 @@ namespace spot
}
void
process_link(int in, int out, const tgba_succ_iterator* si)
process_link(int in, int out, const ta_succ_iterator* si)
{
os_ << " " << in << " -> " << out << " [label=\"";

619
src/taalgos/emptinessta.cc Normal file
View file

@ -0,0 +1,619 @@
// Copyright (C) 2008 Laboratoire de Recherche et Développement
// de l'Epita (LRDE).
// Copyright (C) 2003, 2004, 2005, 2006 Laboratoire d'Informatique de
// Paris 6 (LIP6), département Systèmes Répartis Coopératifs (SRC),
// Université Pierre et Marie Curie.
//
// This file is part of Spot, a model checking library.
//
// Spot is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// Spot is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
// License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Spot; see the file COPYING. If not, write to the Free
// Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
// #define TRACE
#include <iostream>
#ifdef TRACE
#define trace std::clog
#else
#define trace while (0) std::clog
#endif
#include "emptinessta.hh"
#include "misc/memusage.hh"
#include <math.h>
namespace spot
{
ta_check::ta_check(const ta* a, option_map o) :
a_(a), o_(o)
{
is_full_2_pass_ = o.get("is_full_2_pass", 0);
}
ta_check::~ta_check()
{
}
bool
ta_check::check()
{
// We use five main data in this algorithm:
// * 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 = 1;
// * todo: the depth-first search stack. This holds pairs of the
// form (STATE, ITERATOR) where ITERATOR is a ta_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<spot::state*> init_set;
Sgi::hash_map<const state*, std::string, state_ptr_hash, state_ptr_equal>
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;
std::stack<spot::state*> livelock_roots;
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;
}
while (!init_set.empty())
{
// Setup depth-first search from initial states.
{
state* init = dynamic_cast<state*> (init_set.top());
init_set.pop();
numbered_state_heap::state_index_p h_init = h->find(init);
if (h_init.first)
continue;
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();
//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;
// 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;
// fill rem with any component removed,
numbered_state_heap::state_index_p spi =
h->index(curr->clone());
assert(spi.first);
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);
// Backtrack livelock_roots.
if (!livelock_roots.empty() && !livelock_roots.top()->compare(
curr))
livelock_roots.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;
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;
}
dec_depth(scc.rem().size());
scc.pop();
}
delete succ;
// Do not delete CURR: it is a key in H.
continue;
}
// 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();
//may be Buchi accepting scc
scc.top().is_accepting = a_->is_accepting_state(curr)
&& !succ->is_stuttering_transition();
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.
// Are we going to a new state?
numbered_state_heap::state_index_p spi = h->find(dest);
// 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);
ta_succ_iterator* iter = a_->succ_iter(dest);
iter->first();
todo.push(pair_state_iter(dest, iter));
//colour[dest] = GREY;
inc_depth();
//push potential root of live-lock accepting cycle
if (a_->is_livelock_accepting_state(dest)
&& !is_stuttering_transition)
livelock_roots.push(dest);
continue;
}
// If we have reached a dead component, ignore it.
if (*spi.second == -1)
continue;
// 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;
while (threshold < scc.top().index)
{
assert(!scc.empty());
acc |= scc.top().is_accepting;
rem.splice(rem.end(), scc.rem());
scc.pop();
}
// 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.
// Accumulate all acceptance conditions into the merged SSCC.
scc.top().is_accepting |= acc;
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;
}
//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> 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);
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)
{
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;
}
liveset_curr.insert(u);
}
return false;
}
bool
ta_check::livelock_detection(const ta* t)
{
// We use five main data in this algorithm:
// * sscc: a stack of strongly stuttering-connected components (SSCC)
// * 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,
trace
<< "PASS 2" << std::endl;
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<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);
}
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);
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();
}
while (!todo.empty())
{
state* curr = todo.top().first;
// 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 2 : backtrack" << std::endl;
// 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();
// 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();
}
delete succ;
// Do not delete CURR: it is a key in H.
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();
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);
// Is this a new state?
if (!spi.first)
{
// Are we going to a new state through a stuttering transition?
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);
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;
//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;
}
}
// 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());
acc |= sscc.top().is_accepting;
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.
// 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;
}
}
}
clear(h, todo, init_set);
return false;
}
void
ta_check::clear(numbered_state_heap* h, std::stack<pair_state_iter> todo,
std::stack<spot::state*> init_states)
{
set_states(states() + h->size());
while (!init_states.empty())
{
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 h;
}
std::ostream&
ta_check::print_stats(std::ostream& os) const
{
// ecs_->print_stats(os);
os << states() << " unique states visited" << std::endl;
//TODO sscc;
os << scc.size() << " strongly connected components in search stack"
<< std::endl;
os << transitions() << " transitions explored" << std::endl;
os << max_depth() << " items max in DFS search stack" << std::endl;
return os;
}
//////////////////////////////////////////////////////////////////////
}

View file

@ -0,0 +1,94 @@
// Copyright (C) 2008 Laboratoire de Recherche et Development de
// l'Epita (LRDE).
// Copyright (C) 2003, 2004, 2005, 2006 Laboratoire d'Informatique de
// Paris 6 (LIP6), département Systèmes Répartis Coopératifs (SRC),
// Université Pierre et Marie Curie.
//
// This file is part of Spot, a model checking library.
//
// Spot is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// Spot is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
// License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Spot; see the file COPYING. If not, write to the Free
// Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
#ifndef SPOT_TAALGOS_EMPTINESS_HH
# define SPOT_TAALGOS_EMPTINESS_HH
#include "ta/ta.hh"
#include "misc/optionmap.hh"
#include "tgbaalgos/gtec/nsheap.hh"
#include "tgbaalgos/emptiness_stats.hh"
#include <stack>
namespace spot
{
namespace
{
typedef std::pair<spot::state*, ta_succ_iterator*> pair_state_iter;
}
/// \brief An implementation of the ta emptiness-check algorithm.
///
/// See the documentation for spot::ta.
class ta_check : public ec_statistics
{
public:
ta_check(const ta* a, option_map o = option_map());
virtual
~ta_check();
/// Check whether the automaton's language is empty.
virtual bool
check();
virtual bool
livelock_detection(const ta* t);
virtual std::ostream&
print_stats(std::ostream& os) const;
/// \brief Return the status of the emptiness-check.
///
/// When check() succeed, the status should be passed along
/// to spot::counter_example.
///
/// This status should not be deleted, it is a pointer
/// to a member of this class that will be deleted when
/// the ta object is deleted.
// const tgba_check_status* result() const;
protected:
void
clear(numbered_state_heap* h, std::stack<pair_state_iter> todo, std::stack<
spot::state*> init_set);
bool
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.
option_map o_; ///< The options
bool is_full_2_pass_;
// * scc: a stack of strongly connected components (SCC)
scc_stack_ta scc;
// * sscc: a stack of strongly stuttering-connected components (SSCC)
scc_stack_ta sscc;
};
/// @}
}
#endif // SPOT_TAALGOS_EMPTINESS_HH

View file

@ -42,7 +42,7 @@ namespace spot
// Advance the iterator before deleting the "key" pointer.
const state* ptr = s->first;
++s;
delete ptr;
t_automata_->free_state(ptr);
}
}
@ -51,13 +51,13 @@ namespace spot
{
int n = 0;
start();
const ta::states_set_t* init_states_set =
const ta::states_set_t init_states_set =
t_automata_->get_initial_states_set();
ta::states_set_t::const_iterator it;
for (it = init_states_set->begin(); it != init_states_set->end(); it++)
for (it = init_states_set.begin(); it != init_states_set.end(); it++)
{
state* init_state = (*it)->clone();
state* init_state = (*it);
if (want_state(init_state))
add_state(init_state);
seen[init_state] = ++n;
@ -69,11 +69,11 @@ namespace spot
{
assert(seen.find(t) != seen.end());
int tn = seen[t];
tgba_succ_iterator* si = t_automata_->succ_iter(t);
ta_succ_iterator* si = t_automata_->succ_iter(t);
process_state(t, tn);
for (si->first(); !si->done(); si->next())
{
const state* current = si->current_state()->clone();
const state* current = si->current_state();
seen_map::const_iterator s = seen.find(current);
bool ws = want_state(current);
if (s == seen.end())
@ -89,7 +89,7 @@ namespace spot
{
if (ws)
process_link(tn, s->second, si);
delete current;
t_automata_->free_state(current);
}
}
delete si;
@ -119,7 +119,7 @@ namespace spot
}
void
ta_reachable_iterator::process_link(int, int, const tgba_succ_iterator*)
ta_reachable_iterator::process_link(int, int, const ta_succ_iterator*)
{
}

View file

@ -92,7 +92,7 @@ namespace spot
/// spot::ta_reachable_iterator instance and destroyed when the
/// instance is destroyed.
virtual void
process_link(int in, int out, const tgba_succ_iterator* si);
process_link(int in, int out, const ta_succ_iterator* si);
protected:

View file

@ -30,7 +30,6 @@
#include <stack>
#include "sba2ta.hh"
using namespace std;
namespace spot
@ -42,26 +41,32 @@ namespace spot
ta_explicit* ta = new spot::ta_explicit(tgba_);
// build I set:
bdd init_condition;
bdd all_props = bddtrue;
ta::states_set_t todo;
std::stack<state_ta_explicit*> todo;
while ((init_condition = bdd_satoneset(all_props, atomic_propositions_set_,
bddtrue)) != bddfalse)
// build Initial states set:
state* tgba_init_state = tgba_->get_init_state();
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)
{
all_props -= init_condition;
state_ta_explicit* init_state = new state_ta_explicit((tgba_->get_init_state()),
init_condition, true);
ta->add_initial_state(init_state);
todo.insert(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* is = ta->add_state(init_state);
assert(is == init_state);
ta->add_to_initial_states_set(is);
todo.push(init_state);
}
delete tgba_init_state;
while (!todo.empty())
{
ta::states_set_t::iterator todo_it = todo.begin();
state_ta_explicit* source = dynamic_cast<state_ta_explicit*> (*todo_it);
todo.erase(todo_it);
state_ta_explicit* source = todo.top();
todo.pop();
tgba_succ_iterator* tgba_succ_it = tgba_->succ_iter(
source->get_tgba_state());
@ -75,26 +80,35 @@ namespace spot
{
tgba_condition -= satone_tgba_condition;
state_ta_explicit* new_dest = new state_ta_explicit(tgba_state->clone(),
satone_tgba_condition, false, tgba_->state_is_accepting(
tgba_state));
state_ta_explicit* dest = ta->add_state(new_dest);
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));
if (dest != new_dest)
{
// the state dest already exists in the testing automata
delete new_dest->get_tgba_state();
delete new_dest;
}
else
{
todo.insert(dest);
}
state_ta_explicit* dest = ta->add_state(new_dest);
ta->create_transition(source, bdd_setxor(
source->get_tgba_condition(), dest->get_tgba_condition()),
dest);
if (dest != new_dest)
{
// the state dest already exists in the testing automata
delete new_dest->get_tgba_state();
delete new_dest;
}
else
{
todo.push(dest);
}
ta->create_transition(source, bdd_setxor(
source->get_tgba_condition(),
dest->get_tgba_condition()), dest);
}
}
delete tgba_state;
@ -105,8 +119,6 @@ namespace spot
compute_livelock_acceptance_states(ta);
ta->delete_stuttering_transitions();
return ta;
}
@ -121,7 +133,7 @@ namespace spot
{
// We use five main data in this algorithm:
// * sscc: a stack of strongly stuttering-connected components (SSCC)
sscc_stack sscc;
scc_stack_ta sscc;
// * h: a hash of all visited nodes, with their order,
// (it is called "Hash" in Couvreur's paper)
@ -140,23 +152,24 @@ namespace spot
std::stack<pair_state_iter> todo;
// * init: the set of the depth-first search initial states
ta::states_set_t init_set;
std::stack<state*> init_set;
ta::states_set_t::const_iterator it;
for (it = (testing_automata->get_initial_states_set())->begin(); it != (testing_automata->get_initial_states_set())->end(); 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.insert(init_state);
state* init_state = dynamic_cast<state_ta_explicit*> (*it);
init_set.push(init_state);
}
while (!init_set.empty())
{
// Setup depth-first search from an initial state.
// Setup depth-first search from initial states.
{
ta::states_set_t::iterator init_set_it = init_set.begin();
state_ta_explicit* init = dynamic_cast<state_ta_explicit*> (*init_set_it);
init_set.erase(init_set_it);
state_ta_explicit* init =
dynamic_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);
@ -165,8 +178,8 @@ namespace spot
h->insert(init_clone, ++num);
sscc.push(num);
sscc.top().is_accepting = testing_automata->is_accepting_state(init);
sscc.top().is_initial = testing_automata->is_initial_state(init);
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));
@ -176,11 +189,19 @@ namespace spot
while (!todo.empty())
{
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;
}
// We are looking at the next successor in SUCC.
tgba_succ_iterator* succ = todo.top().second;
state* curr = todo.top().first;
// If there is no more successor, backtrack.
if (succ->done())
{
@ -190,7 +211,8 @@ namespace spot
todo.pop();
// fill rem with any component removed,
numbered_state_heap::state_index_p spi = h->index(curr->clone());
numbered_state_heap::state_index_p spi =
h->index(curr->clone());
assert(spi.first);
sscc.rem().push_front(curr);
@ -207,8 +229,9 @@ namespace spot
&& (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);
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)
@ -223,34 +246,14 @@ namespace spot
}
if (sscc.top().is_initial)
{//if it is an initial sscc
//add the state to I (=the initial states set)
state_ta_explicit * initial_state =
dynamic_cast<state_ta_explicit*> (*i);
testing_automata->add_initial_state(initial_state);
}
}
is_livelock_accepting_sscc = testing_automata->is_livelock_accepting_state(
*sscc.rem().begin());
sscc.pop();
if (is_livelock_accepting_sscc && !sscc.empty())
{
sscc.top().is_accepting = true;
state_ta_explicit * livelock_accepting_state =
dynamic_cast<state_ta_explicit*> (todo.top().first);
livelock_accepting_state->set_livelock_accepting_state(
true);
}
if (sscc.top().is_initial && !sscc.empty())
sscc.top().is_initial = true;
}
// automata reduction
testing_automata->delete_stuttering_and_hole_successors(curr);
delete succ;
// Do not delete CURR: it is a key in H.
continue;
@ -266,17 +269,18 @@ namespace spot
// 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);
bool is_stuttering_transition =
testing_automata->get_state_condition(curr)
== testing_automata->get_state_condition(dest);
state* dest_clone = dest->clone();
numbered_state_heap::state_index_p spi = h->find(dest_clone);
spi = h->find(dest_clone);
// Is this a new state?
if (!spi.first)
{
if (!is_stuttering_transition)
{
init_set.insert(dest);
init_set.push(dest);
delete dest_clone;
continue;
}
@ -285,8 +289,9 @@ namespace spot
// for later processing.
h->insert(dest_clone, ++num);
sscc.push(num);
sscc.top().is_accepting = testing_automata->is_accepting_state(dest);
sscc.top().is_initial = testing_automata->is_initial_state(dest);
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));
@ -299,7 +304,8 @@ namespace spot
if (!curr->compare(dest))
{
state_ta_explicit * self_loop_state = dynamic_cast<state_ta_explicit*> (curr);
state_ta_explicit * self_loop_state =
dynamic_cast<state_ta_explicit*> (curr);
if (testing_automata->is_accepting_state(self_loop_state))
self_loop_state->set_livelock_accepting_state(true);
@ -320,13 +326,12 @@ namespace spot
int threshold = *spi.second;
std::list<state*> rem;
bool acc = false;
bool init = false;
while (threshold < sscc.top().index)
{
assert(!sscc.empty());
acc |= sscc.top().is_accepting;
init |= sscc.top().is_initial;
rem.splice(rem.end(), sscc.rem());
sscc.pop();
@ -339,7 +344,6 @@ namespace spot
// Accumulate all acceptance conditions into the merged SSCC.
sscc.top().is_accepting |= acc;
sscc.top().is_initial |= init;
sscc.rem().splice(sscc.rem().end(), rem);

79
src/taalgos/stats.cc Normal file
View file

@ -0,0 +1,79 @@
// Copyright (C) 2008 Laboratoire de Recherche et Développement
// de l'Epita (LRDE).
// Copyright (C) 2004 Laboratoire d'Informatique de Paris 6 (LIP6),
// département Systèmes Répartis Coopératifs (SRC), Université Pierre
// et Marie Curie.
//
// This file is part of Spot, a model checking library.
//
// Spot is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// Spot is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
// License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Spot; see the file COPYING. If not, write to the Free
// Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
#include <iostream>
#include "ta/ta.hh"
#include "stats.hh"
#include "reachiter.hh"
namespace spot
{
namespace
{
class stats_bfs : public ta_reachable_iterator_breadth_first
{
public:
stats_bfs(const ta* a, ta_statistics& s) :
ta_reachable_iterator_breadth_first(a), s_(s)
{
}
void
process_state(const state* s, int)
{
++s_.states;
if (t_automata_->is_accepting_state(s)
|| t_automata_->is_livelock_accepting_state(s))
++s_.acceptance_states;
}
void
process_link(int, int, const ta_succ_iterator*)
{
++s_.transitions;
}
private:
ta_statistics& s_;
};
} // anonymous
std::ostream&
ta_statistics::dump(std::ostream& out) const
{
out << "transitions: " << transitions << std::endl;
out << "states: " << states << std::endl;
return out;
}
ta_statistics
stats_reachable(const ta* t)
{
ta_statistics s =
{ 0, 0, 0};
stats_bfs d(t, s);
d.run();
return s;
}
}

51
src/taalgos/stats.hh Normal file
View file

@ -0,0 +1,51 @@
// Copyright (C) 2008 Laboratoire de Recherche et Développement
// de l'Epita (LRDE).
// Copyright (C) 2004 Laboratoire d'Informatique de Paris 6 (LIP6),
// département Systèmes Répartis Coopératifs (SRC), Université Pierre
// et Marie Curie.
//
// This file is part of Spot, a model checking library.
//
// Spot is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// Spot is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
// License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Spot; see the file COPYING. If not, write to the Free
// Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
#ifndef SPOT_TAALGOS_STATS_HH
# define SPOT_TAALGOS_STATS_HH
#include "ta/ta.hh"
#include <iosfwd>
namespace spot
{
/// \addtogroup ta_misc
/// @{
struct ta_statistics
{
unsigned transitions;
unsigned states;
unsigned acceptance_states;
std::ostream& dump(std::ostream& out) const;
};
/// \brief Compute statistics for an automaton.
ta_statistics stats_reachable(const ta* t);
/// @}
}
#endif // SPOT_TAALGOS_STATS_HH