Commit a15aac28 authored by Pierre PARUTTO's avatar Pierre PARUTTO Committed by Alexandre Duret-Lutz
Browse files

Revamp tgbaexplicit.hh

* src/tgba/tgbaexplicit.hh, src/tgba/tgbaexplicit.cc: Factor most of
the code in an explicit_graph<State, Type> that inherits from type.
The tgba_explicit type<State> now inherits from
explicit_graph<State,tgba>.
* src/ltlvisit/contain.cc, src/neverparse/neverclaimparse.yy
src/tgba/tgbareduc.cc, src/tgba/tgbareduc.hh, src/tgbaalgos/cutscc.cc,
src/tgbaalgos/dupexp.cc, src/tgbaalgos/dupexp.hh,
src/tgbaalgos/emptiness.cc, src/tgbaalgos/ltl2tgba_fm.cc,
src/tgbaalgos/ltl2tgba_fm.hh, src/tgbaalgos/minimize.cc,
src/tgbaalgos/powerset.cc, src/tgbaalgos/randomgraph.cc,
src/tgbaalgos/sccfilter.cc, src/tgbaparse/tgbaparse.yy,
src/tgbatest/complementation.cc, src/tgbatest/explicit.cc,
src/tgbatest/explprod.cc, src/tgbatest/ltl2tgba.cc,
src/tgbatest/mixprod.cc, src/tgbatest/powerset.cc,
src/tgbatest/tgbaread.cc, src/tgbatest/tripprod.cc:
Replace tgba_explicit* by the actual type used.
* src/tgbatest/explicit2.cc: New file.
* src/tgbatest/Makefile.am: Add it.
parent 9e2b932f
......@@ -132,9 +132,11 @@ namespace spot
if (i != translated_.end())
return &i->second;
const tgba_explicit* e = ltl_to_tgba_fm(f, dict_, exprop_, symb_merge_,
branching_postponement_,
fair_loop_approx_);
const tgba_explicit_formula* e =
ltl_to_tgba_fm(f, dict_, exprop_, symb_merge_,
branching_postponement_,
fair_loop_approx_);
record_& r = translated_[f->clone()];
r.translation = e;
return &r;
......
......@@ -120,7 +120,7 @@ ident_list:
state:
ident_list "skip"
{
spot::tgba_explicit::transition* t = result->create_transition(*$1, *$1);
spot::state_explicit_string::transition* t = result->create_transition(*$1, *$1);
bool acc = !strncmp("accept", $1->c_str(), 6);
if (acc)
result->add_acceptance_condition(t,
......@@ -135,7 +135,7 @@ state:
bool acc = !strncmp("accept", $1->c_str(), 6);
for (it = $3->begin(); it != $3->end(); ++it)
{
spot::tgba_explicit::transition* t =
spot::state_explicit_string::transition* t =
result->create_transition(*$1,*it->second);
result->add_condition(t, it->first);
......
// Copyright (C) 2009, 2010, 2011 Laboratoire de Recherche et Dveloppement
// Copyright (C) 2012 Laboratoire de Recherche et Développement
// de l'Epita (LRDE).
// Copyright (C) 2003, 2004 Laboratoire d'Informatique de Paris 6 (LIP6),
// dpartement Systmes Rpartis Coopratifs (SRC), Universit Pierre
// et Marie Curie.
//
// This file is part of Spot, a model checking library.
//
......@@ -21,348 +18,13 @@
// Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
#include <sstream>
#include "ltlast/atomic_prop.hh"
#include "ltlast/constant.hh"
#include "tgbaexplicit.hh"
#include "tgba/formula2bdd.hh"
#include "misc/bddop.hh"
#include <cassert>
#include "ltlvisit/tostring.hh"
#include "ltlast/constant.hh"
namespace spot
{
////////////////////////////////////////
// tgba_explicit_succ_iterator
tgba_explicit_succ_iterator::tgba_explicit_succ_iterator
(const state_explicit::transitions_t* s, bdd all_acc)
: s_(s), all_acceptance_conditions_(all_acc)
{
}
void
tgba_explicit_succ_iterator::first()
{
i_ = s_->begin();
}
void
tgba_explicit_succ_iterator::next()
{
++i_;
}
bool
tgba_explicit_succ_iterator::done() const
{
return i_ == s_->end();
}
state_explicit*
tgba_explicit_succ_iterator::current_state() const
{
assert(!done());
return const_cast<state_explicit*>(i_->dest);
}
bdd
tgba_explicit_succ_iterator::current_condition() const
{
assert(!done());
return i_->condition;
}
bdd
tgba_explicit_succ_iterator::current_acceptance_conditions() const
{
assert(!done());
return i_->acceptance_conditions & all_acceptance_conditions_;
}
////////////////////////////////////////
// state_explicit
int
state_explicit::compare(const spot::state* other) const
{
const state_explicit* o = down_cast<const state_explicit*>(other);
assert(o);
// Do not simply return "o - this", it might not fit in an int.
if (o < this)
return -1;
if (o > this)
return 1;
return 0;
}
size_t
state_explicit::hash() const
{
return
reinterpret_cast<const char*>(this) - static_cast<const char*>(0);
}
////////////////////////////////////////
// tgba_explicit
tgba_explicit::tgba_explicit(bdd_dict* dict)
: dict_(dict), init_(0), all_acceptance_conditions_(bddfalse),
neg_acceptance_conditions_(bddtrue),
all_acceptance_conditions_computed_(false)
{
}
tgba_explicit::~tgba_explicit()
{
dict_->unregister_all_my_variables(this);
}
tgba_explicit::transition*
tgba_explicit::create_transition(state* source, const state* dest)
{
transition t;
t.dest = dest;
t.condition = bddtrue;
t.acceptance_conditions = bddfalse;
state_explicit::transitions_t::iterator i =
source->successors.insert(source->successors.end(), t);
return &*i;
}
void
tgba_explicit::add_condition(transition* t, const ltl::formula* f)
{
t->condition &= formula_to_bdd(f, dict_, this);
f->destroy();
}
void
tgba_explicit::add_conditions(transition* t, bdd f)
{
dict_->register_propositions(f, this);
t->condition &= f;
}
void
tgba_explicit::copy_acceptance_conditions_of(const tgba *a)
{
assert(neg_acceptance_conditions_ == bddtrue);
assert(all_acceptance_conditions_computed_ == false);
bdd f = a->neg_acceptance_conditions();
dict_->register_acceptance_variables(f, this);
neg_acceptance_conditions_ = f;
}
void
tgba_explicit::set_acceptance_conditions(bdd acc)
{
assert(neg_acceptance_conditions_ == bddtrue);
assert(all_acceptance_conditions_computed_ == false);
dict_->register_acceptance_variables(bdd_support(acc), this);
neg_acceptance_conditions_ = compute_neg_acceptance_conditions(acc);
all_acceptance_conditions_computed_ = true;
all_acceptance_conditions_ = acc;
}
bool
tgba_explicit::has_acceptance_condition(const ltl::formula* f) const
{
return dict_->is_registered_acceptance_variable(f, this);
}
bdd
tgba_explicit::get_acceptance_condition(const ltl::formula* f)
{
bdd_dict::fv_map::iterator i = dict_->acc_map.find(f);
assert(has_acceptance_condition(f));
/* If this second assert fails and the first doesn't,
things are badly broken. This has already happened. */
assert(i != dict_->acc_map.end());
f->destroy();
bdd v = bdd_ithvar(i->second);
v &= bdd_exist(neg_acceptance_conditions_, v);
return v;
}
void
tgba_explicit::add_acceptance_condition(transition* t, const ltl::formula* f)
{
bdd c = get_acceptance_condition(f);
t->acceptance_conditions |= c;
}
void
tgba_explicit::add_acceptance_conditions(transition* t, bdd f)
{
bdd sup = bdd_support(f);
dict_->register_acceptance_variables(sup, this);
while (sup != bddtrue)
{
neg_acceptance_conditions_ &= bdd_nithvar(bdd_var(sup));
sup = bdd_high(sup);
}
t->acceptance_conditions |= f;
}
state*
tgba_explicit::get_init_state() const
{
// Fix empty automata by adding a lone initial state.
if (!init_)
const_cast<tgba_explicit*>(this)->add_default_init();
return init_;
}
tgba_succ_iterator*
tgba_explicit::succ_iter(const spot::state* state,
const spot::state* global_state,
const tgba* global_automaton) const
{
const state_explicit* s = down_cast<const state_explicit*>(state);
assert(s);
(void) global_state;
(void) global_automaton;
return new tgba_explicit_succ_iterator(&s->successors,
all_acceptance_conditions());
}
bdd
tgba_explicit::compute_support_conditions(const spot::state* in) const
{
const state_explicit* s = down_cast<const state_explicit*>(in);
assert(s);
const state_explicit::transitions_t& st = s->successors;
bdd res = bddfalse;
state_explicit::transitions_t::const_iterator i;
for (i = st.begin(); i != st.end(); ++i)
res |= i->condition;
return res;
}
bdd
tgba_explicit::compute_support_variables(const spot::state* in) const
{
const state_explicit* s = down_cast<const state_explicit*>(in);
assert(s);
const state_explicit::transitions_t& st = s->successors;
bdd res = bddtrue;
state_explicit::transitions_t::const_iterator i;
for (i = st.begin(); i != st.end(); ++i)
res &= bdd_support(i->condition);
return res;
}
bdd_dict*
tgba_explicit::get_dict() const
{
return dict_;
}
bdd
tgba_explicit::all_acceptance_conditions() const
{
if (!all_acceptance_conditions_computed_)
{
all_acceptance_conditions_ =
compute_all_acceptance_conditions(neg_acceptance_conditions_);
all_acceptance_conditions_computed_ = true;
}
return all_acceptance_conditions_;
}
bdd
tgba_explicit::neg_acceptance_conditions() const
{
return neg_acceptance_conditions_;
}
tgba_explicit_string::~tgba_explicit_string()
{
ns_map::iterator i;
for (i = name_state_map_.begin(); i != name_state_map_.end(); ++i)
{
// Do not erase the same state twice. (Because of possible aliases.)
if (state_name_map_.erase(i->second))
{
delete i->second;
}
}
}
tgba_explicit::state*
tgba_explicit_string::add_default_init()
{
return add_state("empty");
}
std::string
tgba_explicit_string::format_state(const spot::state* s) const
{
const state_explicit* se = down_cast<const state_explicit*>(s);
assert(se);
sn_map::const_iterator i = state_name_map_.find(se);
assert(i != state_name_map_.end());
return i->second;
}
tgba_explicit_formula::~tgba_explicit_formula()
{
ns_map::iterator i = name_state_map_.begin();
while (i != name_state_map_.end())
{
// Advance the iterator before deleting the formula.
const ltl::formula* s = i->first;
delete i->second;
++i;
s->destroy();
}
}
tgba_explicit::state* tgba_explicit_formula::add_default_init()
{
return add_state(ltl::constant::true_instance());
}
std::string
tgba_explicit_formula::format_state(const spot::state* s) const
{
const state_explicit* se = down_cast<const state_explicit*>(s);
assert(se);
sn_map::const_iterator i = state_name_map_.find(se);
assert(i != state_name_map_.end());
return ltl::to_string(i->second);
}
tgba_explicit_number::~tgba_explicit_number()
{
ns_map::iterator i = name_state_map_.begin();
while (i != name_state_map_.end())
{
delete i->second;
++i;
}
}
tgba_explicit::state* tgba_explicit_number::add_default_init()
{
return add_state(0);
}
std::string
tgba_explicit_number::format_state(const spot::state* s) const
{
const state_explicit* se = down_cast<const state_explicit*>(s);
assert(se);
sn_map::const_iterator i = state_name_map_.find(se);
assert(i != state_name_map_.end());
std::stringstream ss;
ss << i->second;
return ss.str();
}
const std::string state_explicit_string::default_val("empty");
const int state_explicit_number::default_val(0);
const ltl::formula*
state_explicit_formula::default_val(ltl::constant::true_instance());
}
This diff is collapsed.
......@@ -148,15 +148,15 @@ namespace spot
}
}
tgba_explicit::transition*
tgba_explicit_string::transition*
tgba_reduc::create_transition(const spot::state* source,
const spot::state* dest)
{
const std::string ss = aut_->format_state(source);
const std::string sd = aut_->format_state(dest);
tgba_explicit::state* s = tgba_explicit_string::add_state(ss);
tgba_explicit::state* d = tgba_explicit_string::add_state(sd);
state_explicit_string* s = tgba_explicit_string::add_state(ss);
state_explicit_string* d = tgba_explicit_string::add_state(sd);
transition t;
t.dest = d;
......@@ -175,7 +175,7 @@ namespace spot
t.condition = bddtrue;
t.acceptance_conditions = bddfalse;
state_explicit::transitions_t::iterator is
state_explicit_string::transitions_t::iterator is
= s->successors.insert(s->successors.end(), t);
return &*is;
}
......@@ -190,10 +190,10 @@ namespace spot
bdd cond_simul;
bdd acc_simul;
std::list<state*> ltmp;
const tgba_explicit::state* s1 =
name_state_map_[tgba_explicit_string::format_state(s)];
const tgba_explicit::state* s2 =
name_state_map_[tgba_explicit_string::format_state(simul)];
const state_explicit_string* s1 =
&(ls_[tgba_explicit_string::format_state(s)]);
const state_explicit_string* s2 =
&(ls_[tgba_explicit_string::format_state(simul)]);
sp_map::iterator i = state_predecessor_map_.find(s1);
if (i == state_predecessor_map_.end()) // 0 predecessor
......@@ -205,7 +205,7 @@ namespace spot
{
// We check if simul belong to the successor of p,
// as s belong too.
for (state_explicit::transitions_t::iterator
for (state_explicit_string::transitions_t::iterator
j = (*p)->successors.begin();
j != (*p)->successors.end(); ++j)
if (j->dest == s2) // simul belong to the successor of p.
......@@ -221,7 +221,7 @@ namespace spot
continue;
// for all successor of p, a predecessor of s and simul.
for (state_explicit::transitions_t::iterator
for (state_explicit_string::transitions_t::iterator
j = (*p)->successors.begin();
j != (*p)->successors.end(); ++j)
{
......@@ -233,7 +233,7 @@ namespace spot
((!j->acceptance_conditions) | acc_simul) == bddtrue))
{
// We can redirect transition leading to s on simul.
j->dest = const_cast<tgba_explicit::state*>(s2);
j->dest = const_cast<state_explicit_string*>(s2);
// We memorize that we have to remove p
// of the predecessor of s.
......@@ -273,19 +273,20 @@ namespace spot
// merge_state => NO PREDECESSOR. But it can be have some
// predecessor in state_predecessor_map_.
ns_map::iterator k =
name_state_map_.find(tgba_explicit_string::format_state(s));
if (k == name_state_map_.end()) // 0 predecessor
ls_map::iterator k =
ls_.find(tgba_explicit_string::format_state(s));
if (k == ls_.end()) // 0 predecessor
return;
tgba_explicit::state* st =
name_state_map_[tgba_explicit_string::format_state(s)];
state_explicit_string* st =
&(ls_[tgba_explicit_string::format_state(s)]);
// for all successor q of s, we remove s of the predecessor of q.
// Note that the initial node can't be removed.
for (state_explicit::transitions_t::iterator j =
for (state_explicit_string::transitions_t::iterator j =
st->successors.begin(); j != st->successors.end(); ++j)
this->remove_predecessor_state(j->dest, st);
this->remove_predecessor_state(down_cast<const state_explicit_string*>
(j->dest), st);
sp_map::iterator i = state_predecessor_map_.find(st);
......@@ -297,7 +298,7 @@ namespace spot
p != (i->second)->end(); ++p)
{
// for all transition of p, a predecessor of s.
for (state_explicit::transitions_t::iterator
for (state_explicit_string::transitions_t::iterator
j = (*p)->successors.begin();
j != (*p)->successors.end();)
{
......@@ -321,11 +322,11 @@ namespace spot
void
tgba_reduc::merge_state(const spot::state* sim1, const spot::state* sim2)
{
const tgba_explicit::state* s1 =
name_state_map_[tgba_explicit_string::format_state(sim1)];
const tgba_explicit::state* s2 =
name_state_map_[tgba_explicit_string::format_state(sim2)];
const tgba_explicit::state* stmp = s1;
const state_explicit_string* s1 =
&(ls_[tgba_explicit_string::format_state(sim1)]);
const state_explicit_string* s2 =
&(ls_[tgba_explicit_string::format_state(sim2)]);
const state_explicit_string* stmp = s1;
const spot::state* simtmp = sim1;
// if sim1 is the init state, we remove sim2.
......@@ -354,7 +355,7 @@ namespace spot
p != (i->second)->end(); ++p)
{
// for all successor of p, a predecessor of s1.
for (state_explicit::transitions_t::iterator
for (state_explicit_string::transitions_t::iterator
j = (*p)->successors.begin();
j != (*p)->successors.end(); ++j)
{
......@@ -362,7 +363,7 @@ namespace spot
if (j->dest == s1)
{
// ... make it s2.
j->dest = const_cast<tgba_explicit::state*>(s2);
j->dest = const_cast<state_explicit_string*>(s2);
}
}
}
......@@ -373,7 +374,7 @@ namespace spot
// leaving s1 (possible when the simulation is delayed). Since s2
// simulates s1, s2 has some labels that imply these of s1, so we
// can put the acceptance conditions on its arcs.
for (state_explicit::transitions_t::const_iterator
for (state_explicit_string::transitions_t::const_iterator
j = s1->successors.begin();
j != s1->successors.end(); ++j)
{
......@@ -381,7 +382,7 @@ namespace spot
t.dest = j->dest;
t.condition = j->condition;
t.acceptance_conditions = j->acceptance_conditions;
const_cast<state_explicit*>(s2)->successors.push_back(t);
const_cast<state_explicit_string*>(s2)->successors.push_back(t);
}
// We remove all the predecessor of s1.
......
......@@ -75,9 +75,9 @@ namespace spot
void display_scc(std::ostream& os);
protected:
typedef Sgi::hash_map<const tgba_explicit::state*,
typedef Sgi::hash_map<const state_explicit_string*,
std::list<state*>*,
ptr_hash<tgba_explicit::state> > sp_map;
ptr_hash<state_explicit_string> > sp_map;
sp_map state_predecessor_map_;
// Interface of tgba_reachable_iterator_breadth_first
......
......@@ -74,7 +74,7 @@ namespace spot
{
dst->destroy();
}
tgba_explicit::transition* t =
state_explicit_string::transition* t =
sub_a->create_transition(cur_format, dst_format);
sub_a->add_conditions(t, sit->current_condition());
sub_a->
......
......@@ -57,7 +57,7 @@ namespace spot
std::ostringstream out_name;
out_name << "(#" << out << ") " << this->aut_->format_state(out_s);
tgba_explicit::transition* t =
state_explicit_string::transition* t =
out_->create_transition(in_name.str(), out_name.str());
out_->add_conditions(t, si->current_condition());
out_->add_acceptance_conditions(t, si->current_acceptance_conditions());
......@@ -69,7 +69,7 @@ namespace spot
} // anonymous
tgba_explicit*
tgba_explicit_string*
tgba_dupexp_bfs(const tgba* aut)
{
dupexp_iter<tgba_reachable_iterator_breadth_first> di(aut);
......@@ -77,7 +77,7 @@ namespace spot
return di.result();
}
tgba_explicit*
tgba_explicit_string*
tgba_dupexp_dfs(const tgba* aut)
{
dupexp_iter<tgba_reachable_iterator_depth_first> di(aut);
......
......@@ -29,11 +29,11 @@ namespace spot
/// \brief Build an explicit automata from all states of \a aut,
/// numbering states in bread first order as they are processed.
/// \ingroup tgba_misc
tgba_explicit* tgba_dupexp_bfs(const tgba* aut);
tgba_explicit_string* tgba_dupexp_bfs(const tgba* aut);
/// \brief Build an explicit automata from all states of \a aut,