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

@ -25,8 +25,11 @@ tadir = $(pkgincludedir)/ta
ta_HEADERS = \
ta.hh \
taproduct.hh \
taexplicit.hh
noinst_LTLIBRARIES = libta.la
libta_la_SOURCES = \
ta.cc \
taproduct.cc \
taexplicit.cc

82
src/ta/ta.cc Normal file
View file

@ -0,0 +1,82 @@
// 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();
}
}

View file

@ -46,29 +46,35 @@ namespace spot
typedef std::set<state*, state_ptr_less_than> states_set_t;
virtual const states_set_t*
get_initial_states_set() const = 0;
virtual const states_set_t
get_initial_states_set() const = 0;
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*
get_dict() const = 0;
get_dict() const = 0;
virtual std::string
format_state(const spot::state* s) const = 0;
format_state(const spot::state* s) const = 0;
virtual bool
is_accepting_state(const spot::state* s) const = 0;
is_accepting_state(const spot::state* s) const = 0;
virtual bool
is_livelock_accepting_state(const spot::state* s) const = 0;
is_livelock_accepting_state(const spot::state* s) const = 0;
virtual bool
is_initial_state(const spot::state* s) const = 0;
is_initial_state(const spot::state* s) const = 0;
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
virtual bdd
current_condition() const = 0;
virtual bool
is_stuttering_transition() const = 0;
bdd
current_acceptance_conditions() const
@ -103,7 +111,7 @@ namespace spot
};
// A stack of Strongly-Connected Components
class sscc_stack
class scc_stack_ta
{
public:
struct connected_component
@ -116,8 +124,6 @@ namespace spot
bool is_accepting;
bool is_initial;
std::list<state*> rem;
};

View file

