* src/taalgos/minimize.cc: Cosmetics.
This commit is contained in:
parent
f00d97b4ba
commit
92a3366488
1 changed files with 361 additions and 373 deletions
|
|
@ -1,5 +1,6 @@
|
|||
// Copyright (C) 2010, 2011, 2012 Laboratoire de Recherche et
|
||||
// Développement de l'Epita (LRDE).
|
||||
// -*- coding: utf-8 -*-
|
||||
// Copyright (C) 2010, 2011, 2012, 2013 Laboratoire de Recherche et
|
||||
// Développement de l'Epita (LRDE).
|
||||
//
|
||||
// This file is part of Spot, a model checking library.
|
||||
//
|
||||
|
|
@ -67,14 +68,13 @@ namespace spot
|
|||
dump_hash_set(hs, aut, s);
|
||||
return s.str();
|
||||
}
|
||||
}
|
||||
|
||||
// From the base automaton and the list of sets, build the minimal automaton
|
||||
void
|
||||
// From the base automaton and the list of sets, build the minimal
|
||||
// automaton
|
||||
static void
|
||||
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.
|
||||
// For a state s, state_num[s] is the number of the state in the minimal
|
||||
// automaton.
|
||||
|
|
@ -107,10 +107,13 @@ namespace spot
|
|||
if ((a->get_artificial_initial_state() == 0) && is_initial_state)
|
||||
tgba_condition = a->get_state_condition(src);
|
||||
bool is_accepting_state = a->is_accepting_state(src);
|
||||
bool is_livelock_accepting_state = a->is_livelock_accepting_state(src);
|
||||
bool is_livelock_accepting_state =
|
||||
a->is_livelock_accepting_state(src);
|
||||
|
||||
state_ta_explicit* new_src = new state_ta_explicit(tgba_state,
|
||||
tgba_condition, is_initial_state, is_accepting_state,
|
||||
state_ta_explicit* new_src =
|
||||
new state_ta_explicit(tgba_state,
|
||||
tgba_condition, is_initial_state,
|
||||
is_accepting_state,
|
||||
is_livelock_accepting_state);
|
||||
|
||||
state_ta_explicit* ta_src = result->add_state(new_src);
|
||||
|
|
@ -145,11 +148,13 @@ namespace spot
|
|||
if ((a->get_artificial_initial_state() == 0) && is_initial_state)
|
||||
tgba_condition = a->get_state_condition(dst);
|
||||
bool is_accepting_state = a->is_accepting_state(dst);
|
||||
bool is_livelock_accepting_state = a->is_livelock_accepting_state(
|
||||
dst);
|
||||
bool is_livelock_accepting_state =
|
||||
a->is_livelock_accepting_state(dst);
|
||||
|
||||
state_ta_explicit* new_dst = new state_ta_explicit(tgba_state,
|
||||
tgba_condition, is_initial_state, is_accepting_state,
|
||||
state_ta_explicit* new_dst =
|
||||
new state_ta_explicit(tgba_state,
|
||||
tgba_condition, is_initial_state,
|
||||
is_accepting_state,
|
||||
is_livelock_accepting_state);
|
||||
|
||||
state_ta_explicit* ta_dst = result->add_state(new_dst);
|
||||
|
|
@ -168,15 +173,14 @@ namespace spot
|
|||
result->add_to_initial_states_set(new_dst);
|
||||
|
||||
result->create_transition(ta_src, succit->current_condition(),
|
||||
succit->current_acceptance_conditions(), ta_dst);
|
||||
|
||||
succit->current_acceptance_conditions(),
|
||||
ta_dst);
|
||||
}
|
||||
delete succit;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
partition_t
|
||||
static partition_t
|
||||
build_partition(const ta* ta_)
|
||||
{
|
||||
partition_t cur_run;
|
||||
|
|
@ -203,56 +207,41 @@ namespace spot
|
|||
|
||||
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)
|
||||
{
|
||||
const state* s = (*it);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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_);
|
||||
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)
|
||||
{
|
||||
hash_set* cI = new hash_set;
|
||||
|
|
@ -265,8 +254,6 @@ namespace spot
|
|||
++set_num;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
delete I;
|
||||
|
||||
if (!G->empty())
|
||||
|
|
@ -285,7 +272,9 @@ namespace spot
|
|||
|
||||
}
|
||||
else
|
||||
{
|
||||
delete G;
|
||||
}
|
||||
|
||||
if (!F->empty())
|
||||
{
|
||||
|
|
@ -302,7 +291,9 @@ namespace spot
|
|||
state_set_map[*i] = num;
|
||||
}
|
||||
else
|
||||
{
|
||||
delete F;
|
||||
}
|
||||
|
||||
if (!G_F->empty())
|
||||
{
|
||||
|
|
@ -319,7 +310,9 @@ namespace spot
|
|||
state_set_map[*i] = num;
|
||||
}
|
||||
else
|
||||
{
|
||||
delete G_F;
|
||||
}
|
||||
|
||||
if (!S->empty())
|
||||
{
|
||||
|
|
@ -336,10 +329,12 @@ namespace spot
|
|||
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.
|
||||
// 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;
|
||||
|
|
@ -368,8 +363,7 @@ namespace spot
|
|||
const state* src = *hi;
|
||||
bdd f = bddfalse;
|
||||
ta_succ_iterator* si = ta_->succ_iter(src);
|
||||
trace
|
||||
<< "+src: " << src << std::endl;
|
||||
trace << "+src: " << src << std::endl;
|
||||
for (si->first(); !si->done(); si->next())
|
||||
{
|
||||
const state* dst = si->current_state();
|
||||
|
|
@ -385,23 +379,16 @@ namespace spot
|
|||
& current_acceptance_conditions);
|
||||
trace
|
||||
<< "+f: " << bdd_format_accset(ta_->get_dict(), f)
|
||||
<< "\n -bdd_ithvar(i->second): "
|
||||
<< bdd_format_accset(ta_->get_dict(),
|
||||
bdd_ithvar(i->second))
|
||||
<< "\n -si->current_condition(): "
|
||||
<< bdd_format_accset(ta_->get_dict(),
|
||||
si->current_condition())
|
||||
<< "\n -current_acceptance_conditions: "
|
||||
<< bdd_format_accset(ta_->get_dict(),
|
||||
current_acceptance_conditions)
|
||||
<< 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;
|
||||
|
||||
|
|
@ -440,8 +427,8 @@ namespace spot
|
|||
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)
|
||||
// Make sure LEFT does not become negative
|
||||
// (hence bigger than SIZE when read as unsigned)
|
||||
assert(left < size);
|
||||
if (left == 0)
|
||||
{
|
||||
|
|
@ -453,8 +440,8 @@ namespace spot
|
|||
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)
|
||||
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)
|
||||
|
|
@ -478,7 +465,7 @@ namespace spot
|
|||
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);
|
||||
}
|
||||
|
||||
|
|
@ -493,6 +480,7 @@ namespace spot
|
|||
|
||||
return done;
|
||||
}
|
||||
}
|
||||
|
||||
ta*
|
||||
minimize_ta(const ta* ta_)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue