Commit 81e80e60 authored by Ala Eddine's avatar Ala Eddine Committed by Alexandre Duret-Lutz
Browse files

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
parent ba47b821
...@@ -25,8 +25,11 @@ tadir = $(pkgincludedir)/ta ...@@ -25,8 +25,11 @@ tadir = $(pkgincludedir)/ta
ta_HEADERS = \ ta_HEADERS = \
ta.hh \ ta.hh \
taproduct.hh \
taexplicit.hh taexplicit.hh
noinst_LTLIBRARIES = libta.la noinst_LTLIBRARIES = libta.la
libta_la_SOURCES = \ libta_la_SOURCES = \
ta.cc \
taproduct.cc \
taexplicit.cc taexplicit.cc
// Copyright (C) 2010 Laboratoire de Recherche et Developpement
// de l Epita (LRDE).
//
// 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 "ta.hh"
namespace spot
{
scc_stack_ta::connected_component::connected_component(int i)
{
index = i;
is_accepting = false;
}
scc_stack_ta::connected_component&
scc_stack_ta::top()
{
return s.front();
}
const scc_stack_ta::connected_component&
scc_stack_ta::top() const
{
return s.front();
}
void
scc_stack_ta::pop()
{
// assert(rem().empty());
s.pop_front();
}
void
scc_stack_ta::push(int index)
{
s.push_front(connected_component(index));
}
std::list<state*>&
scc_stack_ta::rem()
{
return top().rem;
}
size_t
scc_stack_ta::size() const
{
return s.size();
}
bool
scc_stack_ta::empty() const
{
return s.empty();
}
}
...@@ -46,29 +46,35 @@ namespace spot ...@@ -46,29 +46,35 @@ namespace spot
typedef std::set<state*, state_ptr_less_than> states_set_t; typedef std::set<state*, state_ptr_less_than> states_set_t;
virtual const states_set_t* virtual const states_set_t
get_initial_states_set() const = 0; get_initial_states_set() const = 0;
virtual ta_succ_iterator* virtual ta_succ_iterator*
succ_iter(const spot::state* s) const = 0; succ_iter(const spot::state* s) const = 0;
virtual ta_succ_iterator*
succ_iter(const spot::state* s, bdd condition) const = 0;
virtual bdd_dict* virtual bdd_dict*
get_dict() const = 0; get_dict() const = 0;
virtual std::string virtual std::string
format_state(const spot::state* s) const = 0; format_state(const spot::state* s) const = 0;
virtual bool virtual bool
is_accepting_state(const spot::state* s) const = 0; is_accepting_state(const spot::state* s) const = 0;
virtual bool virtual bool
is_livelock_accepting_state(const spot::state* s) const = 0; is_livelock_accepting_state(const spot::state* s) const = 0;
virtual bool virtual bool
is_initial_state(const spot::state* s) const = 0; is_initial_state(const spot::state* s) const = 0;
virtual bdd virtual bdd
get_state_condition(const spot::state* s) const = 0; get_state_condition(const spot::state* s) const = 0;
virtual void
free_state(const spot::state* s) const = 0;
}; };
...@@ -93,6 +99,8 @@ namespace spot ...@@ -93,6 +99,8 @@ namespace spot
virtual bdd virtual bdd
current_condition() const = 0; current_condition() const = 0;
virtual bool
is_stuttering_transition() const = 0;
bdd bdd
current_acceptance_conditions() const current_acceptance_conditions() const
...@@ -103,7 +111,7 @@ namespace spot ...@@ -103,7 +111,7 @@ namespace spot
}; };
// A stack of Strongly-Connected Components // A stack of Strongly-Connected Components
class sscc_stack class scc_stack_ta
{ {
public: public:
struct connected_component struct connected_component
...@@ -116,8 +124,6 @@ namespace spot ...@@ -116,8 +124,6 @@ namespace spot
bool is_accepting; bool is_accepting;
bool is_initial;
std::list<state*> rem; std::list<state*> rem;
}; };
......
...@@ -28,22 +28,31 @@ ...@@ -28,22 +28,31 @@
#include "tgba/bddprint.hh" #include "tgba/bddprint.hh"
namespace spot namespace spot
{ {
//////////////////////////////////////// ////////////////////////////////////////
// ta_explicit_succ_iterator // ta_explicit_succ_iterator
ta_explicit_succ_iterator::ta_explicit_succ_iterator(const state_ta_explicit* s) ta_explicit_succ_iterator::ta_explicit_succ_iterator(
const state_ta_explicit* s) :
source_(s)
{ {
transitions_ = s->get_transitions(); transitions_ = s->get_transitions();
} }
ta_explicit_succ_iterator::ta_explicit_succ_iterator(
const state_ta_explicit* s, bdd condition) :
source_(s)
{
transitions_ = s->get_transitions(condition);
}
void void
ta_explicit_succ_iterator::first() ta_explicit_succ_iterator::first()
{ {
i_ = transitions_->begin(); if (transitions_ != 0)
i_ = transitions_->begin();
} }
void void
...@@ -55,7 +64,7 @@ namespace spot ...@@ -55,7 +64,7 @@ namespace spot
bool bool
ta_explicit_succ_iterator::done() const ta_explicit_succ_iterator::done() const
{ {
return i_ == transitions_->end(); return transitions_ == 0 || i_ == transitions_->end();
} }
state* state*
...@@ -73,8 +82,11 @@ namespace spot ...@@ -73,8 +82,11 @@ namespace spot
return (*i_)->condition; return (*i_)->condition;
} }
bool
ta_explicit_succ_iterator::is_stuttering_transition() const
{
return source_->get_tgba_condition() == ((*i_)->dest)->get_tgba_condition();
}
//////////////////////////////////////// ////////////////////////////////////////
// state_ta_explicit // state_ta_explicit
...@@ -85,16 +97,44 @@ namespace spot ...@@ -85,16 +97,44 @@ namespace spot
return transitions_; return transitions_;
} }
// return transitions filtred by condition
state_ta_explicit::transitions*
state_ta_explicit::get_transitions(bdd condition) const
{
Sgi::hash_map<int, transitions*, Sgi::hash<int> >::const_iterator i =
transitions_by_condition.find(condition.id());
if (i == transitions_by_condition.end())
{
return 0;
}
else
{
return i->second;
}
}
void void
state_ta_explicit::add_transition(state_ta_explicit::transition* t){ state_ta_explicit::add_transition(state_ta_explicit::transition* t)
if(transitions_ == 0) {
transitions_= new transitions; if (transitions_ == 0)
transitions_ = new transitions;
transitions_->push_back(t); transitions_->push_back(t);
} transitions* transitions_condition = get_transitions(t->condition);
if (transitions_condition == 0)
{
transitions_condition = new transitions;
transitions_by_condition[(t->condition).id()] = transitions_condition;
}
transitions_condition->push_back(t);
}
const state* const state*
state_ta_explicit::get_tgba_state() const state_ta_explicit::get_tgba_state() const
...@@ -133,7 +173,8 @@ namespace spot ...@@ -133,7 +173,8 @@ namespace spot
} }
void void
state_ta_explicit::set_livelock_accepting_state(bool is_livelock_accepting_state) state_ta_explicit::set_livelock_accepting_state(
bool is_livelock_accepting_state)
{ {
is_livelock_accepting_state_ = is_livelock_accepting_state; is_livelock_accepting_state_ = is_livelock_accepting_state;
} }
...@@ -170,54 +211,71 @@ namespace spot ...@@ -170,54 +211,71 @@ namespace spot
return new state_ta_explicit(*this); return new state_ta_explicit(*this);
} }
sscc_stack::connected_component::connected_component(int i)
{
index = i;
is_accepting = false;
is_initial = false;
}
sscc_stack::connected_component&
sscc_stack::top()
{
return s.front();
}
const sscc_stack::connected_component&
sscc_stack::top() const
{
return s.front();
}
void
sscc_stack::pop()
{
// assert(rem().empty());
s.pop_front();
}
void void
sscc_stack::push(int index) state_ta_explicit::delete_stuttering_and_hole_successors()
{ {
s.push_front(connected_component(index)); state_ta_explicit::transitions* trans = 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;
bool is_stuttering_transition = (get_tgba_condition()
== (dest)->get_tgba_condition());
bool dest_is_livelock_accepting = dest->is_livelock_accepting_state();
//Before deleting stuttering transitions, propaged back livelock and initial state's properties
if (is_stuttering_transition)
{
if (dest_is_livelock_accepting)
set_livelock_accepting_state(true);
if (dest->is_initial_state())
set_initial_state(true);
}
//remove hole successors states
state_ta_explicit::transitions* dest_trans =
(dest)->get_transitions();
bool dest_trans_empty = dest_trans == 0 || dest_trans->empty();
if (is_stuttering_transition || (dest_trans_empty
&& (!dest_is_livelock_accepting)))
{
get_transitions((*it_trans)->condition)->remove(*it_trans);
delete (*it_trans);
it_trans = trans->erase(it_trans);
}
else
{
it_trans++;
}
}
std::list<state*>&
sscc_stack::rem()
{
return top().rem;
} }
size_t void
sscc_stack::size() const state_ta_explicit::free_transitions()
{ {
return s.size(); state_ta_explicit::transitions* trans = get_transitions();
} state_ta_explicit::transitions::iterator it_trans;
// We don't destroy the transitions in the state's destructor because
// they are not cloned.
if (trans != 0)
for (it_trans = trans->begin(); it_trans != trans->end(); it_trans++)
{
delete *it_trans;
}
delete trans;
delete get_tgba_state();
Sgi::hash_map<int, transitions*, Sgi::hash<int> >::iterator i =
transitions_by_condition.begin();
while (i != transitions_by_condition.end())
{
delete i->second;
++i;
}
bool
sscc_stack::empty() const
{
return s.empty();
} }
//////////////////////////////////////// ////////////////////////////////////////
...@@ -227,6 +285,7 @@ namespace spot ...@@ -227,6 +285,7 @@ namespace spot
ta_explicit::ta_explicit(const tgba* tgba_) : ta_explicit::ta_explicit(const tgba* tgba_) :
tgba_(tgba_) tgba_(tgba_)
{ {
get_dict()->register_all_variables_of(&tgba_, this);
} }
ta_explicit::~ta_explicit() ta_explicit::~ta_explicit()
...@@ -234,20 +293,13 @@ namespace spot ...@@ -234,20 +293,13 @@ namespace spot
ta::states_set_t::iterator it; ta::states_set_t::iterator it;
for (it = states_set_.begin(); it != states_set_.end(); it++) for (it = states_set_.begin(); it != states_set_.end(); it++)
{ {
const state_ta_explicit* s = dynamic_cast<const state_ta_explicit*> (*it); state_ta_explicit* s = dynamic_cast<state_ta_explicit*> (*it);
state_ta_explicit::transitions* trans = s->get_transitions();
state_ta_explicit::transitions::iterator it_trans; s->free_transitions();
// We don't destroy the transitions in the state's destructor because
// they are not cloned.
for (it_trans = trans->begin(); it_trans != trans->end(); it_trans++)
{
delete *it_trans;
}
delete trans;
delete s->get_tgba_state();
delete s; delete s;
} }
get_dict()->unregister_all_my_variables(this);
delete tgba_;
} }
state_ta_explicit* state_ta_explicit*
...@@ -256,24 +308,33 @@ namespace spot ...@@ -256,24 +308,33 @@ namespace spot
std::pair<ta::states_set_t::iterator, bool> add_state_to_ta = std::pair<ta::states_set_t::iterator, bool> add_state_to_ta =
states_set_.insert(s); states_set_.insert(s);
if (is_initial_state(*add_state_to_ta.first))
initial_states_set_.insert(*add_state_to_ta.first);
return dynamic_cast<state_ta_explicit*> (*add_state_to_ta.first); return dynamic_cast<state_ta_explicit*> (*add_state_to_ta.first);
} }
state_ta_explicit* void
ta_explicit::add_initial_state(state_ta_explicit* s) ta_explicit::add_to_initial_states_set(state* state)
{ {
state_ta_explicit * s = dynamic_cast<state_ta_explicit*> (state);
s->set_initial_state(true); s->set_initial_state(true);
return add_state(s); initial_states_set_.insert(s);
} }
void void
ta_explicit::create_transition(state_ta_explicit* source, bdd condition, state_ta_explicit* dest) ta_explicit::delete_stuttering_and_hole_successors(spot::state* s)
{
state_ta_explicit * state = dynamic_cast<state_ta_explicit*> (s);
state->delete_stuttering_and_hole_successors();
if (state->is_initial_state()) add_to_initial_states_set(state);
}
void
ta_explicit::create_transition(state_ta_explicit* source, bdd condition,
state_ta_explicit* dest)
{ {
state_ta_explicit::transition* t = new state_ta_explicit::transition; state_ta_explicit::transition* t = new state_ta_explicit::transition;
t->dest = dest; t->dest = dest;
...@@ -282,17 +343,18 @@ namespace spot ...@@ -282,17 +343,18 @@ namespace spot
} }
const ta::states_set_t* const ta::states_set_t
ta_explicit::get_initial_states_set() const ta_explicit::get_initial_states_set() const
{ {
return &initial_states_set_; return initial_states_set_;
} }
bdd bdd
ta_explicit::get_state_condition(const spot::state* initial_state) const ta_explicit::get_state_condition(const spot::state* initial_state) const
{ {
const state_ta_explicit* sta = dynamic_cast<const state_ta_explicit*> (initial_state); const state_ta_explicit* sta =
dynamic_cast<const state_ta_explicit*> (initial_state);
return sta->get_tgba_condition(); return sta->get_tgba_condition();
} }
...@@ -325,6 +387,14 @@ namespace spot ...@@ -325,6 +387,14 @@ namespace spot
return new ta_explicit_succ_iterator(s); return new ta_explicit_succ_iterator(s);
} }
ta_succ_iterator*
ta_explicit::succ_iter(const spot::state* state, bdd condition) const
{
const state_ta_explicit* s = dynamic_cast<const state_ta_explicit*> (state);
assert(s);
return new ta_explicit_succ_iterator(s, condition);
}
bdd_dict* bdd_dict*
ta_explicit::get_dict() const ta_explicit::get_dict() const
{ {
...@@ -342,6 +412,10 @@ namespace spot ...@@ -342,6 +412,10 @@ namespace spot
{ {
const state_ta_explicit* sta = dynamic_cast<const state_ta_explicit*> (s); const state_ta_explicit* sta = dynamic_cast<const state_ta_explicit*> (s);
assert(sta); assert(sta);
if (sta->get_tgba_condition() == bddtrue)
return tgba_->format_state(sta->get_tgba_state());
return tgba_->format_state(sta->get_tgba_state()) + "\n" return tgba_->format_state(sta->get_tgba_state()) + "\n"
+ bdd_format_formula(get_dict(), sta->get_tgba_condition()); + bdd_format_formula(get_dict(), sta->get_tgba_condition());