@ -28,22 +28,31 @@
#include "tgba/bddprint.hh"
namespace spot
{
////////////////////////////////////////
// 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();
}
ta_explicit_succ_iterator::ta_explicit_succ_iterator(
const state_ta_explicit* s, bdd condition) :
source_(s)
{
transitions_ = s->get_transitions(condition);
}
void
ta_explicit_succ_iterator::first()
{
i_ = transitions_->begin();
if (transitions_ != 0)
i_ = transitions_->begin();
}
void
@ -55,7 +64,7 @@ namespace spot
bool
ta_explicit_succ_iterator::done() const
{
return i_ == transitions_->end();
return transitions_ == 0 || i_ == transitions_->end();
}
state*
@ -73,8 +82,11 @@ namespace spot
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
@ -85,16 +97,44 @@ namespace spot
return transitions_;
}
// return transitions filtred by condition
state_ta_explicit::transitions*
state_ta_explicit::get_transitions(bdd condition) const
{
void
state_ta_explicit::add_transition(state_ta_explicit::transition* t){
if(transitions_ == 0)
transitions_= new transitions;
Sgi::hash_map<int, transitions*, Sgi::hash<int> >::const_iterator i =
transitions_by_condition.find(condition.id());
transitions_->push_back(t);
if (i == transitions_by_condition.end())
{
return 0;
}
else
{
return i->second;
}
}
void
state_ta_explicit::add_transition(state_ta_explicit::transition* t)
{
if (transitions_ == 0)
transitions_ = new transitions;
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*
state_ta_explicit::get_tgba_state() const
@ -133,7 +173,8 @@ namespace spot
}
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;
}
@ -170,54 +211,71 @@ namespace spot
return new state_ta_explicit(*this);
}
sscc_stack::connected_component::connected_component(int i)
void
state_ta_explicit::delete_stuttering_and_hole_successors()
{
index = i;
is_accepting = false;
is_initial = false;
}
state_ta_explicit::transitions* trans = get_transitions();
state_ta_explicit::transitions::iterator it_trans;
sscc_stack::connected_component&
sscc_stack::top()
{
return s.front();
}
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++;
}
}
const sscc_stack::connected_component&
sscc_stack::top() const
{
return s.front();
}
void
sscc_stack::pop()
state_ta_explicit::free_transitions()
{
// assert(rem().empty());
s.pop_front();
}
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();
void
sscc_stack::push(int index)
{
s.push_front(connected_component(index));
}
Sgi::hash_map<int, transitions*, Sgi::hash<int> >::iterator i =
transitions_by_condition.begin();
while (i != transitions_by_condition.end())
{
delete i->second;
++i;
}
std::list<state*>&
sscc_stack::rem()
{
return top().rem;
}
size_t
sscc_stack::size() const
{
return s.size();
}
bool
sscc_stack::empty() const
{
return s.empty();
}
////////////////////////////////////////
@ -227,6 +285,7 @@ namespace spot
ta_explicit::ta_explicit(const tgba* tgba_) :
tgba_(tgba_)
{
get_dict()->register_all_variables_of(&tgba_, this);
}
ta_explicit::~ta_explicit()
@ -234,20 +293,13 @@ namespace spot
ta::states_set_t::iterator 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::transitions* trans = s->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.
for (it_trans = trans->begin(); it_trans != trans->end(); it_trans++)
{
delete *it_trans;
}
delete trans;
delete s->get_tgba_state();
state_ta_explicit* s = dynamic_cast<state_ta_explicit*> (*it);
s->free_transitions();
delete s;
}
get_dict()->unregister_all_my_variables(this);
delete tgba_;
}
state_ta_explicit*
@ -256,24 +308,33 @@ namespace spot
std::pair<ta::states_set_t::iterator, bool> add_state_to_ta =
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);
}
state_ta_explicit*
ta_explicit::add_initial_state(state_ta_explicit* s)
void
ta_explicit::add_to_initial_states_set(state* state)
{
state_ta_explicit * s = dynamic_cast<state_ta_explicit*> (state);
s->set_initial_state(true);
return add_state(s);
initial_states_set_.insert(s);
}
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;
t->dest = dest;
@ -282,17 +343,18 @@ namespace spot
}
const ta::states_set_t*
const ta::states_set_t
ta_explicit::get_initial_states_set() const
{
return &initial_states_set_;
return initial_states_set_;
}
bdd
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();
}
@ -325,6 +387,14 @@ namespace spot
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*
ta_explicit::get_dict() const
{
@ -342,6 +412,10 @@ namespace spot
{
const state_ta_explicit* sta = dynamic_cast<const state_ta_explicit*> (s);
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"
+ bdd_format_formula(get_dict(), sta->get_tgba_condition());
@ -354,26 +428,33 @@ namespace spot
for (it = states_set_.begin(); it != states_set_.end(); it++)
{
const state_ta_explicit* source = dynamic_cast<const state_ta_explicit*> (*it);
const state_ta_explicit* source =
dynamic_cast<const state_ta_explicit*> (*it);
state_ta_explicit::transitions* trans = source->get_transitions();
state_ta_explicit::transitions::iterator it_trans;
for (it_trans = trans->begin(); it_trans != trans->end();)
{
if (source->get_tgba_condition()
== ((*it_trans)->dest)->get_tgba_condition())
{
delete *it_trans;
it_trans = trans->erase(it_trans);
}
else
{
it_trans++;
}
}
if (trans != 0)
for (it_trans = trans->begin(); it_trans != trans->end();)
{
if (source->get_tgba_condition()
== ((*it_trans)->dest)->get_tgba_condition())
{
delete *it_trans;
it_trans = trans->erase(it_trans);
}
else
{
it_trans++;
}
}
}
}
void
ta_explicit::free_state(const spot::state*) const
{
}
}

View file

