Stable version of TGTA approach implementation (automaton + product)

* src/ta/tgta.hh, src/ta/tgta.cc, src/ta/tgtaexplicit.hh,
src/ta/tgtaexplicit.hh, src/ta/tgtaproduct.hh, src/ta/tgtaproduct.cc,
src/taalgos/minimize.cc, src/taalgos/minimize.hh,
src/taalgos/emptinessta.hh, src/taalgos/emptinessta.hh,
src/taalgos/emptinessta.cc, src/taalgos/tgba2ta.hh,
src/taalgos/tgba2ta.cc: rename tgbta to tgta
in this source files.
* src/ta/tgbtaexplicit.hh, src/ta/tgbtaproduct.hh,  src/ta/tgbta.cc,
src/ta/tgbtaproduct.cc, src/ta/tgbta.hh, src/ta/tgbtaexplicit.cc:
Rename as...
* src/ta/taexplicit.cc, src/ta/taexplicit.hh, src/ta/taproduct.cc,
src/ta/taproduct.hh, src/ta/tgtaexplicit.cc: ... these.
* src/taalgos/sba2ta.hh, src/taalgos/sba2ta.cc: deleted because
the implementation of all the transformations beteween TGBA and
the different forms of TA are new implemented in src/taalgos/tgba2ta.hh
 and src/taalgos/tgba2ta.cc.
* src/tgbatest/ltl2tgba.cc: rename the options of commands that build
the different forms of TA.
* src/ta/ta.hh: BUG Fix
* src/ta/Makefile.am, src/tgbatest/ltl2ta.test: impacts of this renaming
This commit is contained in:
Ala-Eddine Ben-Salem 2012-04-10 23:30:03 +02:00 committed by Alexandre Duret-Lutz
parent c76e651bad
commit 5a706300b0
24 changed files with 1308 additions and 1580 deletions

View file

