Commit 782ba001 authored by Ala-Eddine Ben-Salem's avatar Ala-Eddine Ben-Salem Committed by Alexandre Duret-Lutz
Browse files

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).
parent 310973f8
......@@ -19,62 +19,64 @@
// 02111-1307, USA.
#include "ta.hh"
namespace spot
{
spot::state*
ta::get_artificial_initial_state() const
{
return 0;
}
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();
}
{
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();
}
}
......@@ -49,6 +49,9 @@ namespace spot
virtual const states_set_t
get_initial_states_set() const = 0;
virtual spot::state*
get_artificial_initial_state() const = 0;
virtual ta_succ_iterator*
succ_iter(const spot::state* s) const = 0;
......@@ -67,6 +70,7 @@ namespace spot
virtual bool
is_livelock_accepting_state(const spot::state* s) const = 0;
virtual bool
is_initial_state(const spot::state* s) const = 0;
......
......@@ -64,7 +64,8 @@ namespace spot
bool
ta_explicit_succ_iterator::done() const
{
return transitions_ == 0 || i_ == transitions_->end();
return transitions_ == 0 || transitions_->empty() || i_
== transitions_->end();
}
state*
......@@ -103,15 +104,15 @@ namespace spot
{
Sgi::hash_map<int, transitions*, Sgi::hash<int> >::const_iterator i =
transitions_by_condition.find(condition.id());
transitions_by_condition.find(condition.id());
if (i == transitions_by_condition.end())
{
return 0;
return 0;
}
else
{
return i->second;
return i->second;
}
}
......@@ -122,17 +123,32 @@ namespace spot
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 = new transitions;
transitions_by_condition[(t->condition).id()] = transitions_condition;
}
state_ta_explicit::transitions::iterator it_trans;
bool transition_found = false;
for (it_trans = transitions_condition->begin(); (it_trans
!= transitions_condition->end() && !transition_found); it_trans++)
{
transition_found = ((*it_trans)->dest == t->dest);
}
transitions_condition->push_back(t);
if (!transition_found)
{
transitions_condition->push_back(t);
transitions_->push_back(t);
}
else
{
delete t;
}
}
......@@ -185,6 +201,13 @@ namespace spot
is_initial_state_ = is_initial_state;
}
bool
state_ta_explicit::is_hole_state() const
{
state_ta_explicit::transitions* trans = get_transitions();
return trans == 0 || trans->empty();
}
int
state_ta_explicit::compare(const spot::state* other) const
{
......@@ -196,7 +219,16 @@ namespace spot
if (compare_value != 0)
return compare_value;
return tgba_condition_.id() - o->tgba_condition_.id();
compare_value = tgba_condition_.id() - o->tgba_condition_.id();
// if (compare_value != 0)
// return compare_value;
//
// //unique artificial_livelock_accepting_state
// if (o->is_the_artificial_livelock_accepting_state())
// return is_the_artificial_livelock_accepting_state();
return compare_value;
}
size_t
......@@ -219,37 +251,37 @@ namespace spot
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++;
}
}
{
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++;
}
}
}
......@@ -262,18 +294,17 @@ namespace spot
// they are not cloned.
if (trans != 0)
for (it_trans = trans->begin(); it_trans != trans->end(); it_trans++)
{
delete *it_trans;
}
{
delete *it_trans;
}
delete trans;
get_tgba_state()->destroy();
Sgi::hash_map<int, transitions*, Sgi::hash<int> >::iterator i =
transitions_by_condition.begin();
transitions_by_condition.begin();
while (i != transitions_by_condition.end())
{
delete i->second;
++i;
delete i->second;
++i;
}
}
......@@ -282,10 +313,17 @@ namespace spot
// ta_explicit
ta_explicit::ta_explicit(const tgba* tgba_) :
tgba_(tgba_)
ta_explicit::ta_explicit(const tgba* tgba_,
state_ta_explicit* artificial_initial_state) :
tgba_(tgba_), artificial_initial_state_(artificial_initial_state)
{
get_dict()->register_all_variables_of(&tgba_, this);
if (artificial_initial_state != 0)
{
state_ta_explicit* is = add_state(artificial_initial_state);
assert(is == artificial_initial_state);
}
}
ta_explicit::~ta_explicit()
......@@ -293,10 +331,11 @@ namespace spot
ta::states_set_t::iterator it;
for (it = states_set_.begin(); it != states_set_.end(); it++)
{
state_ta_explicit* s = down_cast<state_ta_explicit*> (*it);
state_ta_explicit* s = down_cast<state_ta_explicit*> (*it);
s->free_transitions();
delete s;
s->free_transitions();
s->get_tgba_state()->destroy();
delete s;
}
get_dict()->unregister_all_my_variables(this);
delete tgba_;
......@@ -306,20 +345,26 @@ namespace spot
ta_explicit::add_state(state_ta_explicit* s)
{
std::pair<ta::states_set_t::iterator, bool> add_state_to_ta =
states_set_.insert(s);
states_set_.insert(s);
return static_cast<state_ta_explicit*> (*add_state_to_ta.first);
}
void
ta_explicit::add_to_initial_states_set(state* state)
ta_explicit::add_to_initial_states_set(state* state, bdd condition)
{
state_ta_explicit * s = down_cast<state_ta_explicit*> (state);
assert(s);
s->set_initial_state(true);
initial_states_set_.insert(s);
if (condition == bddfalse)
condition = get_state_condition(s);
std::pair<ta::states_set_t::iterator, bool> add_state =
initial_states_set_.insert(s);
if (get_artificial_initial_state() != 0)
if (add_state.second)
create_transition((state_ta_explicit*) get_artificial_initial_state(),
condition, s);
}
......@@ -329,7 +374,8 @@ namespace spot
state_ta_explicit * state = down_cast<state_ta_explicit*> (s);
assert(state);
state->delete_stuttering_and_hole_successors();
if (state->is_initial_state()) add_to_initial_states_set(state);
if (state->is_initial_state())
add_to_initial_states_set(state);
}
......@@ -355,7 +401,7 @@ namespace spot
ta_explicit::get_state_condition(const spot::state* initial_state) const
{
const state_ta_explicit* sta =
down_cast<const state_ta_explicit*> (initial_state);
down_cast<const state_ta_explicit*> (initial_state);
assert(sta);
return sta->get_tgba_condition();
}
......@@ -422,7 +468,7 @@ namespace spot
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());
+ bdd_format_formula(get_dict(), sta->get_tgba_condition());
}
......@@ -433,26 +479,26 @@ namespace spot
for (it = states_set_.begin(); it != states_set_.end(); it++)
{
const state_ta_explicit* source =
static_cast<const state_ta_explicit*> (*it);
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();)
{
if (source->get_tgba_condition()
== ((*it_trans)->dest)->get_tgba_condition())
{
delete *it_trans;
it_trans = trans->erase(it_trans);
}
else
{
it_trans++;
}
}
const state_ta_explicit* source =
static_cast<const state_ta_explicit*> (*it);
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();)
{
if (source->get_tgba_condition()
== ((*it_trans)->dest)->get_tgba_condition())
{
delete *it_trans;
it_trans = trans->erase(it_trans);
}
else
{
it_trans++;
}
}
}
}
......
......@@ -41,7 +41,8 @@ namespace spot
class ta_explicit : public ta
{
public:
ta_explicit(const tgba* tgba_);
ta_explicit(const tgba* tgba_, state_ta_explicit* artificial_initial_state =
0);
const tgba*
get_tgba() const;
......@@ -50,7 +51,7 @@ namespace spot
add_state(state_ta_explicit* s);
void
add_to_initial_states_set(state* s);
add_to_initial_states_set(state* s, bdd condition = bddfalse);
void
create_transition(state_ta_explicit* source, bdd condition,
......@@ -91,9 +92,28 @@ namespace spot
virtual void
free_state(const spot::state* s) const;
spot::state*
get_artificial_initial_state() const
{
return (spot::state*) artificial_initial_state_;
}
void
set_artificial_initial_state(state_ta_explicit* s)
{
artificial_initial_state_ = s;
}
virtual void
delete_stuttering_and_hole_successors(spot::state* s);
ta::states_set_t
get_states_set()
{
return states_set_;
}
private:
// Disallow copy.
ta_explicit(const ta_explicit& other);
......@@ -103,6 +123,7 @@ namespace spot
ta::states_set_t states_set_;
ta::states_set_t initial_states_set_;
const tgba* tgba_;
state_ta_explicit* artificial_initial_state_;
};
......@@ -122,7 +143,8 @@ namespace spot
state_ta_explicit(const state* tgba_state, const bdd tgba_condition,
bool is_initial_state = false, bool is_accepting_state = false,
bool is_livelock_accepting_state = false, transitions* trans = 0) :
bool is_livelock_accepting_state = false, transitions* trans = 0,
bool is_the_artificial_livelock_accepting_state = false) :
tgba_state_(tgba_state), tgba_condition_(tgba_condition),
is_initial_state_(is_initial_state), is_accepting_state_(
is_accepting_state), is_livelock_accepting_state_(
......@@ -164,10 +186,15 @@ namespace spot
is_livelock_accepting_state() const;
void
set_livelock_accepting_state(bool is_livelock_accepting_state);
bool
is_initial_state() const;
void
set_initial_state(bool is_initial_state);
bool
is_hole_state() const;
void
delete_stuttering_and_hole_successors();
......
// Copykripke_structure (C) 2010 Laboratoire de Recherche et Developpement
// Copyright (C) 2010 Laboratoire de Recherche et Developpement
// de l Epita (LRDE).
//
//
......@@ -87,7 +87,7 @@ namespace spot
delete ta_succ_it_;
delete kripke_succ_it_;
if (kripke_current_dest_state != 0)
kripke_current_dest_state->destroy();
kripke_current_dest_state->destroy();
}
void
......@@ -116,7 +116,7 @@ namespace spot
else
{
kripke_current_dest_state->destroy();
kripke_current_dest_state = 0;
kripke_current_dest_state = 0;
kripke_succ_it_->next();
}
......@@ -138,7 +138,7 @@ namespace spot
== kripke_current_dest_condition);
if (is_stuttering_transition_)
{
current_condition_ = bddtrue;
current_condition_ = bddfalse;
}
else
{
......@@ -174,7 +174,7 @@ namespace spot
step_();
if (!done())
next_non_stuttering_();
next_non_stuttering_();
}
......@@ -274,7 +274,7 @@ namespace spot
{
//build initial states set
const ta::states_set_t ta_init_states_set = ta_->get_initial_states_set();
ta::states_set_t ta_init_states_set;
ta::states_set_t::const_iterator it;
ta::states_set_t initial_states_set;
......@@ -282,10 +282,29 @@ namespace spot
bdd kripke_init_state_condition = kripke_->state_condition(
kripke_init_state);
spot::state* artificial_initial_state = ta_->get_artificial_initial_state();
if (artificial_initial_state != 0)
{
ta_succ_iterator* ta_init_it_ = ta_->succ_iter(
artificial_initial_state, kripke_init_state_condition);
for (ta_init_it_->first(); !ta_init_it_->done(); ta_init_it_->next())
{
ta_init_states_set.insert(ta_init_it_->current_state());
}
delete ta_init_it_;
}
else
{
ta_init_states_set = ta_->get_initial_states_set();
}
for (it = ta_init_states_set.begin(); it != ta_init_states_set.end(); it++)
{
if (kripke_init_state_condition == (ta_->get_state_condition(*it)))
if ((artificial_initial_state != 0) || (kripke_init_state_condition
== ta_->get_state_condition(*it)))
{
state_ta_product* stp = new state_ta_product((*it),
kripke_init_state->clone());
......@@ -341,6 +360,13 @@ namespace spot
return ta_->is_livelock_accepting_state(stp->get_ta_state());
}
spot::state*
ta_product::get_artificial_initial_state() const
{
return 0;
}