@ -37,8 +37,6 @@ namespace spot
class ta_explicit_succ_iterator;
class ta_explicit;
/// ta_explicit explicit representa_explicittion of a Testing Automata_explicit
class ta_explicit : public ta
{
@ -51,23 +49,27 @@ namespace spot
state_ta_explicit*
add_state(state_ta_explicit* s);
state_ta_explicit*
add_initial_state(state_ta_explicit* s);
void
add_to_initial_states_set(state* s);
void
create_transition(state_ta_explicit* source, bdd condition, state_ta_explicit* dest);
create_transition(state_ta_explicit* source, bdd condition,
state_ta_explicit* dest);
void
delete_stuttering_transitions();
// ta interface
virtual
~ta_explicit();
virtual const states_set_t*
virtual const states_set_t
get_initial_states_set() const;
virtual ta_succ_iterator*
succ_iter(const spot::state* s) const;
virtual ta_succ_iterator*
succ_iter(const spot::state* s, bdd condition) const;
virtual bdd_dict*
get_dict() const;
@ -86,6 +88,12 @@ namespace spot
virtual bdd
get_state_condition(const spot::state* s) const;
virtual void
free_state(const spot::state* s) const;
virtual void
delete_stuttering_and_hole_successors(spot::state* s);
private:
// Disallow copy.
ta_explicit(const ta_explicit& other);
@ -137,6 +145,10 @@ namespace spot
transitions*
get_transitions() const;
// return transitions filtred by condition
transitions*
get_transitions(bdd condition) const;
void
add_transition(transition* t);
@ -156,6 +168,11 @@ namespace spot
is_initial_state() const;
void
set_initial_state(bool is_initial_state);
void
delete_stuttering_and_hole_successors();
void
free_transitions();
private:
const state* tgba_state_;
@ -164,6 +181,7 @@ namespace spot
bool is_accepting_state_;
bool is_livelock_accepting_state_;
transitions* transitions_;
Sgi::hash_map<int, transitions*, Sgi::hash<int> > transitions_by_condition;
};
@ -173,6 +191,8 @@ namespace spot
public:
ta_explicit_succ_iterator(const state_ta_explicit* s);
ta_explicit_succ_iterator(const state_ta_explicit* s, bdd condition);
virtual void
first();
virtual void
@ -185,11 +205,13 @@ namespace spot
virtual bdd
current_condition() const;
virtual bool
is_stuttering_transition() const;
private:
state_ta_explicit::transitions* transitions_;
state_ta_explicit::transitions::const_iterator i_;
const state_ta_explicit* source_;
};
}

346
src/ta/taproduct.cc Normal file
View file