@ -34,7 +34,7 @@
#include "ltlast/allnodes.hh"
#include "misc/hash.hh"
#include "misc/bddlt.hh"
#include "ta/tgbtaexplicit.hh"
#include "ta/tgtaexplicit.hh"
#include "taalgos/statessetbuilder.hh"
#include "tgba/tgbaexplicit.hh"
#include "tgba/bddprint.hh"
@ -73,7 +73,8 @@ namespace spot
// From the base automaton and the list of sets, build the minimal automaton
void
build_result(const ta* a, std::list<hash_set*>& sets, tgba_explicit_number* result_tgba, ta_explicit* result)
build_result(const ta* a, std::list<hash_set*>& sets,
tgba_explicit_number* result_tgba, ta_explicit* result)
{
// For each set, create a state in the tgbaulting automaton.
@ -168,314 +169,331 @@ namespace spot
else if (is_initial_state)
result->add_to_initial_states_set(new_dst);
result->create_transition(ta_src, succit->current_condition(), succit->current_acceptance_conditions(), ta_dst);
result->create_transition(ta_src, succit->current_condition(),
succit->current_acceptance_conditions(), ta_dst);
}
delete succit;
}
}
partition_t build_partition(const ta* ta_){
partition_t
build_partition(const ta* ta_)
{
partition_t cur_run;
partition_t next_run;
partition_t next_run;
// The list of equivalent states.
partition_t done;
// The list of equivalent states.
partition_t done;
std::set<const state*> states_set = get_states_set(ta_);
std::set<const state*> states_set = get_states_set(ta_);
hash_set* I = new hash_set;
hash_set* I = new hash_set;
// livelock acceptance states
hash_set* G = new hash_set;
// livelock acceptance states
hash_set* G = new hash_set;
// Buchi acceptance states
hash_set* F = new hash_set;
// Buchi acceptance states
hash_set* F = new hash_set;
// Buchi and livelock acceptance states
hash_set* G_F = new hash_set;
// Buchi and livelock acceptance states
hash_set* G_F = new hash_set;
// the other states (non initial and not in G, F and G_F)
hash_set* S = new hash_set;
// the other states (non initial and not in G, F and G_F)
hash_set* S = new hash_set;
std::set<const state*>::iterator it;
std::set<const state*>::iterator it;
spot::state* artificial_initial_state = ta_->get_artificial_initial_state();
spot::state* artificial_initial_state = ta_->get_artificial_initial_state();
for (it = states_set.begin(); it != states_set.end(); it++)
for (it = states_set.begin(); it != states_set.end(); it++)
{
const state* s = (*it);
if (s == artificial_initial_state)
{
const state* s = (*it);
if (s == artificial_initial_state)
{
I->insert(s);
}
else if (artificial_initial_state == 0 && ta_->is_initial_state(s))
{
I->insert(s);
}
else if (ta_->is_livelock_accepting_state(s)
&& ta_->is_accepting_state(s))
{
G_F->insert(s);
}
else if (ta_->is_accepting_state(s))
{
F->insert(s);
}
else if (ta_->is_livelock_accepting_state(s))
{
G->insert(s);
}
else
{
S->insert(s);
}
I->insert(s);
}
else if (artificial_initial_state == 0 && ta_->is_initial_state(s))
{
I->insert(s);
}
else if (ta_->is_livelock_accepting_state(s)
&& ta_->is_accepting_state(s))
{
G_F->insert(s);
}
else if (ta_->is_accepting_state(s))
{
F->insert(s);
}
hash_map state_set_map;
// Size of ta_
unsigned size = states_set.size() + 6;
// Use bdd variables to number sets. set_num is the first variable
// available.
unsigned set_num = ta_->get_dict()->register_anonymous_variables(size, ta_);
std::set<int> free_var;
for (unsigned i = set_num; i < set_num + size; ++i)
free_var.insert(i);
std::map<int, int> used_var;
else if (ta_->is_livelock_accepting_state(s))
{
for (hash_set::const_iterator i = I->begin(); i != I->end(); ++i)
{
hash_set* cI = new hash_set;
cI->insert(*i);
done.push_back(cI);
used_var[set_num] = 1;
free_var.erase(set_num);
state_set_map[*i] = set_num;
set_num++;
}
}
delete I;
if (!G->empty())
{
unsigned s = G->size();
unsigned num = set_num;
set_num++;
used_var[num] = s;
free_var.erase(num);
if (s > 1)
cur_run.push_back(G);
else
done.push_back(G);
for (hash_set::const_iterator i = G->begin(); i != G->end(); ++i)
state_set_map[*i] = num;
G->insert(s);
}
else
delete G;
if (!F->empty())
{
unsigned s = F->size();
unsigned num = set_num;
set_num++;
used_var[num] = s;
free_var.erase(num);
if (s > 1)
cur_run.push_back(F);
else
done.push_back(F);
for (hash_set::const_iterator i = F->begin(); i != F->end(); ++i)
state_set_map[*i] = num;
S->insert(s);
}
else
delete F;
if (!G_F->empty())
}
hash_map state_set_map;
// Size of ta_
unsigned size = states_set.size() + 6;
// Use bdd variables to number sets. set_num is the first variable
// available.
unsigned set_num = ta_->get_dict()->register_anonymous_variables(size, ta_);
std::set<int> free_var;
for (unsigned i = set_num; i < set_num + size; ++i)
free_var.insert(i);
std::map<int, int> used_var;
{
for (hash_set::const_iterator i = I->begin(); i != I->end(); ++i)
{
unsigned s = G_F->size();
unsigned num = set_num;
hash_set* cI = new hash_set;
cI->insert(*i);
done.push_back(cI);
used_var[set_num] = 1;
free_var.erase(set_num);
state_set_map[*i] = set_num;
set_num++;
used_var[num] = s;
free_var.erase(num);
if (s > 1)
cur_run.push_back(G_F);
else
done.push_back(G_F);
for (hash_set::const_iterator i = G_F->begin(); i != G_F->end(); ++i)
state_set_map[*i] = num;
}
else
delete G_F;
if (!S->empty())
{
unsigned s = S->size();
unsigned num = set_num;
set_num++;
used_var[num] = s;
free_var.erase(num);
if (s > 1)
cur_run.push_back(S);
else
done.push_back(S);
for (hash_set::const_iterator i = S->begin(); i != S->end(); ++i)
state_set_map[*i] = num;
}
else
delete S;
}
delete I;
// A bdd_states_map is a list of formulae (in a BDD form) associated with a
// destination set of states.
typedef std::map<bdd, hash_set*, bdd_less_than> bdd_states_map;
bool did_split = true;
if (!G->empty())
{
unsigned s = G->size();
unsigned num = set_num;
set_num++;
used_var[num] = 1;
used_var[num] = s;
free_var.erase(num);
bdd bdd_false_acceptance_condition = bdd_ithvar(num);
if (s > 1)
cur_run.push_back(G);
else
done.push_back(G);
for (hash_set::const_iterator i = G->begin(); i != G->end(); ++i)
state_set_map[*i] = num;
while (did_split)
}
else
delete G;
if (!F->empty())
{
unsigned s = F->size();
unsigned num = set_num;
set_num++;
used_var[num] = s;
free_var.erase(num);
if (s > 1)
cur_run.push_back(F);
else
done.push_back(F);
for (hash_set::const_iterator i = F->begin(); i != F->end(); ++i)
state_set_map[*i] = num;
}
else
delete F;
if (!G_F->empty())
{
unsigned s = G_F->size();
unsigned num = set_num;
set_num++;
used_var[num] = s;
free_var.erase(num);
if (s > 1)
cur_run.push_back(G_F);
else
done.push_back(G_F);
for (hash_set::const_iterator i = G_F->begin(); i != G_F->end(); ++i)
state_set_map[*i] = num;
}
else
delete G_F;
if (!S->empty())
{
unsigned s = S->size();
unsigned num = set_num;
set_num++;
used_var[num] = s;
free_var.erase(num);
if (s > 1)
cur_run.push_back(S);
else
done.push_back(S);
for (hash_set::const_iterator i = S->begin(); i != S->end(); ++i)
state_set_map[*i] = num;
}
else
delete S;
// A bdd_states_map is a list of formulae (in a BDD form) associated with a
// destination set of states.
typedef std::map<bdd, hash_set*, bdd_less_than> bdd_states_map;
bool did_split = true;
unsigned num = set_num;
set_num++;
used_var[num] = 1;
free_var.erase(num);
bdd bdd_false_acceptance_condition = bdd_ithvar(num);
while (did_split)
{
did_split = false;
while (!cur_run.empty())
{
did_split = false;
while (!cur_run.empty())
// Get a set to process.
hash_set* cur = cur_run.front();
cur_run.pop_front();
trace
<< "processing " << format_hash_set(cur, ta_) << std::endl;
hash_set::iterator hi;
bdd_states_map bdd_map;
for (hi = cur->begin(); hi != cur->end(); ++hi)
{
// Get a set to process.
hash_set* cur = cur_run.front();
cur_run.pop_front();
const state* src = *hi;
bdd f = bddfalse;
ta_succ_iterator* si = ta_->succ_iter(src);
trace
<< "processing " << format_hash_set(cur, ta_) << std::endl;
hash_set::iterator hi;
bdd_states_map bdd_map;
for (hi = cur->begin(); hi != cur->end(); ++hi)
<< "+src: " << src << std::endl;
for (si->first(); !si->done(); si->next())
{
const state* src = *hi;
bdd f = bddfalse;
ta_succ_iterator* si = ta_->succ_iter(src);
trace << "+src: " << src << std::endl;
for (si->first(); !si->done(); si->next())
{
const state* dst = si->current_state();
hash_map::const_iterator i = state_set_map.find(dst);
const state* dst = si->current_state();
hash_map::const_iterator i = state_set_map.find(dst);
assert(i != state_set_map.end());
bdd current_acceptance_conditions =
si->current_acceptance_conditions();
if (current_acceptance_conditions == bddfalse)
current_acceptance_conditions
= bdd_false_acceptance_condition;
f |= (bdd_ithvar(i->second) & si->current_condition()
& current_acceptance_conditions);
trace << "+f: " << bdd_format_accset(ta_->get_dict(),f) << std::endl;;
trace << " -bdd_ithvar(i->second): " << bdd_format_accset(ta_->get_dict(),bdd_ithvar(i->second)) << std::endl;;
trace << " -si->current_condition(): " << bdd_format_accset(ta_->get_dict(),si->current_condition()) << std::endl;;
trace << " -current_acceptance_conditions: " << bdd_format_accset(ta_->get_dict(),current_acceptance_conditions) << std::endl;;
}
delete si;
// Have we already seen this formula ?
bdd_states_map::iterator bsi = bdd_map.find(f);
if (bsi == bdd_map.end())
{
// No, create a new set.
hash_set* new_set = new hash_set;
new_set->insert(src);
bdd_map[f] = new_set;
}
else
{
// Yes, add the current state to the set.
bsi->second->insert(src);
}
}
bdd_states_map::iterator bsi = bdd_map.begin();
if (bdd_map.size() == 1)
{
// The set was not split.
assert(i != state_set_map.end());
bdd current_acceptance_conditions =
si->current_acceptance_conditions();
if (current_acceptance_conditions == bddfalse)
current_acceptance_conditions
= bdd_false_acceptance_condition;
f |= (bdd_ithvar(i->second) & si->current_condition()
& current_acceptance_conditions);
trace
<< "set " << format_hash_set(bsi->second, ta_)
<< " was not split" << std::endl;
next_run.push_back(bsi->second);
<< "+f: " << bdd_format_accset(ta_->get_dict(), f)
<< std::endl;
;
trace
<< " -bdd_ithvar(i->second): " << bdd_format_accset(
ta_->get_dict(), bdd_ithvar(i->second)) << std::endl;
;
trace
<< " -si->current_condition(): "
<< bdd_format_accset(ta_->get_dict(),
si->current_condition()) << std::endl;
;
trace
<< " -current_acceptance_conditions: "
<< bdd_format_accset(ta_->get_dict(),
current_acceptance_conditions) << std::endl;
;
}
delete si;
// Have we already seen this formula ?
bdd_states_map::iterator bsi = bdd_map.find(f);
if (bsi == bdd_map.end())
{
// No, create a new set.
hash_set* new_set = new hash_set;
new_set->insert(src);
bdd_map[f] = new_set;
}
else
{
did_split = true;
for (; bsi != bdd_map.end(); ++bsi)
// Yes, add the current state to the set.
bsi->second->insert(src);
}
}
bdd_states_map::iterator bsi = bdd_map.begin();
if (bdd_map.size() == 1)
{
// The set was not split.
trace
<< "set " << format_hash_set(bsi->second, ta_)
<< " was not split" << std::endl;
next_run.push_back(bsi->second);
}
else
{
did_split = true;
for (; bsi != bdd_map.end(); ++bsi)
{
hash_set* set = bsi->second;
// Free the number associated to these states.
unsigned num = state_set_map[*set->begin()];
assert(used_var.find(num) != used_var.end());
unsigned left = (used_var[num] -= set->size());
// Make sure LEFT does not become negative (hence bigger
// than SIZE when read as unsigned)
assert(left < size);
if (left == 0)
{
hash_set* set = bsi->second;
// Free the number associated to these states.
unsigned num = state_set_map[*set->begin()];
assert(used_var.find(num) != used_var.end());
unsigned left = (used_var[num] -= set->size());
// Make sure LEFT does not become negative (hence bigger
// than SIZE when read as unsigned)
assert(left < size);
if (left == 0)
{
used_var.erase(num);
free_var.insert(num);
}
// Pick a free number
assert(!free_var.empty());
num = *free_var.begin();
free_var.erase(free_var.begin());
used_var[num] = set->size();
for (hash_set::iterator hit = set->begin(); hit
!= set->end(); ++hit)
state_set_map[*hit] = num;
// Trivial sets can't be splitted any further.
if (set->size() == 1)
{
trace
<< "set " << format_hash_set(set, ta_)
<< " is minimal" << std::endl;
done.push_back(set);
}
else
{
trace
<< "set " << format_hash_set(set, ta_)
<< " should be processed further" << std::endl;
next_run.push_back(set);
}
used_var.erase(num);
free_var.insert(num);
}
// Pick a free number
assert(!free_var.empty());
num = *free_var.begin();
free_var.erase(free_var.begin());
used_var[num] = set->size();
for (hash_set::iterator hit = set->begin(); hit
!= set->end(); ++hit)
state_set_map[*hit] = num;
// Trivial sets can't be splitted any further.
if (set->size() == 1)
{
trace
<< "set " << format_hash_set(set, ta_)
<< " is minimal" << std::endl;
done.push_back(set);
}
else
{
trace
<< "set " << format_hash_set(set, ta_)
<< " should be processed further" << std::endl;
next_run.push_back(set);
}
}
delete cur;
}
if (did_split)
trace
<< "splitting did occur during this pass." << std::endl;
//elsetrace << "splitting did not occur during this pass." << std::endl;
std::swap(cur_run, next_run);
delete cur;
}
if (did_split)
trace
<< "splitting did occur during this pass." << std::endl;
//elsetrace << "splitting did not occur during this pass." << std::endl;
std::swap(cur_run, next_run);
}
done.splice(done.end(), cur_run);
done.splice(done.end(), cur_run);
#ifdef TRACE
trace << "Final partition: ";
for (partition_t::const_iterator i = done.begin(); i != done.end(); ++i)
trace << format_hash_set(*i, ta_) << " ";
trace << std::endl;
#endif
#ifdef TRACE
trace << "Final partition: ";
for (partition_t::const_iterator i = done.begin(); i != done.end(); ++i)
trace << format_hash_set(*i, ta_) << " ";
trace << std::endl;
#endif
return done;
return done;
}
ta*
@ -486,11 +504,8 @@ namespace spot
ta_explicit* res = new ta_explicit(tgba, ta_->all_acceptance_conditions());
partition_t partition = build_partition(ta_);
// Build the ta automata result.
build_result(ta_, partition, tgba, res);
@ -503,32 +518,30 @@ namespace spot
return res;
}
tgbta*
minimize_tgbta(const tgbta* tgbta_)
{
tgta*
minimize_tgta(const tgta* tgta_)
{
tgba_explicit_number* tgba = new tgba_explicit_number(tgbta_->get_dict());
tgba_explicit_number* tgba = new tgba_explicit_number(tgta_->get_dict());
tgbta_explicit* res = new tgbta_explicit(tgba, tgbta_->all_acceptance_conditions(),0);
tgta_explicit* res = new tgta_explicit(tgba,
tgta_->all_acceptance_conditions(), 0);
const ta_explicit* tgbta = dynamic_cast <const tgbta_explicit*> (tgbta_);
//TODO copier le tgta_ dans un tgta_explicit au lieu de faire un cast...
const ta_explicit* tgta = dynamic_cast<const tgta_explicit*> (tgta_);
partition_t partition = build_partition(tgbta);
partition_t partition = build_partition(tgta);
// Build the minimal tgta automaton.
build_result(tgta, partition, tgba, res);
// Free all the allocated memory.
std::list<hash_set*>::iterator itdone;
for (itdone = partition.begin(); itdone != partition.end(); ++itdone)
delete *itdone;
//delete ta_;
// Build the tgbault.
build_result(tgbta, partition,tgba, res);
// Free all the allocated memory.
std::list<hash_set*>::iterator itdone;
for (itdone = partition.begin(); itdone != partition.end(); ++itdone)
delete *itdone;
//delete ta_;
return res;
}
return res;
}
}