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 @@ ...@@ -19,62 +19,64 @@
// 02111-1307, USA. // 02111-1307, USA.
#include "ta.hh" #include "ta.hh"
namespace spot namespace spot
{ {
spot::state*
ta::get_artificial_initial_state() const
{
return 0;
}
scc_stack_ta::connected_component::connected_component(int i) scc_stack_ta::connected_component::connected_component(int i)
{ {
index = i; index = i;
is_accepting = false; is_accepting = false;
} }
scc_stack_ta::connected_component& scc_stack_ta::connected_component&
scc_stack_ta::top() scc_stack_ta::top()
{ {
return s.front(); return s.front();
} }
const scc_stack_ta::connected_component& const scc_stack_ta::connected_component&
scc_stack_ta::top() const scc_stack_ta::top() const
{ {
return s.front(); return s.front();
} }
void void
scc_stack_ta::pop() scc_stack_ta::pop()
{ {
// assert(rem().empty()); // assert(rem().empty());
s.pop_front(); s.pop_front();
} }
void void
scc_stack_ta::push(int index) scc_stack_ta::push(int index)
{ {
s.push_front(connected_component(index)); s.push_front(connected_component(index));
} }
std::list<state*>& std::list<state*>&
scc_stack_ta::rem() scc_stack_ta::rem()
{ {
return top().rem; return top().rem;
} }
size_t size_t
scc_stack_ta::size() const scc_stack_ta::size() const
{ {
return s.size(); return s.size();
} }
bool bool
scc_stack_ta::empty() const scc_stack_ta::empty() const
{ {
return s.empty(); return s.empty();
} }
} }
...@@ -49,6 +49,9 @@ namespace spot ...@@ -49,6 +49,9 @@ namespace spot
virtual const states_set_t virtual const states_set_t
get_initial_states_set() const = 0; get_initial_states_set() const = 0;
virtual spot::state*
get_artificial_initial_state() 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;
...@@ -67,6 +70,7 @@ namespace spot ...@@ -67,6 +70,7 @@ namespace spot
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;
......
...@@ -64,7 +64,8 @@ namespace spot ...@@ -64,7 +64,8 @@ namespace spot
bool bool
ta_explicit_succ_iterator::done() const ta_explicit_succ_iterator::done() const
{ {
return transitions_ == 0 || i_ == transitions_->end(); return transitions_ == 0 || transitions_->empty() || i_
== transitions_->end();
} }
state* state*
...@@ -103,15 +104,15 @@ namespace spot ...@@ -103,15 +104,15 @@ namespace spot
{ {
Sgi::hash_map<int, transitions*, Sgi::hash<int> >::const_iterator i = 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()) if (i == transitions_by_condition.end())
{ {
return 0; return 0;
} }
else else
{ {
return i->second; return i->second;
} }
} }
...@@ -122,17 +123,32 @@ namespace spot ...@@ -122,17 +123,32 @@ namespace spot
if (transitions_ == 0) if (transitions_ == 0)
transitions_ = new transitions; transitions_ = new transitions;
transitions_->push_back(t);
transitions* transitions_condition = get_transitions(t->condition); transitions* transitions_condition = get_transitions(t->condition);
if (transitions_condition == 0) if (transitions_condition == 0)
{ {
transitions_condition = new transitions; transitions_condition = new transitions;
transitions_by_condition[(t->condition).id()] = transitions_condition; 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 ...@@ -185,6 +201,13 @@ namespace spot
is_initial_state_ = is_initial_state; 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 int
state_ta_explicit::compare(const spot::state* other) const state_ta_explicit::compare(const spot::state* other) const
{ {
...@@ -196,7 +219,16 @@ namespace spot ...@@ -196,7 +219,16 @@ namespace spot
if (compare_value != 0) if (compare_value != 0)
return compare_value; 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 size_t
...@@ -219,37 +251,37 @@ namespace spot ...@@ -219,37 +251,37 @@ namespace spot
if (trans != 0) if (trans != 0)
for (it_trans = trans->begin(); it_trans != trans->end();) for (it_trans = trans->begin(); it_trans != trans->end();)
{ {
state_ta_explicit* dest = (*it_trans)->dest; state_ta_explicit* dest = (*it_trans)->dest;
bool is_stuttering_transition = (get_tgba_condition() bool is_stuttering_transition = (get_tgba_condition()
== (dest)->get_tgba_condition()); == (dest)->get_tgba_condition());
bool dest_is_livelock_accepting = dest->is_livelock_accepting_state(); bool dest_is_livelock_accepting = dest->is_livelock_accepting_state();
//Before deleting stuttering transitions, propaged back livelock and initial state's properties //Before deleting stuttering transitions, propaged back livelock and initial state's properties
if (is_stuttering_transition) if (is_stuttering_transition)
{ {
if (dest_is_livelock_accepting) if (dest_is_livelock_accepting)
set_livelock_accepting_state(true); set_livelock_accepting_state(true);
if (dest->is_initial_state()) if (dest->is_initial_state())
set_initial_state(true); set_initial_state(true);
} }
//remove hole successors states //remove hole successors states
state_ta_explicit::transitions* dest_trans = state_ta_explicit::transitions* dest_trans =
(dest)->get_transitions(); (dest)->get_transitions();
bool dest_trans_empty = dest_trans == 0 || dest_trans->empty(); bool dest_trans_empty = dest_trans == 0 || dest_trans->empty();
if (is_stuttering_transition || (dest_trans_empty if (is_stuttering_transition || (dest_trans_empty
&& (!dest_is_livelock_accepting))) && (!dest_is_livelock_accepting)))
{ {
get_transitions((*it_trans)->condition)->remove(*it_trans); get_transitions((*it_trans)->condition)->remove(*it_trans);
delete (*it_trans); delete (*it_trans);
it_trans = trans->erase(it_trans); it_trans = trans->erase(it_trans);
} }
else else
{ {
it_trans++; it_trans++;
} }
} }
} }
...@@ -262,18 +294,17 @@ namespace spot ...@@ -262,18 +294,17 @@ namespace spot
// they are not cloned. // they are not cloned.
if (trans != 0) if (trans != 0)
for (it_trans = trans->begin(); it_trans != trans->end(); it_trans++) for (it_trans = trans->begin(); it_trans != trans->end(); it_trans++)
{ {
delete *it_trans; delete *it_trans;
} }
delete trans; delete trans;
get_tgba_state()->destroy();
Sgi::hash_map<int, transitions*, Sgi::hash<int> >::iterator i = Sgi::hash_map<int, transitions*, Sgi::hash<int> >::iterator i =
transitions_by_condition.begin(); transitions_by_condition.begin();
while (i != transitions_by_condition.end()) while (i != transitions_by_condition.end())
{ {
delete i->second; delete i->second;
++i; ++i;
} }
} }
...@@ -282,10 +313,17 @@ namespace spot ...@@ -282,10 +313,17 @@ namespace spot
// ta_explicit // ta_explicit
ta_explicit::ta_explicit(const tgba* tgba_) : ta_explicit::ta_explicit(const tgba* tgba_,
tgba_(tgba_) state_ta_explicit* artificial_initial_state) :
tgba_(tgba_), artificial_initial_state_(artificial_initial_state)
{ {
get_dict()->register_all_variables_of(&tgba_, this); 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() ta_explicit::~ta_explicit()
...@@ -293,10 +331,11 @@ namespace spot ...@@ -293,10 +331,11 @@ 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++)
{ {
state_ta_explicit* s = down_cast<state_ta_explicit*> (*it); state_ta_explicit* s = down_cast<state_ta_explicit*> (*it);
s->free_transitions(); s->free_transitions();
delete s; s->get_tgba_state()->destroy();
delete s;
} }
get_dict()->unregister_all_my_variables(this); get_dict()->unregister_all_my_variables(this);
delete tgba_; delete tgba_;
...@@ -306,20 +345,26 @@ namespace spot ...@@ -306,20 +345,26 @@ namespace spot
ta_explicit::add_state(state_ta_explicit* s) ta_explicit::add_state(state_ta_explicit* s)
{ {
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);
return static_cast<state_ta_explicit*> (*add_state_to_ta.first); return static_cast<state_ta_explicit*> (*add_state_to_ta.first);
} }
void 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); state_ta_explicit * s = down_cast<state_ta_explicit*> (state);
assert(s); assert(s);
s->set_initial_state(true); s->set_initial_state(true);
if (condition == bddfalse)
initial_states_set_.insert(s); 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 ...@@ -329,7 +374,8 @@ namespace spot
state_ta_explicit * state = down_cast<state_ta_explicit*> (s); state_ta_explicit * state = down_cast<state_ta_explicit*> (s);
assert(state); assert(state);
state->delete_stuttering_and_hole_successors(); 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 ...@@ -355,7 +401,7 @@ namespace spot
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 = const state_ta_explicit* sta =
down_cast<const state_ta_explicit*> (initial_state); down_cast<const state_ta_explicit*> (initial_state);
assert(sta); assert(sta);
return sta->get_tgba_condition(); return sta->get_tgba_condition();
} }
...@@ -422,7 +468,7 @@ namespace spot ...@@ -422,7 +468,7 @@ namespace spot
return tgba_->format_state(sta->get_tgba_state()); 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());
} }
...@@ -433,26 +479,26 @@ namespace spot ...@@ -433,26 +479,26 @@ namespace spot
for (it = states_set_.begin(); it != states_set_.end(); it++) for (it = states_set_.begin(); it != states_set_.end(); it++)
{ {
const state_ta_explicit* source = const state_ta_explicit* source =
static_cast<const state_ta_explicit*> (*it); static_cast<const state_ta_explicit*> (*it);
state_ta_explicit::transitions* trans = source->get_transitions(); state_ta_explicit::transitions* trans = source->get_transitions();
state_ta_explicit::transitions::iterator it_trans; state_ta_explicit::transitions::iterator it_trans;
if (trans != 0) if (trans != 0)
for (it_trans = trans->begin(); it_trans != trans->end();) for (it_trans = trans->begin(); it_trans != trans->end();)
{ {
if (source->get_tgba_condition() if (source->get_tgba_condition()
== ((*it_trans)->dest)->get_tgba_condition()) == ((*it_trans)->dest)->get_tgba_condition())
{ {
delete *it_trans; delete *it_trans;
it_trans = trans->erase(it_trans); it_trans = trans->erase(it_trans);
} }
else else
{ {
it_trans++; it_trans++;
} }
} }
} }
} }
......
...@@ -41,7 +41,8 @@ namespace spot ...@@ -41,7 +41,8 @@ namespace spot
class ta_explicit : public ta class ta_explicit : public ta
{ {
public: public:
ta_explicit(const tgba* tgba_); ta_explicit(const tgba* tgba_, state_ta_explicit* artificial_initial_state =
0);
const tgba* const tgba*
get_tgba() const; get_tgba() const;
...@@ -50,7 +51,7 @@ namespace spot ...@@ -50,7 +51,7 @@ namespace spot
add_state(state_ta_explicit* s); add_state(state_ta_explicit* s);
void void
add_to_initial_states_set(state* s); add_to_initial_states_set(state* s, bdd condition = bddfalse);
void void
create_transition(state_ta_explicit* source, bdd condition, create_transition(state_ta_explicit* source, bdd condition,
...@@ -91,9 +92,28 @@ namespace spot ...@@ -91,9 +92,28 @@ namespace spot
virtual void virtual void
free_state(const spot::state* s) const; 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 virtual void
delete_stuttering_and_hole_successors(spot::state* s); delete_stuttering_and_hole_successors(spot::state* s);
ta::states_set_t
get_states_set()
{
return states_set_;
}
private: private:
// Disallow copy. // Disallow copy.
ta_explicit(const ta_explicit& other); ta_explicit(const ta_explicit& other);
...@@ -103,6 +123,7 @@ namespace spot ...@@ -103,6 +123,7 @@ namespace spot
ta::states_set_t states_set_; ta::states_set_t states_set_;
ta::states_set_t initial_states_set_; ta::states_set_t initial_states_set_;
const tgba* tgba_; const tgba* tgba_;
state_ta_explicit* artificial_initial_state_;
}; };
...@@ -122,7 +143,8 @@ namespace spot ...@@ -122,7 +143,8 @@ namespace spot
state_ta_explicit(const state* tgba_state, const bdd tgba_condition, state_ta_explicit(const state* tgba_state, const bdd tgba_condition,
bool is_initial_state = false, bool is_accepting_state = false,