@ -0,0 +1,346 @@
// Copykripke_structure (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 "taproduct.hh"
#include <cassert>
#include "misc/hashfunc.hh"
namespace spot
{
////////////////////////////////////////////////////////////
// state_ta_product
state_ta_product::state_ta_product(const state_ta_product& o) :
state(), ta_state_(o.get_ta_state()), kripke_state_(
o.get_kripke_state()->clone())
{
}
state_ta_product::~state_ta_product()
{
//see ta_product::free_state() method
delete kripke_state_;
}
int
state_ta_product::compare(const state* other) const
{
const state_ta_product* o = dynamic_cast<const state_ta_product*> (other);
assert(o);
int res = ta_state_->compare(o->get_ta_state());
if (res != 0)
return res;
return kripke_state_->compare(o->get_kripke_state());
}
size_t
state_ta_product::hash() const
{
// We assume that size_t is 32-bit wide.
return wang32_hash(ta_state_->hash()) ^ wang32_hash(kripke_state_->hash());
}
state_ta_product*
state_ta_product::clone() const
{
return new state_ta_product(*this);
}
////////////////////////////////////////////////////////////
// ta_succ_iterator_product
ta_succ_iterator_product::ta_succ_iterator_product(const state_ta_product* s,
const ta* t, const kripke* k) :
source_(s), ta_(t), kripke_(k)
{
kripke_succ_it_ = k->succ_iter(s->get_kripke_state());
current_state_ = 0;
}
ta_succ_iterator_product::~ta_succ_iterator_product()
{
// ta_->free_state(current_state_);
delete current_state_;
current_state_ = 0;
delete ta_succ_it_;
delete kripke_succ_it_;
}
void
ta_succ_iterator_product::step_()
{
if (!ta_succ_it_->done())
ta_succ_it_->next();
if (ta_succ_it_->done())
{
delete ta_succ_it_;
ta_succ_it_ = 0;
kripke_succ_it_->next();
}
}
void
ta_succ_iterator_product::first()
{
if (!kripke_succ_it_)
return;
ta_succ_it_ = 0;
kripke_succ_it_->first();
// If one of the two successor sets is empty initially, we reset
// kripke_succ_it_, so that done() can detect this situation easily. (We
// choose to reset kripke_succ_it_ because this variable is already used by
// done().)
if (kripke_succ_it_->done())
{
delete kripke_succ_it_;
kripke_succ_it_ = 0;
return;
}
next_non_stuttering_();
}
void
ta_succ_iterator_product::next()
{
delete current_state_;
current_state_ = 0;
if (is_stuttering_transition())
{
ta_succ_it_ = 0;
kripke_succ_it_->next();
}
else
step_();
if (!done())
next_non_stuttering_();
}
void
ta_succ_iterator_product::next_non_stuttering_()
{
bdd sc = kripke_->state_condition(source_->get_kripke_state());
while (!done())
{
state * kripke_succ_it_current_state = kripke_succ_it_->current_state();
bdd dc = kripke_->state_condition(kripke_succ_it_current_state);
is_stuttering_transition_ = (sc == dc);
if (is_stuttering_transition_)
{
//if stuttering transition, the TA automata stays in the same state
current_state_ = new state_ta_product(source_->get_ta_state(),
kripke_succ_it_current_state);
current_condition_ = bddtrue;
return;
}
if (ta_succ_it_ == 0){
current_condition_ = bdd_setxor(sc, dc);
ta_succ_it_ = ta_->succ_iter(source_->get_ta_state(), current_condition_);
ta_succ_it_->first();
}
if (!ta_succ_it_->done())
{
current_state_ = new state_ta_product(ta_succ_it_->current_state(),
kripke_succ_it_current_state);
return;
}
delete kripke_succ_it_current_state;
step_();
}
}
bool
ta_succ_iterator_product::done() const
{
return !kripke_succ_it_ || kripke_succ_it_->done();
}
state_ta_product*
ta_succ_iterator_product::current_state() const
{
//assert(!done());
//if stuttering transition, the TA automata stays in the same state
// if (is_stuttering_transition())
// return new state_ta_product(source_->get_ta_state(),
// kripke_succ_it_->current_state());
//
// return new state_ta_product(ta_succ_it_->current_state(),
// kripke_succ_it_->current_state());
return current_state_->clone();
}
bool
ta_succ_iterator_product::is_stuttering_transition() const
{
// assert(!done());
// bdd sc = kripke_->state_condition(source_->get_kripke_state());
// state * kripke_succ_it_current_state = kripke_succ_it_->current_state();
// bdd dc = kripke_->state_condition(kripke_succ_it_current_state);
// delete kripke_succ_it_current_state;
return is_stuttering_transition_;
}
bdd
ta_succ_iterator_product::current_condition() const
{
// assert(!done());
// bdd sc = kripke_->state_condition(source_->get_kripke_state());
// state * kripke_succ_it_current_state = kripke_succ_it_->current_state();
// bdd dc = kripke_->state_condition(kripke_succ_it_current_state);
// delete kripke_succ_it_current_state;
// return bdd_setxor(sc, dc);
return current_condition_;
}
////////////////////////////////////////////////////////////
// ta_product
ta_product::ta_product(const ta* testing_automata,
const kripke* kripke_structure) :
dict_(testing_automata->get_dict()), ta_(testing_automata), kripke_(
kripke_structure)
{
assert(dict_ == kripke_structure->get_dict());
dict_->register_all_variables_of(&ta_, this);
dict_->register_all_variables_of(&kripke_, this);
}
ta_product::~ta_product()
{
dict_->unregister_all_my_variables(this);
}
const ta::states_set_t
ta_product::get_initial_states_set() const
{
//build initial states set
const ta::states_set_t ta_init_states_set = ta_->get_initial_states_set();
ta::states_set_t::const_iterator it;
ta::states_set_t initial_states_set;
for (it = ta_init_states_set.begin(); it != ta_init_states_set.end(); it++)
{
state* kripke_init_state = kripke_->get_init_state();
if ((kripke_->state_condition(kripke_init_state))
== (ta_->get_state_condition(*it)))
{
state_ta_product* stp = new state_ta_product((*it),
kripke_init_state);
initial_states_set.insert(stp);
}
else
{
delete kripke_init_state;
}
}
return initial_states_set;
}
ta_succ_iterator_product*
ta_product::succ_iter(const state* s) const
{
const state_ta_product* stp = dynamic_cast<const state_ta_product*> (s);
assert(s);
return new ta_succ_iterator_product(stp, ta_, kripke_);
}
bdd_dict*
ta_product::get_dict() const
{
return dict_;
}
std::string
ta_product::format_state(const state* state) const
{
const state_ta_product* s = dynamic_cast<const state_ta_product*> (state);
assert(s);
return kripke_->format_state(s->get_kripke_state()) + " * \n"
+ ta_->format_state(s->get_ta_state());
}
bool
ta_product::is_accepting_state(const spot::state* s) const
{
const state_ta_product* stp = dynamic_cast<const state_ta_product*> (s);
return ta_->is_accepting_state(stp->get_ta_state());
}
bool
ta_product::is_livelock_accepting_state(const spot::state* s) const
{
const state_ta_product* stp = dynamic_cast<const state_ta_product*> (s);
return ta_->is_livelock_accepting_state(stp->get_ta_state());
}
bool
ta_product::is_initial_state(const spot::state* s) const
{
const state_ta_product* stp = dynamic_cast<const state_ta_product*> (s);
state* ta_s = stp->get_ta_state();
state* kr_s = stp->get_kripke_state();
return (ta_->is_initial_state(ta_s))
&& ((kripke_->get_init_state())->compare(kr_s) == 0)
&& ((kripke_->state_condition(kr_s))
== (ta_->get_state_condition(ta_s)));
}
bdd
ta_product::get_state_condition(const spot::state* s) const
{
const state_ta_product* stp = dynamic_cast<const state_ta_product*> (s);
state* ta_s = stp->get_ta_state();
return ta_->get_state_condition(ta_s);
}
void
ta_product::free_state(const spot::state* s) const
{
const state_ta_product* stp = dynamic_cast<const state_ta_product*> (s);
ta_->free_state(stp->get_ta_state());
delete stp;
}
}

180
src/ta/taproduct.hh Normal file
View file

@ -0,0 +1,180 @@
// 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.
#ifndef SPOT_TA_TAPRODUCT_HH
# define SPOT_TA_TAPRODUCT_HH
#include "ta.hh"
#include "kripke/kripke.hh"
namespace spot
{
/// \brief A state for spot::ta_product.
///
/// This state is in fact a pair of state: the state from the ta
/// automaton and that of Kripke structure.
class state_ta_product : public state
{
public:
/// \brief Constructor
/// \param ta_state The state from the ta automaton.
/// \param kripke_state_ The state from Kripke structure.
state_ta_product(state* ta_state, state* kripke_state) :
ta_state_(ta_state), kripke_state_(kripke_state)
{
}
/// Copy constructor
state_ta_product(const state_ta_product& o);
virtual
~state_ta_product();
state*
get_ta_state() const
{
return ta_state_;
}
state*
get_kripke_state() const
{
return kripke_state_;
}
virtual int
compare(const state* other) const;
virtual size_t
hash() const;
virtual state_ta_product*
clone() const;
private:
state* ta_state_; ///< State from the ta automaton.
state* kripke_state_; ///< State from the kripke structure.
};
/// \brief Iterate over the successors of a product computed on the fly.
class ta_succ_iterator_product : public ta_succ_iterator
{
public:
ta_succ_iterator_product(const state_ta_product* s, const ta* t, const kripke* k);
virtual
~ta_succ_iterator_product();
// iteration
void
first();
void
next();
bool
done() const;
// inspection
state_ta_product*
current_state() const;
bdd
current_condition() const;
bool
is_stuttering_transition() const;
private:
//@{
/// Internal routines to advance to the next successor.
void
step_();
void
next_non_stuttering_();
//@}
protected:
const state_ta_product* source_;
const ta* ta_;
const kripke* kripke_;
ta_succ_iterator* ta_succ_it_;
tgba_succ_iterator* kripke_succ_it_;
state_ta_product* current_state_;
bdd current_condition_;
bool is_stuttering_transition_;
};
/// \brief A lazy product. (States are computed on the fly.)
class ta_product : public ta
{
public:
ta_product(const ta* testing_automata, const kripke* kripke_structure);
virtual
~ta_product();
virtual const states_set_t
get_initial_states_set() const;
virtual ta_succ_iterator_product*
succ_iter(const spot::state* s) const;
virtual ta_succ_iterator_product*
succ_iter(const spot::state* s, bdd condition) const {
if(condition == bddtrue) return succ_iter(s);
//TODO
return 0;
}
virtual bdd_dict*
get_dict() const;
virtual std::string
format_state(const spot::state* s) const;
virtual bool
is_accepting_state(const spot::state* s) const;
virtual bool
is_livelock_accepting_state(const spot::state* s) const;
virtual bool
is_initial_state(const spot::state* s) const;
virtual bdd
get_state_condition(const spot::state* s) const;
virtual void
free_state(const spot::state* s) const;
private:
bdd_dict* dict_;
const ta* ta_;
const kripke* kripke_;
// Disallow copy.
ta_product(const ta_product&);
ta_product&
operator=(const ta_product&);
};
}
#endif // SPOT_TA_TAPRODUCT_HH